Module: Afterburner::Protocols::Searcher

Defined in:
lib/afterburner/protocols/searcher.rb

Overview

Wraps searching so that users can swap out searching models with the use of any one searching plugin. At present, it only supports a single searching method, but it will pass along any arguments given to that method.

Simply set Afterburner::Searcher.searching_method equal to the symbol name of your searching method, and then use the :as_search_results method for queries. For example, if you are wrapping acts_as_indexed, the searching method there is called ‘with_query’. Thus:

Afterburner::Searcher.searching_method = :with_query
MyModel.where(:field => true).as_search_results("cats") # uses with_query

You can also set searching_method on the model itself to use a different as_search_results for just that model. For example:

MyModel.searching_method = :local_query
MyModel.where(:field => true).as_search_results("cats") # uses local_query

This won’t interrupt other models’ ability to use the default as_search_results.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.searching_methodObject

Returns the value of attribute searching_method.



25
26
27
# File 'lib/afterburner/protocols/searcher.rb', line 25

def searching_method
  @searching_method
end

Instance Attribute Details

#searching_methodObject

Returns the value of attribute searching_method.



28
29
30
# File 'lib/afterburner/protocols/searcher.rb', line 28

def searching_method
  @searching_method
end

Instance Method Details

#as_search_results(*args) ⇒ Object



33
34
35
# File 'lib/afterburner/protocols/searcher.rb', line 33

def as_search_results(*args)
  send searching_method, *args
end