Class: Lolita::Search::Simple
Overview
Default search class for Lolita::Search. Lolita::Configuration::Search uses this by default. It accepts method name as constructor argument, when none is given it call Lolita::DBI#search.
Instance Attribute Summary collapse
-
#dbi ⇒ Object
readonly
Returns the value of attribute dbi.
-
#search_method ⇒ Object
Method in model used to run a search.
Instance Method Summary collapse
-
#initialize(dbi, *args) ⇒ Simple
constructor
Accepts search method as optional argument.
-
#run(query, *args) ⇒ Object
Require dbi (Lolita::DBI instance), query (String) and request and dbi as optional argument.
Constructor Details
#initialize(dbi, *args) ⇒ Simple
Accepts search method as optional argument
13 14 15 16 17 |
# File 'lib/lolita/search/simple.rb', line 13 def initialize(dbi, *args) @dbi = dbi @options = args. @search_method = args[0] end |
Instance Attribute Details
#dbi ⇒ Object (readonly)
Returns the value of attribute dbi.
10 11 12 |
# File 'lib/lolita/search/simple.rb', line 10 def dbi @dbi end |
#search_method ⇒ Object
Method in model used to run a search.
9 10 11 |
# File 'lib/lolita/search/simple.rb', line 9 def search_method @search_method end |
Instance Method Details
#run(query, *args) ⇒ Object
Require dbi (Lolita::DBI instance), query (String) and request and dbi as optional argument. Also you can pass options.
Example
search.run("query",:fields => [:name])
# this will search only in :name field
search.run("query",nil, Lolita::DBI::Base.create(Category))
# this will use Category dbi for search
When there is search method defined, it uses that otherwise run default search.
27 28 29 30 31 32 33 34 35 |
# File 'lib/lolita/search/simple.rb', line 27 def run(query,*args) with_query(query,*args) do if self.search_method run_custom_search else run_default_search end end end |