Skip to content
Browse files

+ Picky recipes

  • Loading branch information...
1 parent e8f2cbf commit 148591d70c2f70273bf048574adb24a48799f10a @floere committed Dec 28, 2011
Showing with 46 additions and 0 deletions.
  1. +1 −0 recipes/.gitignore
  2. +3 −0 recipes/Rakefile
  3. +21 −0 recipes/basic.rb
  4. +18 −0 recipes/realtime.rb
  5. +3 −0 recipes/run.rb
View
1 recipes/.gitignore
@@ -0,0 +1 @@
+index
View
3 recipes/Rakefile
@@ -0,0 +1,3 @@
+require File.expand_path '../run', __FILE__
+
+task :default
View
21 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]
View
18 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]
View
3 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.
Something went wrong with that request. Please try again.