picky 4.21.2 → 4.22.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 867ccbdac334b762659c0cb099da2545e2ca408f
4
- data.tar.gz: 0102830fb69655ebe0e097ad84aff897e9e26068
3
+ metadata.gz: 954befab3206369e74bfcdda5281da5f9c638f6a
4
+ data.tar.gz: 7128af9049b1b9ce1f5d29fbc1b37df8ef9eca58
5
5
  SHA512:
6
- metadata.gz: 3b5efada92088f0e30442f8eb1b9a51dfa551308a9f423e11fa57a326ed22ebff62d36a8fd7ca96257b1474cb1268a9daac2ad7f6f61cfa66277cd0e0740b093
7
- data.tar.gz: 2dd2598eecd67120079d2feacda2430ded9ab7c0aeee6c8b239b9c3d19ffdc65fe036a194e8abdd13b3527020cf77fef9d7d35273381f89f9882e3834ab5ac0c
6
+ metadata.gz: aa52877a9229a585e86fa4e2dd47dfedd093a53e1f7cc802eb6b309ccc49e0ef9c161c2e3b9b6be0ebdec9866365bf940e589dcd83731bdef4c1593fb6c3bce4
7
+ data.tar.gz: 6f5095a81599f40c006db8cce7bacfa82b58ac8f7043b64d1287ac673dec5b40bb3dd558213dd478d6ee5980f82f1695227a94bc158fe95c3aaa7d93e7dfc172
data/lib/picky/bundle.rb CHANGED
@@ -128,19 +128,20 @@ module Picky
128
128
 
129
129
  # Get a list of similar texts.
130
130
  #
131
- # Note: Does not return itself.
131
+ # Note: Also checks for itself.
132
132
  #
133
133
  def similar text
134
134
  code = similarity_strategy.encode text
135
135
  return [] unless code
136
- similar_codes = @similarity[code]
137
- if similar_codes.blank?
138
- [] # Return a simple array.
139
- else
140
- similar_codes = similar_codes.dup
141
- similar_codes.delete text
142
- similar_codes
143
- end
136
+ @similarity[code] || []
137
+ # similar_codes = @similarity[code]
138
+ # if similar_codes.blank?
139
+ # [] # Return a simple array.
140
+ # else
141
+ # similar_codes = similar_codes.dup
142
+ # similar_codes.delete text # Remove itself.
143
+ # similar_codes
144
+ # end
144
145
  end
145
146
 
146
147
  # If a key format is set, use it, else forward to the category.
@@ -1,5 +1,5 @@
1
1
  module Picky
2
-
2
+
3
3
  module Generators
4
4
 
5
5
  module Similarity
@@ -12,8 +12,8 @@ module Picky
12
12
  thing
13
13
  else
14
14
  raise <<-ERROR
15
- similarity options #{identifier_for(index_name, category_name)}should be either
16
- * for example a Similarity::Phonetic.new(n), Similarity::Metaphone.new(n), Similarity::DoubleMetaphone.new(n) etc.
15
+ Similarity options #{identifier_for(index_name, category_name)}should be either
16
+ * for example a Similarity::Soundex.new(n), Similarity::Metaphone.new(n), Similarity::DoubleMetaphone.new(n) etc.
17
17
  or
18
18
  * an object that responds to #encode(text) => encoded_text and #prioritize(array_of_encoded, encoded)
19
19
  ERROR
@@ -23,5 +23,5 @@ ERROR
23
23
  end
24
24
 
25
25
  end
26
-
26
+
27
27
  end
@@ -105,6 +105,8 @@ module Picky
105
105
  #
106
106
  # Parameter is a method name to use on the key (e.g. :to_i, :to_s, :strip, :split).
107
107
  #
108
+ # TODO Rename to id_format.
109
+ #
108
110
  def key_format key_format = nil
109
111
  key_format ? (@key_format = key_format) : @key_format
110
112
  end
@@ -1,7 +1,7 @@
1
1
  module Picky
2
2
 
3
3
  module Query
4
-
4
+
5
5
  # An Allocation contains an ordered list of
6
6
  # tuples (Combinations).
7
7
  # The Combinations are ordered according to the order
@@ -25,7 +25,13 @@ module Picky
25
25
  @index = index
26
26
  @combinations = combinations
27
27
  end
28
-
28
+
29
+ # TODO
30
+ #
31
+ def each &block
32
+ @combinations.each &block
33
+ end
34
+
29
35
  #
30
36
  #
31
37
  def backend
@@ -48,6 +54,14 @@ module Picky
48
54
  end)
49
55
  end
50
56
 
57
+ # Ids return by default [].
58
+ #
59
+ # TODO Calculate ids here.
60
+ #
61
+ def ids
62
+ @ids ||= []
63
+ end
64
+
51
65
  # Asks the backend for the (intersected) ids.
52
66
  #
53
67
  # Note: Combinations can be empty on eg.
@@ -56,18 +70,12 @@ module Picky
56
70
  #
57
71
  def calculate_ids amount, offset
58
72
  return [] if @combinations.empty? # Checked here to avoid checking in each backend.
59
-
73
+
60
74
  # TODO Redesign such that ids is only created (and cached) if requested.
61
75
  #
62
76
  backend.ids @combinations, amount, offset
63
77
  end
64
78
 
65
- # Ids return by default [].
66
- #
67
- def ids
68
- @ids ||= []
69
- end
70
-
71
79
  # This starts the searching process.
72
80
  #
73
81
  # Returns the calculated ids (from the offset).
@@ -112,7 +120,7 @@ module Picky
112
120
  def to_result
113
121
  [@index.result_identifier, self.score, self.count, @combinations.to_result, self.ids] if self.count && self.count > 0
114
122
  end
115
-
123
+
116
124
  #
117
125
  #
118
126
  def to_qualifiers
@@ -53,7 +53,7 @@ module Picky
53
53
  def remove_categories categories = []
54
54
  @allocations.each { |allocation| allocation.remove categories } unless categories.empty?
55
55
  end
56
-
56
+
57
57
  # Removes allocations.
58
58
  #
59
59
  # Only those passed in are removed.
@@ -70,7 +70,7 @@ module Picky
70
70
  allocation
71
71
  end
72
72
  end
73
-
73
+
74
74
  # Keeps allocations.
75
75
  #
76
76
  # Only those passed in are kept.
@@ -90,7 +90,7 @@ module Picky
90
90
  # Returns the top amount ids.
91
91
  #
92
92
  def ids amount = 20
93
- @allocations.inject([]) do |total, allocation|
93
+ inject([]) do |total, allocation|
94
94
  total.size >= amount ? (return total.shift(amount)) : total + allocation.ids
95
95
  end
96
96
  end
@@ -128,7 +128,7 @@ module Picky
128
128
  end
129
129
  end
130
130
  end
131
-
131
+
132
132
  # Same as #process! but removes duplicate ids from results.
133
133
  #
134
134
  # Note that in the result later on an allocation won't be
@@ -6,7 +6,7 @@ module Picky
6
6
  #
7
7
  # Combinations contain methods for calculating score (including
8
8
  # the boost) and ids for each of its Combination s.
9
- #
9
+ #
10
10
  # They are the core of an Allocation.
11
11
  # An Allocation consists of a number of Combinations.
12
12
  #
@@ -23,6 +23,12 @@ module Picky
23
23
  @combinations = combinations
24
24
  end
25
25
 
26
+ # TODO
27
+ #
28
+ def each &block
29
+ @combinations.each &block
30
+ end
31
+
26
32
  # Sums up the weights of the combinations.
27
33
  #
28
34
  # Note: Optimized sum(&:weight) away – ~3% improvement.
@@ -39,7 +45,7 @@ module Picky
39
45
  # ids that have an associated identifier that is nil.
40
46
  #
41
47
  def remove categories = []
42
- # TODO Do not use the name, but the category.
48
+ # TODO Do not use the name, but the category.
43
49
  #
44
50
  @combinations.reject! { |combination| categories.include?(combination.category.name) }
45
51
  end
@@ -49,7 +55,7 @@ module Picky
49
55
  def to_result
50
56
  @combinations.map &:to_result
51
57
  end
52
-
58
+
53
59
  def to_qualifiers
54
60
  @combinations.map &:category_name
55
61
  end
data/lib/picky/results.rb CHANGED
@@ -5,31 +5,29 @@ module Picky
5
5
  #
6
6
  class Results
7
7
 
8
+ include Enumerable
9
+
8
10
  # Duration is set externally by the query.
9
11
  #
10
12
  attr_writer :duration
11
- attr_reader :allocations,
12
- :offset,
13
+ attr_reader :offset,
13
14
  :amount,
14
15
  :query
15
16
 
16
17
  # Takes instances of Query::Allocations as param.
17
18
  #
18
- def initialize query = nil, amount = 0, offset = 0, allocations = Query::Allocations.new
19
+ def initialize query = nil, amount = 0, offset = 0, allocations = Query::Allocations.new, extra_allocations = nil, unique = false
19
20
  @amount = amount
20
21
  @query = query
21
22
  @offset = offset
22
23
  @allocations = allocations
24
+ @extra_allocations = extra_allocations
25
+ @unique = unique
23
26
  end
24
27
 
25
- # Create new results and calculate the ids.
26
- #
27
- # TODO Remove and calculate lazily via results.ids (rewrite all references to use Result.new).
28
- #
29
- def self.from query, amount, offset, allocations, extra_allocations = nil, unique = false
30
- results = new query, amount, offset, allocations
31
- results.prepare! extra_allocations, unique
32
- results
28
+ def allocations
29
+ prepare! *(@prepared || [@extra_allocations, @unique])
30
+ @allocations
33
31
  end
34
32
 
35
33
  # This starts the actual processing.
@@ -38,9 +36,15 @@ module Picky
38
36
  # and no ids are calculated.
39
37
  #
40
38
  def prepare! extra_allocations = nil, unique = false
39
+ return if @prepared == [extra_allocations, unique] # cached?
40
+ @prepared = [extra_allocations, unique] # cache!
41
41
  unique ?
42
- allocations.process_unique!(amount, offset, extra_allocations) :
43
- allocations.process!(amount, offset, extra_allocations)
42
+ @allocations.process_unique!(amount, offset, extra_allocations) :
43
+ @allocations.process!(amount, offset, extra_allocations)
44
+ end
45
+
46
+ def each &block
47
+ allocations.each &block
44
48
  end
45
49
 
46
50
  # Forwards to allocations.
@@ -49,6 +53,8 @@ module Picky
49
53
  # should not be done repeatedly. Just keep
50
54
  # a reference to the result.
51
55
  #
56
+ # TODO Rewrite such that this triggers calculation, not prepare!
57
+ #
52
58
  def ids only = amount
53
59
  allocations.ids only
54
60
  end
data/lib/picky/search.rb CHANGED
@@ -138,7 +138,7 @@ module Picky
138
138
  def boost boosts
139
139
  @boosts = extract_boosts boosts
140
140
  end
141
-
141
+
142
142
  # Ignore given categories and/or combinations of
143
143
  # categories.
144
144
  #
@@ -158,7 +158,7 @@ module Picky
158
158
  end
159
159
  end
160
160
  end
161
-
161
+
162
162
  # Exclusively keep combinations of
163
163
  # categories.
164
164
  #
@@ -171,7 +171,7 @@ module Picky
171
171
  def only *allocations_and_categories
172
172
  indexes.keep_allocations *allocations_and_categories
173
173
  end
174
-
174
+
175
175
  # Ignore the given token if it cannot be matched to a category.
176
176
  # The default behaviour is that if a token does not match to
177
177
  # any category, the query will not return anything (since a
@@ -236,12 +236,12 @@ module Picky
236
236
  # Note: Internal method, use #search to search.
237
237
  #
238
238
  def execute tokens, ids, offset, original_text = nil, unique = false
239
- Results.from original_text,
240
- ids,
241
- offset,
242
- sorted_allocations(tokens, @max_allocations),
243
- @extra_allocations,
244
- unique
239
+ Results.new original_text,
240
+ ids,
241
+ offset,
242
+ sorted_allocations(tokens, @max_allocations),
243
+ @extra_allocations,
244
+ unique
245
245
  end
246
246
 
247
247
  # Forwards the tokenizing to the query tokenizer.
@@ -4,8 +4,8 @@ require 'spec_helper'
4
4
  require 'ostruct'
5
5
 
6
6
  describe "Array IDs" do
7
-
8
- let(:index) { Picky::Index.new :arrays }
7
+
8
+ let(:index) { Picky::Index.new :arrays }
9
9
  let(:try) { Picky::Search.new index }
10
10
 
11
11
  # This tests the weights option.
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+ #
3
+ require 'spec_helper'
4
+ require 'ostruct'
5
+
6
+ describe "Results" do
7
+
8
+ let(:index1) { Picky::Index.new :results1 }
9
+ let(:index2) { Picky::Index.new :results2 }
10
+ let(:try) { Picky::Search.new index1, index2 }
11
+
12
+ # Test the enumerator abilities.
13
+ #
14
+ it 'can enumerate through the allocations' do
15
+ index1.category :text
16
+ index2.category :text
17
+
18
+ thing = OpenStruct.new id: 1, text: "ohai"
19
+ other = OpenStruct.new id: 2, text: "ohai kthxbye"
20
+
21
+ index1.add thing
22
+ index1.add other
23
+ index2.add thing
24
+
25
+ # each
26
+ #
27
+ expected = [
28
+ [2, 1],
29
+ [1]
30
+ ]
31
+ try.search("text:ohai").each do |allocation|
32
+ expected.shift.should == allocation.ids
33
+ end
34
+
35
+ # map
36
+ #
37
+ try.search("text:ohai").map(&:ids).should == [
38
+ [2, 1],
39
+ [1]
40
+ ]
41
+ try.search("text:ohai").map(&:score).should == [0.693, 0.0]
42
+ end
43
+
44
+ it 'can re-prepare with different parameters' do
45
+ index1.category :text
46
+ index2.category :text
47
+
48
+ thing = OpenStruct.new id: 1, text: "ohai"
49
+ other = OpenStruct.new id: 2, text: "ohai kthxbye"
50
+
51
+ index1.add thing
52
+ index1.add other
53
+ index2.add thing
54
+
55
+ results = try.search "text:ohai"
56
+ results.ids.should == [2, 1, 1]
57
+
58
+ results.prepare! nil, true
59
+ results.ids.should == [2, 1]
60
+ results.ids.object_id.should_not == results.ids.object_id # Not cached.
61
+ end
62
+
63
+ end
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+ #
3
+ require 'spec_helper'
4
+
5
+ describe 'similarity' do
6
+ it 'does Soundex' do
7
+ index = Picky::Index.new :phonetic do
8
+ indexing removes_characters: /[^a-z\s]/i
9
+ category :text, similarity: Picky::Similarity::Soundex.new(1)
10
+ end
11
+
12
+ index.replace_from id: 1, text: "Peter"
13
+
14
+ try = Picky::Search.new index
15
+
16
+ # No ~, no similarity.
17
+ #
18
+ try.search("text:petor").ids.should == []
19
+
20
+ # Finds soundex-similar text.
21
+ #
22
+ try.search("text:petor~").ids.should == [1]
23
+
24
+ # Finds the identity.
25
+ #
26
+ try.search("text:peter~").ids.should == [1]
27
+ end
28
+ it 'does Metaphone' do
29
+ index = Picky::Index.new :phonetic do
30
+ indexing removes_characters: /[^a-z\s]/i
31
+ category :text, similarity: Picky::Similarity::Metaphone.new(1)
32
+ end
33
+
34
+ index.replace_from id: 1, text: "Peter"
35
+
36
+ try = Picky::Search.new index
37
+
38
+ # No ~, no similarity.
39
+ #
40
+ try.search("text:pdr").ids.should == []
41
+
42
+ # Finds soundex-similar text.
43
+ #
44
+ try.search("text:pdr~").ids.should == [1]
45
+
46
+ # Finds the identity.
47
+ #
48
+ try.search("text:peter~").ids.should == [1]
49
+ end
50
+ it 'does DoubleMetaphone' do
51
+ index = Picky::Index.new :phonetic do
52
+ indexing removes_characters: /[^a-z\s]/i
53
+ category :text, similarity: Picky::Similarity::DoubleMetaphone.new(1)
54
+ end
55
+
56
+ index.replace_from id: 1, text: "Peter"
57
+
58
+ try = Picky::Search.new index
59
+
60
+ # No ~, no similarity.
61
+ #
62
+ try.search("text:pdr").ids.should == []
63
+
64
+ # Finds soundex-similar text.
65
+ #
66
+ try.search("text:pdr~").ids.should == [1]
67
+
68
+ # Finds the identity.
69
+ #
70
+ try.search("text:peter~").ids.should == [1]
71
+ end
72
+ end
@@ -156,43 +156,51 @@ describe 'Search#terminate_early' do
156
156
  fast = performance_of do
157
157
  try_fast.search 'hello'
158
158
  end
159
- (slow/fast).should >= 1.1
159
+ slow.should < 0.00009
160
+ fast.should < 0.00005
161
+ (slow/fast).should >= 1.5
160
162
 
161
163
  try_slow = Picky::Search.new index
162
164
  slow = performance_of do
163
- try_slow.search 'hello hello'
165
+ try_slow.search('hello hello').ids
164
166
  end
165
167
  try_fast = Picky::Search.new index do
166
168
  terminate_early
167
169
  end
168
170
  fast = performance_of do
169
- try_fast.search 'hello hello'
171
+ try_fast.search('hello hello').ids
170
172
  end
171
- (slow/fast).should >= 1.2
173
+ slow.should < 0.00015
174
+ fast.should < 0.00009
175
+ (slow/fast).should >= 1.5
172
176
 
173
177
  try_slow = Picky::Search.new index
174
178
  slow = performance_of do
175
- try_slow.search 'hello hello hello'
179
+ try_slow.search('hello hello hello').ids
176
180
  end
177
181
  try_fast = Picky::Search.new index do
178
182
  terminate_early
179
183
  end
180
184
  fast = performance_of do
181
- try_fast.search 'hello hello hello'
185
+ try_fast.search('hello hello hello').ids
182
186
  end
183
- (slow/fast).should >= 1.4
187
+ slow.should < 0.0005
188
+ fast.should < 0.00025
189
+ (slow/fast).should >= 2
184
190
 
185
191
  try_slow = Picky::Search.new index
186
192
  slow = performance_of do
187
- try_slow.search 'hello hello hello hello'
193
+ try_slow.search('hello hello hello hello').ids
188
194
  end
189
195
  try_fast = Picky::Search.new index do
190
196
  terminate_early
191
197
  end
192
198
  fast = performance_of do
193
- try_fast.search 'hello hello hello hello'
199
+ try_fast.search('hello hello hello hello').ids
194
200
  end
195
- (slow/fast).should >= 1.7
201
+ slow.should < 0.002
202
+ fast.should < 0.0008
203
+ (slow/fast).should >= 2.3
196
204
  end
197
205
 
198
206
  end
@@ -21,8 +21,8 @@ describe Picky::Bundle do
21
21
  bundle.add_similarity :dragon
22
22
  bundle.add_similarity :dargon
23
23
  end
24
- it 'returns the right similars (not itself)' do
25
- bundle.similar(:dragon).should == [:dargon]
24
+ it 'returns the right similars (including itself)' do
25
+ bundle.similar(:dragon).should == [:dargon, :dragon]
26
26
  end
27
27
  it 'returns the right similars' do
28
28
  bundle.similar(:trkn).should == [:dargon, :dragon]
@@ -19,48 +19,9 @@ describe Picky::Generators::Similarity::DoubleMetaphone do
19
19
  @similarity.encode(text).should == expected
20
20
  end
21
21
  end
22
- # def self.it_should_generate_from index, expected
23
- # it "should generate #{expected.inspect} correctly from #{index.inspect}" do
24
- # @similarity.generate_from(index).should == expected
25
- # end
26
- # end
27
22
 
28
23
  it_should_encode :meier, :MR
29
24
  it_should_encode :grossberger, :KRSP
30
25
  it_should_encode :hadelbla, :HTLP
31
26
 
32
- # it_should_generate_from({}, {})
33
- # it_should_generate_from({ :maier => nil, :meier => nil }, :MR => [:maier, :meier]) # should be correctly ordered
34
- # it_should_generate_from({ :maier => nil, :meier => nil, :hallaballa => nil }, :MR => [:maier, :meier], :HLPL => [:hallaballa])
35
- # it_should_generate_from({ :susan => nil, :susanne => nil, :bruderer => nil }, :SSN => [:susan, :susanne], :PRTR => [:bruderer])
36
-
37
- # describe 'with reduced amount' do
38
- # before(:each) do
39
- # @similarity = described_class.new(1)
40
- # end
41
- # it_should_generate_from({ :maier => nil, :meier => nil }, :MR => [:maier])
42
- # it_should_generate_from({ :susan => nil, :susanne => nil, :bruderer => nil }, :SSN => [:susan], :PRTR => [:bruderer])
43
- # end
44
-
45
- # describe 'hashify' do
46
- # it 'should turn an empty list into an empty hash' do
47
- # @similarity.send(:hashify, []).should == {}
48
- # end
49
- # it 'should turn the list into an unordered similarity' do
50
- # @similarity.send(:hashify, [:meier, :maier]).should == { :MR => [:meier, :maier] }
51
- # end
52
- # it 'should turn the list into a encoded hash' do
53
- # @similarity.send(:hashify, [:meier, :maier, :peter]).should == { :MR => [:meier, :maier], :PTR => [:peter] }
54
- # end
55
- # end
56
- #
57
- # context 'integration' do
58
- # it 'should return the right ordered array' do
59
- # index = @similarity.generate_from :meier => nil, :maier => nil, :mairai => nil, :mair => nil, :meira => nil
60
- # code = @similarity.encoded :maier
61
- #
62
- # index[code].should == [:mair, :maier, :meier, :meira, :mairai]
63
- # end
64
- # end
65
-
66
27
  end
@@ -20,48 +20,8 @@ describe Picky::Generators::Similarity::Metaphone do
20
20
  end
21
21
  end
22
22
 
23
- # def self.it_should_generate_from index, expected
24
- # it "should generate #{expected.inspect} correctly from #{index.inspect}" do
25
- # @similarity.generate_from(index).should == expected
26
- # end
27
- # end
28
-
29
23
  it_should_encode :meier, :MR
30
24
  it_should_encode :grossberger, :KRSBRJR
31
25
  it_should_encode :hadelbla, :HTLBL
32
26
 
33
- # it_should_generate_from({}, {})
34
- # it_should_generate_from({ :maier => nil, :meier => nil }, :MR => [:maier, :meier]) # should be correctly ordered
35
- # it_should_generate_from({ :maier => nil, :meier => nil, :hallaballa => nil }, :MR => [:maier, :meier], :HLBL => [:hallaballa])
36
- # it_should_generate_from({ :susan => nil, :susanne => nil, :bruderer => nil }, :SSN => [:susan, :susanne], :BRTRR => [:bruderer])
37
-
38
- # describe 'with reduced amount' do
39
- # before(:each) do
40
- # @similarity = described_class.new(1)
41
- # end
42
- # it_should_generate_from({ :maier => nil, :meier => nil }, :MR => [:maier])
43
- # it_should_generate_from({ :susan => nil, :susanne => nil, :bruderer => nil }, :SSN => [:susan], :BRTRR => [:bruderer])
44
- # end
45
- #
46
- # describe 'hashify' do
47
- # it 'should turn an empty list into an empty hash' do
48
- # @similarity.send(:hashify, []).should == {}
49
- # end
50
- # it 'should turn the list into an unordered similarity' do
51
- # @similarity.send(:hashify, [:meier, :maier]).should == { :MR => [:meier, :maier] }
52
- # end
53
- # it 'should turn the list into a encoded hash' do
54
- # @similarity.send(:hashify, [:meier, :maier, :peter]).should == { :MR => [:meier, :maier], :PTR => [:peter] }
55
- # end
56
- # end
57
- #
58
- # context 'integration' do
59
- # it 'should return the right ordered array' do
60
- # index = @similarity.generate_from :meier => nil, :maier => nil, :mairai => nil, :mair => nil, :meira => nil
61
- # code = @similarity.encoded :maier
62
- #
63
- # index[code].should == [:mair, :maier, :meier, :meira, :mairai]
64
- # end
65
- # end
66
-
67
27
  end
@@ -20,48 +20,8 @@ describe Picky::Generators::Similarity::Soundex do
20
20
  end
21
21
  end
22
22
 
23
- # def self.it_should_generate_from index, expected
24
- # it "should generate #{expected.inspect} correctly from #{index.inspect}" do
25
- # @similarity.generate_from(index).should == expected
26
- # end
27
- # end
28
-
29
23
  it_should_encode :meier, :M600
30
24
  it_should_encode :grossberger, :G621
31
25
  it_should_encode :hadelbla, :H341
32
26
 
33
- # it_should_generate_from({}, {})
34
- # it_should_generate_from({ :maier => nil, :meier => nil }, :M600 => [:maier, :meier]) # should be correctly ordered
35
- # it_should_generate_from({ :maier => nil, :meier => nil, :hallaballa => nil }, :M600 => [:maier, :meier], :H414 => [:hallaballa])
36
- # it_should_generate_from({ :susan => nil, :susanne => nil, :bruderer => nil }, :S250 => [:susan, :susanne], :B636 => [:bruderer])
37
-
38
- # describe 'with reduced amount' do
39
- # before(:each) do
40
- # @similarity = described_class.new(1)
41
- # end
42
- # it_should_generate_from({ :maier => nil, :meier => nil }, :M600 => [:maier])
43
- # it_should_generate_from({ :susan => nil, :susanne => nil, :bruderer => nil }, :S250 => [:susan], :B636 => [:bruderer])
44
- # end
45
-
46
- # describe 'hashify' do
47
- # it 'should turn an empty list into an empty hash' do
48
- # @similarity.send(:hashify, []).should == {}
49
- # end
50
- # it 'should turn the list into an unordered similarity' do
51
- # @similarity.send(:hashify, [:meier, :maier]).should == { :M600 => [:meier, :maier] }
52
- # end
53
- # it 'should turn the list into a encoded hash' do
54
- # @similarity.send(:hashify, [:meier, :maier, :peter]).should == { :M600 => [:meier, :maier], :P360 => [:peter] }
55
- # end
56
- # end
57
-
58
- # context 'integration' do
59
- # it 'should return the right ordered array' do
60
- # index = @similarity.generate_from :meier => nil, :maier => nil, :mairai => nil, :mair => nil, :meira => nil
61
- # code = @similarity.encoded :maier
62
- #
63
- # index[code].should == [:mair, :maier, :meier, :meira, :mairai]
64
- # end
65
- # end
66
-
67
27
  end
@@ -28,8 +28,8 @@ describe Picky::Generators::Similarity do
28
28
  expect {
29
29
  similarity.from Object.new
30
30
  }.to raise_error(<<-ERROR)
31
- similarity options should be either
32
- * for example a Similarity::Phonetic.new(n), Similarity::Metaphone.new(n), Similarity::DoubleMetaphone.new(n) etc.
31
+ Similarity options should be either
32
+ * for example a Similarity::Soundex.new(n), Similarity::Metaphone.new(n), Similarity::DoubleMetaphone.new(n) etc.
33
33
  or
34
34
  * an object that responds to #encode(text) => encoded_text and #prioritize(array_of_encoded, encoded)
35
35
  ERROR
@@ -38,8 +38,8 @@ ERROR
38
38
  expect {
39
39
  similarity.from Object.new, 'some_index'
40
40
  }.to raise_error(<<-ERROR)
41
- similarity options for some_index should be either
42
- * for example a Similarity::Phonetic.new(n), Similarity::Metaphone.new(n), Similarity::DoubleMetaphone.new(n) etc.
41
+ Similarity options for some_index should be either
42
+ * for example a Similarity::Soundex.new(n), Similarity::Metaphone.new(n), Similarity::DoubleMetaphone.new(n) etc.
43
43
  or
44
44
  * an object that responds to #encode(text) => encoded_text and #prioritize(array_of_encoded, encoded)
45
45
  ERROR
@@ -48,8 +48,8 @@ ERROR
48
48
  expect {
49
49
  similarity.from Object.new, 'some_index', 'some_category'
50
50
  }.to raise_error(<<-ERROR)
51
- similarity options for some_index:some_category should be either
52
- * for example a Similarity::Phonetic.new(n), Similarity::Metaphone.new(n), Similarity::DoubleMetaphone.new(n) etc.
51
+ Similarity options for some_index:some_category should be either
52
+ * for example a Similarity::Soundex.new(n), Similarity::Metaphone.new(n), Similarity::DoubleMetaphone.new(n) etc.
53
53
  or
54
54
  * an object that responds to #encode(text) => encoded_text and #prioritize(array_of_encoded, encoded)
55
55
  ERROR
@@ -2,34 +2,23 @@ require 'spec_helper'
2
2
 
3
3
  describe Picky::Results do
4
4
 
5
- describe "from" do
6
- before(:each) do
7
- @results = double :results
8
- described_class.stub :new => @results
9
-
10
- @results.stub :prepare!
11
- end
12
- it "should generate a result" do
13
- described_class.from("some query", 20, 0, @allocations).should == @results
14
- end
15
- end
16
-
17
5
  describe "ids" do
18
6
  before(:each) do
19
7
  @allocations = double :allocations
20
- @results = described_class.new :unimportant, :amount, :unimportant, @allocations
8
+ @results = described_class.new :unimportant, :amount, :offset, @allocations
21
9
  end
22
10
  it "forwards" do
11
+ @allocations.should_receive(:process!).once.with :amount, :offset, nil
23
12
  @allocations.should_receive(:ids).once.with :anything
24
13
 
25
14
  @results.ids :anything
26
15
  end
27
16
  it "forwards and uses amount if nothing given" do
17
+ @allocations.should_receive(:process!).once.with :amount, :offset, nil
28
18
  @allocations.should_receive(:ids).once.with :amount
29
19
 
30
20
  @results.ids
31
21
  end
32
-
33
22
  end
34
23
 
35
24
  describe 'to_s time format' do
@@ -54,12 +43,12 @@ describe Picky::Results do
54
43
  context 'with results' do
55
44
  before(:each) do
56
45
  @allocations = double :allocations,
57
- :process! => nil,
58
- :size => 12
46
+ :process! => nil,
47
+ :size => 12
59
48
 
60
49
  @results = described_class.new "some_query", 20, 1234, @allocations
61
50
  @results.stub :duration => 0.1234567890,
62
- :total => 12345678
51
+ :total => 12345678
63
52
  end
64
53
  it 'should output a specific log' do
65
54
  @results.to_s.should == '>|2011-08-16 10:07:33|0.123457|some_query |12345678|1234|12|'
@@ -94,7 +83,8 @@ describe Picky::Results do
94
83
 
95
84
  describe "accessors" do
96
85
  before(:each) do
97
- @results = described_class.new :query, :amount, :offset, :allocations
86
+ @allocations = double :allocations, :process! => :allocations
87
+ @results = described_class.new :query, :amount, :offset, @allocations
98
88
  end
99
89
  it "should have accessors for query" do
100
90
  @results.query.should == :query
@@ -106,7 +96,7 @@ describe Picky::Results do
106
96
  @results.offset.should == :offset
107
97
  end
108
98
  it "should have accessors for allocations" do
109
- @results.allocations.should == :allocations
99
+ @results.allocations.should == @allocations
110
100
  end
111
101
  it "should have accessors for duration" do
112
102
  @results.duration = :some_duration
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picky
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.21.2
4
+ version: 4.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Hanke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-03 00:00:00.000000000 Z
11
+ date: 2014-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -259,6 +259,8 @@ files:
259
259
  - spec/functional/regression_spec.rb
260
260
  - spec/functional/reloading_spec.rb
261
261
  - spec/functional/remap_qualifiers_spec.rb
262
+ - spec/functional/results_spec.rb
263
+ - spec/functional/similarity_spec.rb
262
264
  - spec/functional/sorting_spec.rb
263
265
  - spec/functional/speed_spec.rb
264
266
  - spec/functional/static_spec.rb
@@ -438,6 +440,8 @@ test_files:
438
440
  - spec/functional/regression_spec.rb
439
441
  - spec/functional/reloading_spec.rb
440
442
  - spec/functional/remap_qualifiers_spec.rb
443
+ - spec/functional/results_spec.rb
444
+ - spec/functional/similarity_spec.rb
441
445
  - spec/functional/sorting_spec.rb
442
446
  - spec/functional/speed_spec.rb
443
447
  - spec/functional/static_spec.rb