Skip to content

Commit

Permalink
+ Picky recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Dec 28, 2011
1 parent e8f2cbf commit 148591d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions recipes/.gitignore
@@ -0,0 +1 @@
index
3 changes: 3 additions & 0 deletions recipes/Rakefile
@@ -0,0 +1,3 @@
require File.expand_path '../run', __FILE__

task :default
21 changes: 21 additions & 0 deletions recipes/basic.rb
@@ -0,0 +1,21 @@
require File.expand_path '../../server/lib/picky', __FILE__

data = Picky::Index.new :people do
source do
[Person.new(1, 'Donald', 'Knuth'),
Person.new(2, 'Niklaus', 'Wirth'),
Person.new(3, 'Donald', 'Worth'),
Person.new(4, 'Peter', 'Niklaus')]
end
category :first
category :last
end

people = Picky::Search.new data

data.reindex # aka data.index; data.load

results = people.search 'donald'

# p results.allocations
fail __FILE__ unless results.ids == [1, 3]
18 changes: 18 additions & 0 deletions recipes/realtime.rb
@@ -0,0 +1,18 @@
require File.expand_path '../../server/lib/picky', __FILE__

data = Picky::Index.new :people do
category :first
category :last
end

data.replace Person.new(1, 'Donald', 'Knuth')
data.replace Person.new(2, 'Niklaus', 'Wirth')
data.replace Person.new(3, 'Donald', 'Worth')
data.replace Person.new(4, 'Peter', 'Niklaus')

people = Picky::Search.new data

results = people.search 'donald'

# p results.allocations
fail __FILE__ unless results.ids == [3, 1]
3 changes: 3 additions & 0 deletions recipes/run.rb
@@ -0,0 +1,3 @@
Person = Struct.new :id, :first, :last

Dir['**/*.rb'].each { |file| require File.expand_path "../#{file}", __FILE__ }

0 comments on commit 148591d

Please sign in to comment.