picky 3.4.3 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/aux/picky/cli.rb +1 -1
- data/lib/picky/backends/memory/json.rb +1 -1
- data/lib/picky/backends/memory/text.rb +2 -2
- data/lib/picky/backends/redis/string.rb +6 -0
- data/lib/picky/bundle.rb +0 -1
- data/lib/picky/bundle_indexing.rb +11 -107
- data/lib/picky/bundle_realtime.rb +16 -8
- data/lib/picky/calculations/location.rb +18 -14
- data/lib/picky/categories.rb +1 -1
- data/lib/picky/category.rb +7 -1
- data/lib/picky/category_indexed.rb +1 -0
- data/lib/picky/category_indexing.rb +17 -17
- data/lib/picky/category_realtime.rb +23 -11
- data/lib/picky/deployment.rb +33 -33
- data/lib/picky/generators/partial/substring.rb +0 -2
- data/lib/picky/generators/similarity/double_metaphone.rb +1 -1
- data/lib/picky/generators/similarity/metaphone.rb +1 -1
- data/lib/picky/generators/similarity/soundex.rb +1 -1
- data/lib/picky/index.rb +22 -5
- data/lib/picky/index_indexing.rb +3 -15
- data/lib/picky/indexers/base.rb +7 -3
- data/lib/picky/indexers/parallel.rb +1 -10
- data/lib/picky/indexers/serial.rb +1 -10
- data/lib/picky/indexes.rb +1 -1
- data/lib/picky/loader.rb +2 -6
- data/lib/picky/query/qualifier_category_mapper.rb +2 -2
- data/lib/picky/query/token.rb +1 -2
- data/lib/picky/query/tokens.rb +6 -0
- data/lib/picky/search.rb +1 -0
- data/lib/picky/sources/couch.rb +1 -1
- data/lib/picky/sources/csv.rb +1 -1
- data/lib/picky/sources/mongo.rb +1 -1
- data/lib/picky/wrappers/bundle/calculation.rb +8 -8
- data/lib/picky/wrappers/bundle/delegators.rb +4 -1
- data/lib/picky/wrappers/bundle/exact_partial.rb +1 -1
- data/lib/picky/wrappers/bundle/location.rb +30 -13
- data/lib/picky/wrappers/category/location.rb +14 -9
- data/lib/tasks/try.rb +2 -2
- data/spec/lib/backends/memory/text_spec.rb +6 -6
- data/spec/lib/bundle_spec.rb +4 -4
- data/spec/lib/calculations/location_spec.rb +27 -29
- data/spec/lib/category_indexed_spec.rb +1 -0
- data/spec/lib/category_indexing_spec.rb +23 -36
- data/spec/lib/category_spec.rb +2 -0
- data/spec/lib/extensions/string_spec.rb +1 -1
- data/spec/lib/generators/partial/infix_spec.rb +2 -2
- data/spec/lib/index_indexing_spec.rb +5 -3
- data/spec/lib/indexed/bundle_spec.rb +2 -2
- data/spec/lib/indexers/base_spec.rb +2 -4
- data/spec/lib/indexers/serial_spec.rb +3 -19
- data/spec/lib/indexing/bundle_partial_generation_speed_spec.rb +42 -42
- data/spec/lib/indexing/bundle_spec.rb +4 -133
- data/spec/lib/query/combination_spec.rb +6 -6
- data/spec/lib/query/token_spec.rb +32 -19
- data/spec/lib/query/tokens_spec.rb +23 -10
- metadata +27 -34
- data/lib/picky/no_source_specified_exception.rb +0 -7
- data/lib/picky/wrappers/sources/base.rb +0 -35
- data/lib/picky/wrappers/sources/location.rb +0 -56
- data/spec/lib/sources/wrappers/base_spec.rb +0 -38
- data/spec/lib/sources/wrappers/location_spec.rb +0 -55
@@ -11,15 +11,15 @@ describe Picky::Query::Combination do
|
|
11
11
|
|
12
12
|
@combination = described_class.new @token, @category
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
describe "to_s" do
|
16
16
|
it "shows the combination's info" do
|
17
17
|
@token.stub! :to_result => :token_result
|
18
|
-
|
18
|
+
|
19
19
|
@combination.to_s.should == 'bundle_name some_category_name:token_result'
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
describe 'hash' do
|
24
24
|
it 'should hash the token and the bundle' do
|
25
25
|
@combination.hash.should == [@token.to_s, @bundle].hash
|
@@ -34,7 +34,7 @@ describe Picky::Query::Combination do
|
|
34
34
|
@combination = Picky::Query::Combination.new token, @category
|
35
35
|
end
|
36
36
|
it 'should return a correct result' do
|
37
|
-
@combination.to_result.should == [:some_category_name, 'Blä~',
|
37
|
+
@combination.to_result.should == [:some_category_name, 'Blä~', 'blä'] # Note: Characters not substituted. That's ok.
|
38
38
|
end
|
39
39
|
end
|
40
40
|
it 'should return a correct result' do
|
@@ -52,7 +52,7 @@ describe Picky::Query::Combination do
|
|
52
52
|
|
53
53
|
describe 'ids' do
|
54
54
|
it 'should call ids with the text on bundle' do
|
55
|
-
@bundle.should_receive(:ids).once.with
|
55
|
+
@bundle.should_receive(:ids).once.with 'some_text'
|
56
56
|
|
57
57
|
@combination.ids
|
58
58
|
end
|
@@ -68,7 +68,7 @@ describe Picky::Query::Combination do
|
|
68
68
|
|
69
69
|
describe 'weight' do
|
70
70
|
it 'should call weight with the text on bundle' do
|
71
|
-
@bundle.should_receive(:weight).once.with
|
71
|
+
@bundle.should_receive(:weight).once.with 'some_text'
|
72
72
|
|
73
73
|
@combination.weight
|
74
74
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Picky::Query::Token do
|
5
|
-
|
5
|
+
|
6
6
|
describe '==' do
|
7
7
|
it 'is equal if the originals are equal' do
|
8
8
|
described_class.processed('similar~', 'Similar~').should == described_class.processed('similar~', 'Similar~')
|
@@ -11,12 +11,12 @@ describe Picky::Query::Token do
|
|
11
11
|
described_class.processed('similar~', 'Similar~').should_not == described_class.processed('similar', 'Similar')
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
describe 'next_similar_token' do
|
16
16
|
before(:each) do
|
17
17
|
@bundle = stub :bundle, :similar => [:array, :of, :similar]
|
18
18
|
@category = stub :category, :bundle_for => @bundle
|
19
|
-
|
19
|
+
|
20
20
|
@token = described_class.processed 'similar~', 'Similar~'
|
21
21
|
end
|
22
22
|
it 'returns the right next tokens' do
|
@@ -30,7 +30,7 @@ describe Picky::Query::Token do
|
|
30
30
|
next_token.should == nil
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
describe 'next_similar' do
|
35
35
|
before(:each) do
|
36
36
|
@bundle = stub :bundle
|
@@ -44,7 +44,7 @@ describe Picky::Query::Token do
|
|
44
44
|
end
|
45
45
|
it 'should have a certain original text' do
|
46
46
|
@token.next_similar @bundle
|
47
|
-
|
47
|
+
|
48
48
|
@token.original.should == :array
|
49
49
|
end
|
50
50
|
end
|
@@ -67,7 +67,7 @@ describe Picky::Query::Token do
|
|
67
67
|
@token.next_similar @bundle
|
68
68
|
@token.next_similar @bundle
|
69
69
|
@token.next_similar @bundle
|
70
|
-
|
70
|
+
|
71
71
|
@token.text.should == :similar
|
72
72
|
end
|
73
73
|
end
|
@@ -84,17 +84,17 @@ describe Picky::Query::Token do
|
|
84
84
|
end
|
85
85
|
it 'should have a certain text' do
|
86
86
|
@token.next_similar @bundle
|
87
|
-
|
88
|
-
@token.text.should ==
|
87
|
+
|
88
|
+
@token.text.should == 'nonsimilar'
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
describe "generate_similarity_for" do
|
95
95
|
before(:each) do
|
96
96
|
@bundle = stub :bundle
|
97
|
-
|
97
|
+
|
98
98
|
@token = described_class.processed 'flarb~', 'FLARB~'
|
99
99
|
end
|
100
100
|
context "with similar" do
|
@@ -114,7 +114,7 @@ describe Picky::Query::Token do
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
# describe 'to_solr' do
|
119
119
|
# def self.it_should_solr text, expected_result
|
120
120
|
# it "should solrify into #{expected_result} from #{text}" do
|
@@ -133,7 +133,7 @@ describe Picky::Query::Token do
|
|
133
133
|
# it_should_solr 'searchengi', 'searchengi~0.89'
|
134
134
|
# it_should_solr 'searchengin', 'searchengin~0.9'
|
135
135
|
# it_should_solr 'searchengine', 'searchengine~0.9'
|
136
|
-
#
|
136
|
+
#
|
137
137
|
# it_should_solr 'spec:tex', 'specific:tex'
|
138
138
|
# it_should_solr 'with:text', 'text~0.74'
|
139
139
|
# it_should_solr 'name:', 'name~0.74'
|
@@ -183,7 +183,7 @@ describe Picky::Query::Token do
|
|
183
183
|
described_class.processed('some text', 'SOME TEXT').class.should == described_class
|
184
184
|
end
|
185
185
|
end
|
186
|
-
|
186
|
+
|
187
187
|
describe 'process' do
|
188
188
|
let(:token) { described_class.new 'any_text' }
|
189
189
|
it 'returns itself' do
|
@@ -194,12 +194,25 @@ describe Picky::Query::Token do
|
|
194
194
|
token.should_receive(:partialize).once.ordered
|
195
195
|
token.should_receive(:similarize).once.ordered
|
196
196
|
token.should_receive(:remove_illegals).once.ordered
|
197
|
-
token.should_receive(:symbolize).once.ordered
|
198
197
|
|
199
198
|
token.process
|
200
199
|
end
|
201
200
|
end
|
202
201
|
|
202
|
+
describe 'symbolize!' do
|
203
|
+
before(:each) do
|
204
|
+
@token = described_class.processed 'string', 'String'
|
205
|
+
end
|
206
|
+
it 'is not symbolized' do
|
207
|
+
@token.text.should == 'string'
|
208
|
+
end
|
209
|
+
it 'can be symbolized' do
|
210
|
+
@token.symbolize!
|
211
|
+
|
212
|
+
@token.text.should == :string
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
203
216
|
describe 'partial?' do
|
204
217
|
context 'similar, partial' do
|
205
218
|
before(:each) do
|
@@ -365,7 +378,7 @@ describe Picky::Query::Token do
|
|
365
378
|
end
|
366
379
|
it 'should not set partial' do
|
367
380
|
@token.instance_variable_set :@partial, false
|
368
|
-
|
381
|
+
|
369
382
|
@token.partial = true
|
370
383
|
|
371
384
|
@token.instance_variable_get(:@partial).should be_false
|
@@ -400,20 +413,20 @@ describe Picky::Query::Token do
|
|
400
413
|
it 'should remove *' do
|
401
414
|
token = described_class.processed 'text*'
|
402
415
|
|
403
|
-
token.text.should ==
|
416
|
+
token.text.should == 'text'
|
404
417
|
end
|
405
418
|
it 'should remove ~' do
|
406
419
|
token = described_class.processed 'text~'
|
407
420
|
|
408
|
-
token.text.should ==
|
421
|
+
token.text.should == 'text'
|
409
422
|
end
|
410
423
|
it 'should remove "' do
|
411
424
|
token = described_class.processed 'text"'
|
412
425
|
|
413
|
-
token.text.should ==
|
426
|
+
token.text.should == 'text'
|
414
427
|
end
|
415
428
|
it "should pass on a processed text" do
|
416
|
-
described_class.processed('text').text.should ==
|
429
|
+
described_class.processed('text').text.should == 'text'
|
417
430
|
end
|
418
431
|
end
|
419
432
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Picky::Query::Tokens do
|
4
|
-
|
4
|
+
|
5
5
|
context 'with ignore_unassigned_tokens true' do
|
6
6
|
it 'generates processed tokens from all words' do
|
7
7
|
expected = [
|
@@ -11,12 +11,12 @@ describe Picky::Query::Tokens do
|
|
11
11
|
Picky::Query::Token.processed('sp:solr'),
|
12
12
|
Picky::Query::Token.processed('query"')
|
13
13
|
]
|
14
|
-
|
14
|
+
|
15
15
|
described_class.should_receive(:new).once.with expected, true
|
16
|
-
|
16
|
+
|
17
17
|
described_class.processed ['this~', 'is', 'a', 'sp:solr', 'query"'], [], true
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
describe 'possible_combinations_in' do
|
21
21
|
before(:each) do
|
22
22
|
@token1 = stub :token1
|
@@ -48,7 +48,7 @@ describe Picky::Query::Tokens do
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
describe '.processed' do
|
53
53
|
it 'generates processed tokens from all words' do
|
54
54
|
expected = [
|
@@ -58,9 +58,9 @@ describe Picky::Query::Tokens do
|
|
58
58
|
Picky::Query::Token.processed('sp:solr'),
|
59
59
|
Picky::Query::Token.processed('query"')
|
60
60
|
]
|
61
|
-
|
61
|
+
|
62
62
|
described_class.should_receive(:new).once.with expected, false
|
63
|
-
|
63
|
+
|
64
64
|
described_class.processed ['this~', 'is', 'a', 'sp:solr', 'query"'], []
|
65
65
|
end
|
66
66
|
it 'generates processed tokens from all words' do
|
@@ -71,13 +71,26 @@ describe Picky::Query::Tokens do
|
|
71
71
|
Picky::Query::Token.processed('sp:solr'),
|
72
72
|
Picky::Query::Token.processed('query"')
|
73
73
|
]
|
74
|
-
|
74
|
+
|
75
75
|
described_class.should_receive(:new).once.with expected, false
|
76
|
-
|
76
|
+
|
77
77
|
described_class.processed ['this~', 'is', 'a', 'sp:solr', 'query"'], []
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
+
describe 'symbolize' do
|
82
|
+
let(:tokens) { described_class.processed ['a*', 'b'], ['A*', 'B'] }
|
83
|
+
|
84
|
+
it 'has non symbolized tokens' do
|
85
|
+
tokens.map(&:text).should == ['a', 'b']
|
86
|
+
end
|
87
|
+
it 'symbolizes all tokens' do
|
88
|
+
tokens.symbolize
|
89
|
+
|
90
|
+
tokens.map(&:text).should == [:a, :b]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
81
94
|
describe 'partialize_last' do
|
82
95
|
context 'special case' do
|
83
96
|
before(:each) do
|
@@ -140,7 +153,7 @@ describe Picky::Query::Tokens do
|
|
140
153
|
@token1 = stub :token1
|
141
154
|
@token2 = stub :token2
|
142
155
|
@token3 = stub :token3
|
143
|
-
|
156
|
+
|
144
157
|
@tokens = described_class.new [@token1, @token2, @token3]
|
145
158
|
end
|
146
159
|
it 'should work correctly' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: picky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70136161803160 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,21 +21,21 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70136161803160
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: picky-client
|
27
|
-
requirement: &
|
27
|
+
requirement: &70136161800540 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 3.
|
32
|
+
version: 3.5.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70136161800540
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rack
|
38
|
-
requirement: &
|
38
|
+
requirement: &70136161797800 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70136161797800
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rack_fast_escape
|
49
|
-
requirement: &
|
49
|
+
requirement: &70136161795300 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70136161795300
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: text
|
60
|
-
requirement: &
|
60
|
+
requirement: &70136161794320 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70136161794320
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: yajl-ruby
|
71
|
-
requirement: &
|
71
|
+
requirement: &70136161791120 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70136161791120
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: activesupport
|
82
|
-
requirement: &
|
82
|
+
requirement: &70136161786960 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '3.0'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70136161786960
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: activerecord
|
93
|
-
requirement: &
|
93
|
+
requirement: &70136161784620 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '3.0'
|
99
99
|
type: :runtime
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70136161784620
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: unicorn
|
104
|
-
requirement: &
|
104
|
+
requirement: &70136161782840 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70136161782840
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: sinatra
|
115
|
-
requirement: &
|
115
|
+
requirement: &70136161780240 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :runtime
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70136161780240
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: redis
|
126
|
-
requirement: &
|
126
|
+
requirement: &70136161776800 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *70136161776800
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: mysql
|
137
|
-
requirement: &
|
137
|
+
requirement: &70136161773460 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ! '>='
|
@@ -142,7 +142,7 @@ dependencies:
|
|
142
142
|
version: '0'
|
143
143
|
type: :runtime
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *70136161773460
|
146
146
|
description: Fast Ruby semantic text search engine with comfortable single field interface.
|
147
147
|
email: florian.hanke+picky@gmail.com
|
148
148
|
executables:
|
@@ -234,7 +234,6 @@ files:
|
|
234
234
|
- lib/picky/interfaces/live_parameters.rb
|
235
235
|
- lib/picky/loader.rb
|
236
236
|
- lib/picky/migrations/from_30_to_31.rb
|
237
|
-
- lib/picky/no_source_specified_exception.rb
|
238
237
|
- lib/picky/performant.rb
|
239
238
|
- lib/picky/query/allocation.rb
|
240
239
|
- lib/picky/query/allocations.rb
|
@@ -267,8 +266,6 @@ files:
|
|
267
266
|
- lib/picky/wrappers/bundle/wrapper.rb
|
268
267
|
- lib/picky/wrappers/category/exact_first.rb
|
269
268
|
- lib/picky/wrappers/category/location.rb
|
270
|
-
- lib/picky/wrappers/sources/base.rb
|
271
|
-
- lib/picky/wrappers/sources/location.rb
|
272
269
|
- lib/picky.rb
|
273
270
|
- lib/tasks/try.rb
|
274
271
|
- lib/tasks/application.rake
|
@@ -372,8 +369,6 @@ files:
|
|
372
369
|
- spec/lib/sources/db_spec.rb
|
373
370
|
- spec/lib/sources/delicious_spec.rb
|
374
371
|
- spec/lib/sources/mongo_spec.rb
|
375
|
-
- spec/lib/sources/wrappers/base_spec.rb
|
376
|
-
- spec/lib/sources/wrappers/location_spec.rb
|
377
372
|
- spec/lib/statistics_spec.rb
|
378
373
|
- spec/lib/tasks/try_spec.rb
|
379
374
|
- spec/lib/tokenizer_spec.rb
|
@@ -497,8 +492,6 @@ test_files:
|
|
497
492
|
- spec/lib/sources/db_spec.rb
|
498
493
|
- spec/lib/sources/delicious_spec.rb
|
499
494
|
- spec/lib/sources/mongo_spec.rb
|
500
|
-
- spec/lib/sources/wrappers/base_spec.rb
|
501
|
-
- spec/lib/sources/wrappers/location_spec.rb
|
502
495
|
- spec/lib/statistics_spec.rb
|
503
496
|
- spec/lib/tasks/try_spec.rb
|
504
497
|
- spec/lib/tokenizer_spec.rb
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Picky
|
2
|
-
|
3
|
-
module Wrappers
|
4
|
-
|
5
|
-
# Source wrappers can be used to rewrite data before it goes into the index.
|
6
|
-
#
|
7
|
-
# For example if you want to normalize data.
|
8
|
-
#
|
9
|
-
module Sources # :nodoc:all
|
10
|
-
|
11
|
-
class Base
|
12
|
-
|
13
|
-
attr_reader :source
|
14
|
-
|
15
|
-
# Wraps an indexing category.
|
16
|
-
#
|
17
|
-
def initialize source
|
18
|
-
@source = source
|
19
|
-
end
|
20
|
-
|
21
|
-
# Default is delegation for all methods
|
22
|
-
#
|
23
|
-
delegate :harvest,
|
24
|
-
:connect_backend,
|
25
|
-
:take_snapshot,
|
26
|
-
:key_format,
|
27
|
-
:to => :source
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
module Picky
|
2
|
-
|
3
|
-
module Wrappers
|
4
|
-
|
5
|
-
module Sources
|
6
|
-
|
7
|
-
# Should this actually just be a tokenizer?
|
8
|
-
#
|
9
|
-
class Location < Base
|
10
|
-
|
11
|
-
attr_reader :calculation
|
12
|
-
|
13
|
-
def initialize source, grid, precision = 1
|
14
|
-
super source
|
15
|
-
@calculation = Calculations::Location.new grid, precision
|
16
|
-
end
|
17
|
-
|
18
|
-
# Yield the data (id, text for id) for the given category.
|
19
|
-
#
|
20
|
-
def harvest category
|
21
|
-
minimum = 1.0/0
|
22
|
-
|
23
|
-
# Cache.
|
24
|
-
#
|
25
|
-
locations = []
|
26
|
-
|
27
|
-
# Gather min/max.
|
28
|
-
#
|
29
|
-
source.harvest category do |indexed_id, location|
|
30
|
-
location = location.to_f
|
31
|
-
minimum = location if location < minimum
|
32
|
-
locations << [indexed_id, location]
|
33
|
-
end
|
34
|
-
|
35
|
-
calculation.minimum = minimum
|
36
|
-
|
37
|
-
# Recalculate locations.
|
38
|
-
#
|
39
|
-
locations.each do |indexed_id, location|
|
40
|
-
calculation.recalculated_range(location).each do |new_location|
|
41
|
-
yield indexed_id, new_location.to_s
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# TODO Move to the right place.
|
46
|
-
#
|
47
|
-
category.exact[:location_minimum] = minimum
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Picky::Wrappers::Sources::Base do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@source = stub :source
|
7
|
-
end
|
8
|
-
|
9
|
-
context "with backend" do
|
10
|
-
it "doesn't fail" do
|
11
|
-
lambda { described_class.new(@source) }.should_not raise_error
|
12
|
-
end
|
13
|
-
before(:each) do
|
14
|
-
@wrapper = described_class.new @source
|
15
|
-
end
|
16
|
-
it "delegates harvest" do
|
17
|
-
@source.should_receive(:harvest).once.with :some_category
|
18
|
-
|
19
|
-
@wrapper.harvest :some_category
|
20
|
-
end
|
21
|
-
it "delegates take_snapshot" do
|
22
|
-
@source.should_receive(:take_snapshot).once.with :some_index
|
23
|
-
|
24
|
-
@wrapper.take_snapshot :some_index
|
25
|
-
end
|
26
|
-
it "delegates connect_backend" do
|
27
|
-
@source.should_receive(:connect_backend).once.with # nothing
|
28
|
-
|
29
|
-
@wrapper.connect_backend
|
30
|
-
end
|
31
|
-
end
|
32
|
-
context "without backend" do
|
33
|
-
it "fails" do
|
34
|
-
lambda { described_class.new }.should raise_error(ArgumentError)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Picky::Wrappers::Sources::Location do
|
4
|
-
|
5
|
-
context "with backend" do
|
6
|
-
before(:each) do
|
7
|
-
@source = stub :source
|
8
|
-
@category = stub :category
|
9
|
-
end
|
10
|
-
context "without grid option" do
|
11
|
-
it "fails" do
|
12
|
-
lambda { described_class.new(:something) }.should raise_error
|
13
|
-
end
|
14
|
-
end
|
15
|
-
context "with grid option" do
|
16
|
-
before(:each) do
|
17
|
-
@wrapper = described_class.new @source, 10
|
18
|
-
end
|
19
|
-
it "uses a default of 1 on the precision" do
|
20
|
-
@wrapper.calculation.precision.should == 1
|
21
|
-
end
|
22
|
-
it "delegates harvest" do
|
23
|
-
@category.stub! :exact => {}
|
24
|
-
|
25
|
-
@source.should_receive(:harvest).once.with @category
|
26
|
-
|
27
|
-
@wrapper.harvest @category
|
28
|
-
end
|
29
|
-
it "delegates take_snapshot" do
|
30
|
-
@source.should_receive(:take_snapshot).once.with()
|
31
|
-
|
32
|
-
@wrapper.take_snapshot
|
33
|
-
end
|
34
|
-
it "delegates connect_backend" do
|
35
|
-
@source.should_receive(:connect_backend).once.with()
|
36
|
-
|
37
|
-
@wrapper.connect_backend
|
38
|
-
end
|
39
|
-
end
|
40
|
-
context "with grid and precision option" do
|
41
|
-
before(:each) do
|
42
|
-
@wrapper = described_class.new @category, 4, 2
|
43
|
-
end
|
44
|
-
it "uses the given precision" do
|
45
|
-
@wrapper.calculation.precision.should == 2
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
context "without backend" do
|
50
|
-
it "fails" do
|
51
|
-
lambda { described_class.new }.should raise_error(ArgumentError)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|