Indexes alone cannot be searched. You need a
Search object and give it all indexes you want to search:
Searches operate on Indexes.
books_index = Picky::Index.new :books do # ... end books = Search.new books_index books.search 'test'
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!
books_index = index # ... dvd_index = index # ... music_index = index # ... books = Search.new books_index, dvd_index, music_index books.search 'test'
This will return results found in all three indexes.
Apart from a list of indexes, searches take options in their options block.
The options are currently:
[ [token1, token2], [original1, original2] ].
Call them as methods in the block:
books = Search.new books_index do searching splits_text_on: /\s\_/, max_words: 4 terminate_early end
books = Search.new books_index do boost [:author] => 6, # Eg. 'Goethe'. Note that this only boosts on a single word. [:title, :author] => 5, # Eg. 'hobbit tolkien' [:author, :year] => 2 # Eg. 'orwell 1948' end
[:author] => 6means 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.