Skip to content

Index configuration

kschiess edited this page Nov 23, 2010 · 15 revisions

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 data can be accessed.

For a valid index, you will need to define the index and various categories. An index without categories cannot be searched. The categories link the data in the source to how the data can be searched for.

In code (using Ruby 1.9 new style hashes):

books_index = index :books, Sources::CSV.new(:title, :author, :isbn, file: 'app/library.csv')
books_index.define_category :title,
                            similarity: Similarity::Phonetic.new(3),
                            partial: Partial::Substring.new(from: 1)

This creates a new index (with the index method), 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). Also, 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: