-
Notifications
You must be signed in to change notification settings - Fork 49
Index configuration
Indexes in Picky hold categorized data. You use Queries to search in these indexes.
An index needs:
- A Source: Where the data comes from.
- One or more Categories: The various ways the data is accessed.
For a valid index, you will need to define the index and one or more categories. An index without categories cannot be searched. The categories link the data – the what – in the source to how the data is searched.
In code (using Ruby 1.9 new style hashes):
books_index = Index::Memory.new :books, Sources::CSV.new(:title, :author, :isbn, file: 'app/library.csv') do
category :title,
similarity: Similarity::DoubleMetaphone.new(3),
partial: Partial::Substring.new(from: 1)
end
This creates a new index (with Index::Memory.new
, or Index::Redis.new
), which has a CSV source with (an implicit id) title, author, and isbn. It then links the title field in the input with the title category (see options). In the example, we tell Picky to also find phonetically similar results (each indexed word is linked to up to three other indexed, similar words). In addition to that, it will find a title word even if it is only partially matched, so “Hob” will find “Hobbit”.
If you are of the “an image says 1000 words” type, I hope this helps:
(This image only has about 197 words on it, so the other 803 words are in the forms and colors)
For the bigger picture, this shows the indexes in context. You can have multiple indexes. Each query can have multiple indexes. Each query also can have multiple URLs mapping to it.