Skip to content

Navigation Menu

Sign up

Contributing sources

floere edited this page Nov 21, 2010 · 7 revisions

Glad you’d like to add another (削除) tentacle (削除ここまで) source to Picky!

Here’d how you do it:

  1. Check the available Sources if the source already exists.
  2. If yes, use (and improve) it :)
  3. If not, fork the repository and follow the instructions below.

Every source derives from the base class Sources::Base, which contains 3 methods. These methods are all called by the indexer:

  • connect_backend # Connect to the backend here if your source needs that.
  • take_snapshot(type) # If you have fast moving data, you might want to get a snapshot here (into a hash, or a temp table etc.)
  • harvest(type, category) # This is the mandatory method. Yield each id and data for that id.

Example

This is how the CSV source implements the harvest method. It’s currently not optimized.

 def harvest _, field # We don't care about the type.
 index = field_names.index field.name # Get the right column from the data.
 ::CSV.foreach file_name do |ary| # A helper method that reads a line from the csv file.
 indexed_id = ary.shift
 text = ary[index]
 next unless text
 yield indexed_id, text # <- the most important part, yields the indexed_id and the corresponding text to the indexer. 
 end
 end

Clone this wiki locally

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