Skip to content

Sources Configuration

Stanley edited this page Nov 3, 2010 · 32 revisions

Sources

Sources tell an index where to get its data.

Example
Possible Sources
  Database
  CSV
  Delicious
Experimental

Example

The method index(identifier_symbol, source, *categories, options = {}) takes a source as second argument.

class PickySearch < Application
  
  books_index = index :books,
                      Sources::CSV.new(:title, :author, :isbn, :year, :publisher, :subjects, :file => 'app/library.csv'),
                      category(:title, # ...
  
end

The source defines where this index is getting its data from.

Possible sources

Database

Sources::DB.new('SELECT id, title, author, isbn13 as isbn FROM books', :file => 'app/db.yml')
Sources::DB.new('SELECT id, title, author, isbn13 as isbn FROM books', active_records_configuration_options_hash)

You can use join statements etc. (The :file option points to a yml with an active record config hash)
Then, reference your columns by their names in the catgories:

Sources::DB.new('SELECT id, title, author, isbn13 as isbn FROM books', :file => 'app/db.yml'),
category(:isbn),
category(:title), # ...

CSV

Sources::CSV.new(:title, :author, :isbn, :year, :publisher, :subjects, :file => 'app/library.csv')

The first column in the CSV needs to be the id. The others are assumed to be in the order you provide.

Delicious

Sources::Delicious.new('username', 'password')

Delicious then provides a selection of categories: title, tags, url.

CouchDB

Sources::Couch.new(:title, :author, :isbn, :year, :publisher, :subjects, {:url => 'http://localhost:5984/library', :user => 'user', :password => 'password'})

TODO:

  • Get mapped/filtered documents,
  • add picky-client example with documents retrieving

Experimental

If needed you can provide each category with its own source.

Sources::DB.new('SELECT id, title, author, isbn13 as isbn FROM books', :file => 'app/db.yml'),
category(:isbn, :source => Sources::CSV.new(:isbn, :file => 'app/isbn.csv')),
category(:title, :source => Sources::Delicious.new('username', 'password')), # ...

But normally you won’t need this. Don’t hesitate to ask if you don’t see any other possibility than using this.