Repository navigation
Searches Configuration
Searches search Picky indexes: Search.new(*indexes_to_search, options = {})
Searches are defined in app/application.rb like all other search specific options.
See below, under "weights option".
Searches operate on Indexes.
class PickySearch < Application # ... books_index = index # ... Index definition omitted. # ... books = Search.new books_index # or directly route %r{^/books$} => Search.new(books_index) # ... end
You can search over an arbitrary number of indexes. Say, you have multiple indexes, one for books, one for dvds, one for music. You can combine them to search through them all with a single query!
class PickySearch < Application # ... books_index = index # ... dvd_index = index # ... music_index = index # ... # ... books = Search.new books_index, dvd_index, music_index end
This will return results found in all three indexes.
Apart from a list of indexes, searches take options.
The options are currently:
- weights: Define a number of combinations that should receive positive or negative weights (see example below).
- tokenizer: The Tokenizer to use. Default is Tokenizer::Query.
options = { :weights => [:author] => 6, [:title, :author] => 5, [:author, :year] => 2 } books = Search.new books_index, options end
Giving
[:author] => 6 means that if results are found where Picky thinks that one or all search terms are in the title, it is weighed by 6 (a lot) higher.
[:title, :author] => 5 will add 5 to the weight, if Picky finds a title followed by an author, e.g. "ulysses joyce". If it finds an author followed by a title, 5 points will not be added.
The order is important!
So for example you can give more weight to [:street, :streetnumber], but subtract points for [:streetnumber, :street], an unlikely order of search terms.
As a rule of thumb: 6 is very high, 0 is the default added weight, -6 is a very harsh penalty.
TODO