Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 37 lines (29 sloc) 0.917 kb
01eb221 Florian R. Hanke + boosting, + partials
authored
1 require File.expand_path '../../../server/lib/picky', __FILE__
2
ce3d034 Florian R. Hanke + independent recipes, + geolocation, + range/area/volumetric searches
authored
3 Person = Struct.new :id, :first, :last
4
01eb221 Florian R. Hanke + boosting, + partials
authored
5 # Our special partializer only allows partials
6 # of even length.
7 #
8 class Partializer
9
10 def each_partial text
11 temp = text.dup
12 temp.length.times do
13 yield temp if temp.size.even?
14 temp.chop!
15 end
16 end
17
18 end
19
20 data = Picky::Index.new :people do
21 category :first
22 category :last, partial: Partializer.new # <= Passed in here.
23 end
24
25 data.replace Person.new(1, 'Donald', 'Knuth')
26 data.replace Person.new(2, 'Niklaus', 'Wirth')
27 data.replace Person.new(3, 'Donald', 'North')
28 data.replace Person.new(4, 'Peter', 'Niklaus')
29
30 people = Picky::Search.new data
31
32 # Finds only even partials.
33 #
34 fail __FILE__ unless people.search('n').ids == []
35 fail __FILE__ unless people.search('no').ids == [3]
36 fail __FILE__ unless people.search('nor').ids == []
37 fail __FILE__ unless people.search('nort').ids == [3]
Something went wrong with that request. Please try again.