Skip to content

Navigation Menu

Sign up

Searches Configuration

Florian Hanke edited this page Mar 28, 2011 · 7 revisions

Searches

Searches search Picky indexes: Search.new(*indexes_to_search, options = {})

Searches are defined in app/application.rb like all other search specific options.

FAQ

How to prefer certain results?

See below, under "weights option".

Simplest Example

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

Example with multiple indexes per Search

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.

Search Options

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.

weights option

 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.

tokenizer option

TODO

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /