-
Notifications
You must be signed in to change notification settings - Fork 49
Sources Configuration
Sources tell an index where to get its data.
Example
Possible Sources
Database
CSV
Delicious
Experimental
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')
books_index.define_category :title, # ...
end
The source defines where this index is getting its data from.
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:
index = index :name, Sources::DB.new('SELECT id, title, author, isbn13 as isbn FROM books', :file => 'app/db.yml')
index.define_category :isbn
index.define_category :title
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.
- file: Relative file path of the data csv file.
Ruby 1.9 options like col_sep, row_sep etc. (see http://ruby-doc.org/ruby-1.9/classes/CSV.html for details) are all available.
Sources::Delicious.new('username', 'password')
Delicious then provides a selection of categories: title, tags, url.
If needed you can provide each category with its own source.
index = index :name, Sources::DB.new('SELECT id, title, author, isbn13 as isbn FROM books', :file => 'app/db.yml')
index.define_category :isbn, :source => Sources::CSV.new(:isbn, :file => 'app/isbn.csv')
index.define_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.