Picky Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'picky' | |
# create an index which is auto-saved into './index' | |
# note that :id is implied - every input object must supply an :id ! | |
index = Picky::Index.new :people do | |
category :age | |
category :name | |
end | |
# define a data input class | |
# any object that responds to :id, :age, :name can be added to the index. | |
Person = Struct.new :id, :age, :name | |
# add some data objects to the index | |
# note that the IDs can be any unique string or integer | |
index.add Person.new(1, 34, 'Florian is the author of picky') | |
index.add Person.new(2, 77, 'Floris is related to Florian') | |
# create a search object | |
people = Picky::Search.new index | |
# do a search and save the results | |
search_results = people.search 'floris' | |
# show the results | |
puts search_results.ids |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment