One idea is to do it like that (a complete working example, just run it in eg. TextMate):
require 'picky'
require 'picky-client'
index = Picky::Index.new :index do
category :name
end
data = Picky::Search.new index
class Name < Struct.new(:id, :name)
@@names = {}
def self.register id, name
@@names[id] = new id, name
end
def self.find ids, options = {}
return ids.map { |id| @@names[id] }
end
end
index.add Name.register(1, 'hello world')
index.add Name.register(2, 'hello mars')
results = data.search 'hello'
results = results.to_hash
results.extend Picky::Convenience
# Instead of just a single name, we
# insert an array of a name and its id.
#
# (Silly example, but it illustrates how to do it)
#
results.populate_with Name do |name|
end
# A list of the "rendered" names.
#
puts "The entries:"
p results.entries
# The results hash.
#
puts "The results hash:"
p results
Don't hesitate to look at Picky's client/server code, too :)
Cheers,
Florian