Module: SearchExtension::ClassMethods
- Defined in:
- app/models/search_extension.rb
Instance Method Summary collapse
- #build_query_string(params = {}) ⇒ Object
- #forces_multi_query? ⇒ Boolean
- #multi_query(params = {}) ⇒ Object
- #single_query(params = {}) ⇒ Object
- #supports_multi_query? ⇒ Boolean
Instance Method Details
#build_query_string(params = {}) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'app/models/search_extension.rb', line 47 def build_query_string(params = {}) query_str = params[:query] query_str = "%#{query_str}" if ["contains", "ends_with"].include?(params[:query_type].to_s) query_str = "#{query_str}%" if ["contains", "begins_with"].include?(params[:query_type].to_s) # Note that 'contains' will add an '%' to the beginning AND to the end query_str end |
#forces_multi_query? ⇒ Boolean
43 44 45 |
# File 'app/models/search_extension.rb', line 43 def forces_multi_query? false end |
#multi_query(params = {}) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'app/models/search_extension.rb', line 26 def multi_query(params = {}) query_terms = params[:query].split(/\r\n/) results = [] query_terms.each do |term| results << { :query => term, :result => single_query(params.merge({:query => term})) } end results end |
#single_query(params = {}) ⇒ Object
35 36 37 |
# File 'app/models/search_extension.rb', line 35 def single_query(params = {}) raise NotImplementedError.new("Implement self.single_query in your specific class (#{self.name}) that should be searchable!") end |
#supports_multi_query? ⇒ Boolean
39 40 41 |
# File 'app/models/search_extension.rb', line 39 def supports_multi_query? false end |