Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

+ more recipes (search options)

  • Loading branch information...
commit 9c5abec157df5982bbb655acb4d584243f6e2508 1 parent 5b4c799
@floere authored
View
3  recipes/realtime.rb
@@ -1,5 +1,8 @@
require File.expand_path '../../server/lib/picky', __FILE__
+# Loading the Picky index without a source,
+# but purely by adding (replacing) items.
+#
data = Picky::Index.new :people do
category :first
category :last
View
6 recipes/searches/README.textile
@@ -1,6 +1,6 @@
h1. Searches
* ignore_unassigned.rb
-* ignore.rb (TODO)
-* max_words.rb (TODO)
-...
+* ignore.rb
+* max_allocations.rb
+* terminate_early.rb
View
25 recipes/searches/max_allocations.rb
@@ -0,0 +1,25 @@
+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 do
+ boost [:first] => +1 # First name will be better than the last name.
+ max_allocations 1 # <= Only search for the first (best) allocation.
+end
+
+# The niklaus in the first name will be found
+# and the one in the last name will be thrown
+# away.
+#
+results = people.search 'niklaus'
+
+# p results.allocations
+fail __FILE__ unless results.ids == [2]
View
21 recipes/searches/terminate_early.rb
@@ -0,0 +1,21 @@
+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 do
+ boost [:first] => +1 # The first name category will be boosted.
+ terminate_early # <= Only search for necessary allocations to get enough ids.
+end
+
+results = people.search 'niklaus', 1 # We just need one id, so just one allocation is enough.
+
+# p results.allocations
+fail __FILE__ unless results.ids == [2] # Only found in the first name category.
View
0  recipes/sinatra_rails/TODO
No changes.
View
5 recipes/sourced.rb
@@ -1,5 +1,8 @@
require File.expand_path '../../server/lib/picky', __FILE__
+# An example where you give the Picky index
+# an #each source.
+#
data = Picky::Index.new :people do
source do
[Person.new(1, 'Donald', 'Knuth'),
@@ -13,7 +16,7 @@
people = Picky::Search.new data
-data.reindex # aka data.index; data.load
+data.reindex # == data.index; data.load
results = people.search 'donald'
View
0  recipes/tokenizers/TODO
No changes.
Please sign in to comment.
Something went wrong with that request. Please try again.