picky 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/picky/{alias_instances.rb → aliases.rb} +1 -3
- data/lib/picky/application.rb +18 -19
- data/lib/picky/cores.rb +1 -1
- data/lib/picky/generators/aliases.rb +3 -0
- data/lib/picky/index/base.rb +179 -0
- data/lib/picky/index/memory.rb +28 -0
- data/lib/picky/index/redis.rb +28 -0
- data/lib/picky/{indexes_api.rb → index_bundle.rb} +16 -16
- data/lib/picky/indexed/indexes.rb +11 -7
- data/lib/picky/indexing/indexes.rb +14 -8
- data/lib/picky/internals/adapters/rack/base.rb +27 -0
- data/lib/picky/internals/adapters/rack/live_parameters.rb +37 -0
- data/lib/picky/internals/adapters/rack/query.rb +63 -0
- data/lib/picky/internals/adapters/rack.rb +34 -0
- data/lib/picky/{calculations → internals/calculations}/location.rb +0 -0
- data/lib/picky/{cli.rb → internals/cli.rb} +0 -0
- data/lib/picky/{configuration → internals/configuration}/index.rb +8 -2
- data/lib/picky/{ext → internals/ext}/maybe_compile.rb +0 -0
- data/lib/picky/{ext → internals/ext}/ruby19/extconf.rb +0 -0
- data/lib/picky/{ext → internals/ext}/ruby19/performant.c +0 -0
- data/lib/picky/{extensions → internals/extensions}/array.rb +0 -0
- data/lib/picky/{extensions → internals/extensions}/hash.rb +0 -0
- data/lib/picky/{extensions → internals/extensions}/module.rb +0 -0
- data/lib/picky/{extensions → internals/extensions}/object.rb +0 -0
- data/lib/picky/{extensions → internals/extensions}/symbol.rb +0 -0
- data/lib/picky/internals/frontend_adapters/rack.rb +154 -0
- data/lib/picky/internals/generators/base.rb +19 -0
- data/lib/picky/internals/generators/partial/default.rb +7 -0
- data/lib/picky/internals/generators/partial/none.rb +35 -0
- data/lib/picky/internals/generators/partial/strategy.rb +29 -0
- data/lib/picky/internals/generators/partial/substring.rb +122 -0
- data/lib/picky/internals/generators/partial_generator.rb +19 -0
- data/lib/picky/internals/generators/similarity/default.rb +9 -0
- data/lib/picky/internals/generators/similarity/double_levenshtone.rb +81 -0
- data/lib/picky/internals/generators/similarity/none.rb +35 -0
- data/lib/picky/internals/generators/similarity/strategy.rb +11 -0
- data/lib/picky/internals/generators/similarity_generator.rb +19 -0
- data/lib/picky/internals/generators/strategy.rb +18 -0
- data/lib/picky/internals/generators/weights/default.rb +9 -0
- data/lib/picky/internals/generators/weights/logarithmic.rb +43 -0
- data/lib/picky/internals/generators/weights/strategy.rb +11 -0
- data/lib/picky/internals/generators/weights_generator.rb +19 -0
- data/lib/picky/{helpers → internals/helpers}/measuring.rb +0 -0
- data/lib/picky/internals/index/backend.rb +113 -0
- data/lib/picky/internals/index/file/basic.rb +101 -0
- data/lib/picky/internals/index/file/json.rb +38 -0
- data/lib/picky/internals/index/file/marshal.rb +38 -0
- data/lib/picky/internals/index/file/text.rb +60 -0
- data/lib/picky/internals/index/files.rb +24 -0
- data/lib/picky/internals/index/redis/basic.rb +77 -0
- data/lib/picky/internals/index/redis/list_hash.rb +46 -0
- data/lib/picky/internals/index/redis/string_hash.rb +35 -0
- data/lib/picky/internals/index/redis.rb +44 -0
- data/lib/picky/internals/indexed/bundle/base.rb +72 -0
- data/lib/picky/internals/indexed/bundle/memory.rb +69 -0
- data/lib/picky/internals/indexed/bundle/redis.rb +70 -0
- data/lib/picky/internals/indexed/categories.rb +135 -0
- data/lib/picky/internals/indexed/category.rb +90 -0
- data/lib/picky/internals/indexed/index.rb +57 -0
- data/lib/picky/{indexed → internals/indexed}/wrappers/bundle/calculation.rb +0 -0
- data/lib/picky/{indexed → internals/indexed}/wrappers/bundle/location.rb +4 -2
- data/lib/picky/{indexed → internals/indexed}/wrappers/bundle/wrapper.rb +1 -1
- data/lib/picky/internals/indexed/wrappers/exact_first.rb +65 -0
- data/lib/picky/{indexers → internals/indexers}/no_source_specified_error.rb +0 -0
- data/lib/picky/{indexers → internals/indexers}/serial.rb +2 -2
- data/lib/picky/{indexers → internals/indexers}/solr.rb +0 -0
- data/lib/picky/internals/indexing/bundle/base.rb +219 -0
- data/lib/picky/internals/indexing/bundle/memory.rb +25 -0
- data/lib/picky/internals/indexing/bundle/redis.rb +28 -0
- data/lib/picky/internals/indexing/bundle/super_base.rb +65 -0
- data/lib/picky/internals/indexing/categories.rb +42 -0
- data/lib/picky/internals/indexing/category.rb +120 -0
- data/lib/picky/internals/indexing/index.rb +67 -0
- data/lib/picky/{performant.rb → internals/performant.rb} +0 -0
- data/lib/picky/internals/query/allocation.rb +88 -0
- data/lib/picky/internals/query/allocations.rb +137 -0
- data/lib/picky/internals/query/combination.rb +80 -0
- data/lib/picky/internals/query/combinations/base.rb +84 -0
- data/lib/picky/internals/query/combinations/memory.rb +58 -0
- data/lib/picky/internals/query/combinations/redis.rb +59 -0
- data/lib/picky/internals/query/indexes.rb +180 -0
- data/lib/picky/internals/query/qualifiers.rb +81 -0
- data/lib/picky/internals/query/token.rb +215 -0
- data/lib/picky/internals/query/tokens.rb +89 -0
- data/lib/picky/{query → internals/query}/weights.rb +0 -0
- data/lib/picky/internals/results/base.rb +106 -0
- data/lib/picky/internals/results/full.rb +17 -0
- data/lib/picky/internals/results/live.rb +17 -0
- data/lib/picky/{solr → internals/solr}/schema_generator.rb +0 -0
- data/lib/picky/internals/tokenizers/base.rb +166 -0
- data/lib/picky/internals/tokenizers/index.rb +63 -0
- data/lib/picky/internals/tokenizers/query.rb +79 -0
- data/lib/picky/loader.rb +148 -112
- data/lib/picky/query/base.rb +57 -26
- data/lib/picky/query/full.rb +1 -1
- data/lib/picky/query/live.rb +1 -1
- data/lib/picky/sources/db.rb +27 -6
- data/lib/tasks/index.rake +3 -3
- data/lib/tasks/try.rake +2 -2
- data/spec/lib/aliases_spec.rb +9 -0
- data/spec/lib/application_spec.rb +3 -3
- data/spec/lib/generators/aliases_spec.rb +1 -0
- data/spec/lib/{index_api_spec.rb → index/base_spec.rb} +7 -7
- data/spec/lib/index_bundle_spec.rb +71 -0
- data/spec/lib/indexed/indexes_spec.rb +61 -0
- data/spec/lib/indexing/indexes_spec.rb +94 -24
- data/spec/lib/{adapters → internals/adapters}/rack/base_spec.rb +2 -2
- data/spec/lib/{adapters → internals/adapters}/rack/live_parameters_spec.rb +2 -2
- data/spec/lib/{adapters → internals/adapters}/rack/query_spec.rb +2 -2
- data/spec/lib/{calculations → internals/calculations}/location_spec.rb +0 -0
- data/spec/lib/{cli_spec.rb → internals/cli_spec.rb} +4 -1
- data/spec/lib/{configuration → internals/configuration}/index_spec.rb +1 -1
- data/spec/lib/{cores_spec.rb → internals/cores_spec.rb} +0 -0
- data/spec/lib/{extensions → internals/extensions}/array_spec.rb +0 -0
- data/spec/lib/{extensions → internals/extensions}/hash_spec.rb +0 -0
- data/spec/lib/{extensions → internals/extensions}/module_spec.rb +0 -0
- data/spec/lib/{extensions → internals/extensions}/object_spec.rb +0 -0
- data/spec/lib/{extensions → internals/extensions}/symbol_spec.rb +0 -0
- data/spec/lib/{frontend_adapters → internals/frontend_adapters}/rack_spec.rb +11 -11
- data/spec/lib/{cacher → internals/generators}/cacher_strategy_spec.rb +2 -2
- data/spec/lib/internals/generators/partial/default_spec.rb +17 -0
- data/spec/lib/internals/generators/partial/none_spec.rb +17 -0
- data/spec/lib/{cacher → internals/generators}/partial/substring_spec.rb +26 -27
- data/spec/lib/{cacher → internals/generators}/partial_generator_spec.rb +5 -5
- data/spec/lib/{cacher → internals/generators}/similarity/double_levenshtone_spec.rb +4 -4
- data/spec/lib/{cacher → internals/generators}/similarity/none_spec.rb +2 -2
- data/spec/lib/{cacher → internals/generators}/similarity_generator_spec.rb +4 -4
- data/spec/lib/{cacher → internals/generators}/weights/logarithmic_spec.rb +2 -2
- data/spec/lib/internals/generators/weights_generator_spec.rb +21 -0
- data/spec/lib/{helpers → internals/helpers}/measuring_spec.rb +0 -0
- data/spec/lib/{index → internals/index}/file/basic_spec.rb +2 -2
- data/spec/lib/{index → internals/index}/file/json_spec.rb +2 -2
- data/spec/lib/{index → internals/index}/file/marshal_spec.rb +2 -2
- data/spec/lib/{index → internals/index}/file/text_spec.rb +2 -2
- data/spec/lib/{index → internals/index}/files_spec.rb +2 -2
- data/spec/lib/{indexed/bundle_spec.rb → internals/indexed/bundle/memory_spec.rb} +4 -5
- data/spec/lib/{indexed → internals/indexed}/categories_spec.rb +13 -13
- data/spec/lib/{indexed → internals/indexed}/category_spec.rb +59 -32
- data/spec/lib/{indexed → internals/indexed}/index_spec.rb +5 -5
- data/spec/lib/{indexed → internals/indexed}/wrappers/bundle/calculation_spec.rb +0 -0
- data/spec/lib/{indexed → internals/indexed}/wrappers/bundle/wrapper_spec.rb +0 -0
- data/spec/lib/{indexed → internals/indexed}/wrappers/exact_first_spec.rb +5 -5
- data/spec/lib/{indexers → internals/indexers}/serial_spec.rb +0 -0
- data/spec/lib/{indexing/bundle_partial_generation_speed_spec.rb → internals/indexing/bundle/memory_partial_generation_speed_spec.rb} +3 -3
- data/spec/lib/{indexing/bundle_spec.rb → internals/indexing/bundle/memory_spec.rb} +3 -3
- data/spec/lib/{index/bundle_spec.rb → internals/indexing/bundle/super_base_spec.rb} +9 -3
- data/spec/lib/{indexing → internals/indexing}/category_spec.rb +3 -3
- data/spec/lib/{indexing → internals/indexing}/index_spec.rb +3 -3
- data/spec/lib/internals/indexing/indexes_spec.rb +36 -0
- data/spec/lib/{interfaces → internals/interfaces}/live_parameters_spec.rb +0 -0
- data/spec/lib/internals/results/base_spec.rb +105 -0
- data/spec/lib/internals/results/full_spec.rb +78 -0
- data/spec/lib/internals/results/live_spec.rb +88 -0
- data/spec/lib/{solr → internals/solr}/schema_generator_spec.rb +0 -0
- data/spec/lib/{tokenizers → internals/tokenizers}/base_spec.rb +3 -3
- data/spec/lib/{tokenizers → internals/tokenizers}/index_spec.rb +9 -9
- data/spec/lib/{tokenizers → internals/tokenizers}/query_spec.rb +11 -11
- data/spec/lib/query/allocation_spec.rb +12 -12
- data/spec/lib/query/allocations_spec.rb +19 -19
- data/spec/lib/query/base_spec.rb +28 -4
- data/spec/lib/query/combination_spec.rb +8 -9
- data/spec/lib/query/combinations/base_spec.rb +116 -0
- data/spec/lib/query/{combinations_spec.rb → combinations/memory_spec.rb} +14 -14
- data/spec/lib/query/combinations/redis_spec.rb +132 -0
- data/spec/lib/query/full_spec.rb +2 -2
- data/spec/lib/query/indexes_spec.rb +81 -0
- data/spec/lib/query/live_spec.rb +3 -3
- data/spec/lib/query/qualifiers_spec.rb +6 -6
- data/spec/lib/query/token_spec.rb +38 -38
- data/spec/lib/query/tokens_spec.rb +35 -35
- data/spec/lib/sources/db_spec.rb +23 -18
- metadata +212 -181
- data/lib/picky/adapters/rack/base.rb +0 -23
- data/lib/picky/adapters/rack/live_parameters.rb +0 -33
- data/lib/picky/adapters/rack/query.rb +0 -59
- data/lib/picky/adapters/rack.rb +0 -28
- data/lib/picky/cacher/convenience.rb +0 -3
- data/lib/picky/cacher/generator.rb +0 -15
- data/lib/picky/cacher/partial/default.rb +0 -5
- data/lib/picky/cacher/partial/none.rb +0 -31
- data/lib/picky/cacher/partial/strategy.rb +0 -21
- data/lib/picky/cacher/partial/substring.rb +0 -118
- data/lib/picky/cacher/partial_generator.rb +0 -15
- data/lib/picky/cacher/similarity/default.rb +0 -7
- data/lib/picky/cacher/similarity/double_levenshtone.rb +0 -77
- data/lib/picky/cacher/similarity/none.rb +0 -31
- data/lib/picky/cacher/similarity/strategy.rb +0 -9
- data/lib/picky/cacher/similarity_generator.rb +0 -15
- data/lib/picky/cacher/strategy.rb +0 -12
- data/lib/picky/cacher/weights/default.rb +0 -7
- data/lib/picky/cacher/weights/logarithmic.rb +0 -39
- data/lib/picky/cacher/weights/strategy.rb +0 -9
- data/lib/picky/cacher/weights_generator.rb +0 -15
- data/lib/picky/frontend_adapters/rack.rb +0 -150
- data/lib/picky/index/bundle.rb +0 -54
- data/lib/picky/index/file/basic.rb +0 -97
- data/lib/picky/index/file/json.rb +0 -34
- data/lib/picky/index/file/marshal.rb +0 -34
- data/lib/picky/index/file/text.rb +0 -56
- data/lib/picky/index/files.rb +0 -118
- data/lib/picky/index_api.rb +0 -175
- data/lib/picky/indexed/bundle.rb +0 -54
- data/lib/picky/indexed/categories.rb +0 -131
- data/lib/picky/indexed/category.rb +0 -85
- data/lib/picky/indexed/index.rb +0 -39
- data/lib/picky/indexed/wrappers/exact_first.rb +0 -61
- data/lib/picky/indexing/bundle.rb +0 -213
- data/lib/picky/indexing/categories.rb +0 -38
- data/lib/picky/indexing/category.rb +0 -117
- data/lib/picky/indexing/index.rb +0 -55
- data/lib/picky/query/allocation.rb +0 -82
- data/lib/picky/query/allocations.rb +0 -130
- data/lib/picky/query/combination.rb +0 -74
- data/lib/picky/query/combinations.rb +0 -105
- data/lib/picky/query/qualifiers.rb +0 -77
- data/lib/picky/query/token.rb +0 -202
- data/lib/picky/query/tokens.rb +0 -86
- data/lib/picky/query/weigher.rb +0 -165
- data/lib/picky/results/base.rb +0 -102
- data/lib/picky/results/full.rb +0 -13
- data/lib/picky/results/live.rb +0 -13
- data/lib/picky/tokenizers/base.rb +0 -161
- data/lib/picky/tokenizers/index.rb +0 -58
- data/lib/picky/tokenizers/query.rb +0 -74
- data/spec/lib/cacher/partial/default_spec.rb +0 -15
- data/spec/lib/cacher/partial/none_spec.rb +0 -17
- data/spec/lib/cacher/weights_generator_spec.rb +0 -21
- data/spec/lib/results/base_spec.rb +0 -257
- data/spec/lib/results/live_spec.rb +0 -15
@@ -1,24 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Internals::Generators::Partial::Substring do
|
4
4
|
|
5
5
|
context 'default from' do
|
6
|
-
|
7
|
-
|
8
|
-
end
|
6
|
+
let(:generator) { described_class.new }
|
7
|
+
|
9
8
|
describe 'use_exact_for_partial?' do
|
10
9
|
it 'returns false' do
|
11
|
-
|
10
|
+
described_class.new.use_exact_for_partial?.should == false
|
12
11
|
end
|
13
12
|
end
|
14
13
|
describe 'from' do
|
15
14
|
it 'should return the right value' do
|
16
|
-
|
15
|
+
generator.from.should == 1
|
17
16
|
end
|
18
17
|
end
|
19
18
|
describe 'generate_from' do
|
20
19
|
it 'should generate the right index' do
|
21
|
-
|
20
|
+
generator.generate_from(florian: [1], flavia: [2]).should == {
|
22
21
|
florian: [1],
|
23
22
|
floria: [1],
|
24
23
|
flori: [1],
|
@@ -33,10 +32,10 @@ describe Cacher::Partial::Substring do
|
|
33
32
|
}
|
34
33
|
end
|
35
34
|
it "should be fast" do
|
36
|
-
performance_of {
|
35
|
+
performance_of { generator.generate_from(florian: [1], flavia: [2]) }.should < 0.0001
|
37
36
|
end
|
38
37
|
it "should handle duplicate ids" do
|
39
|
-
|
38
|
+
generator.generate_from(flo: [1], fla: [1]).should == {
|
40
39
|
flo: [1],
|
41
40
|
fl: [1],
|
42
41
|
f: [1],
|
@@ -48,10 +47,10 @@ describe Cacher::Partial::Substring do
|
|
48
47
|
context 'from set' do
|
49
48
|
describe 'negative from' do
|
50
49
|
before(:each) do
|
51
|
-
@
|
50
|
+
@generator = described_class.new from: -2
|
52
51
|
end
|
53
52
|
it 'should generate the right index' do
|
54
|
-
@
|
53
|
+
@generator.generate_from(florian: [1], flavia: [2]).should == {
|
55
54
|
florian: [1],
|
56
55
|
floria: [1],
|
57
56
|
flavia: [2],
|
@@ -61,11 +60,11 @@ describe Cacher::Partial::Substring do
|
|
61
60
|
end
|
62
61
|
context "large from" do
|
63
62
|
before(:each) do
|
64
|
-
@
|
63
|
+
@generator = described_class.new from: 10
|
65
64
|
end
|
66
65
|
describe 'generate_from' do
|
67
66
|
it 'should generate the right index' do
|
68
|
-
@
|
67
|
+
@generator.generate_from(florian: [1], :'01234567890' => [2] ).should == {
|
69
68
|
:florian => [1],
|
70
69
|
:'01234567890' => [2],
|
71
70
|
:'0123456789' => [2]
|
@@ -75,21 +74,21 @@ describe Cacher::Partial::Substring do
|
|
75
74
|
end
|
76
75
|
context 'default to' do
|
77
76
|
before(:each) do
|
78
|
-
@
|
77
|
+
@generator = described_class.new from: 4
|
79
78
|
end
|
80
79
|
describe 'to' do
|
81
80
|
it 'should return the right value' do
|
82
|
-
@
|
81
|
+
@generator.to.should == -1
|
83
82
|
end
|
84
83
|
end
|
85
84
|
describe 'from' do
|
86
85
|
it 'should return the right value' do
|
87
|
-
@
|
86
|
+
@generator.from.should == 4
|
88
87
|
end
|
89
88
|
end
|
90
89
|
describe 'generate_from' do
|
91
90
|
it 'should generate the right index' do
|
92
|
-
@
|
91
|
+
@generator.generate_from( :florian => [1], :flavia => [2] ).should == {
|
93
92
|
:florian => [1],
|
94
93
|
:floria => [1],
|
95
94
|
:flori => [1],
|
@@ -111,7 +110,7 @@ describe Cacher::Partial::Substring do
|
|
111
110
|
end
|
112
111
|
end
|
113
112
|
it "should be fast" do
|
114
|
-
performance_of { @
|
113
|
+
performance_of { @generator.generate_from(@index) }.should < 0.008
|
115
114
|
end
|
116
115
|
end
|
117
116
|
describe "a bigger example with almost identical symbols" do
|
@@ -123,27 +122,27 @@ describe Cacher::Partial::Substring do
|
|
123
122
|
end
|
124
123
|
end
|
125
124
|
it "should be fast" do
|
126
|
-
performance_of { @
|
125
|
+
performance_of { @generator.generate_from(@index) }.should < 0.0045
|
127
126
|
end
|
128
127
|
end
|
129
128
|
end
|
130
129
|
context 'to set' do
|
131
130
|
before(:each) do
|
132
|
-
@
|
131
|
+
@generator = described_class.new from: 4, to: -2
|
133
132
|
end
|
134
133
|
describe 'to' do
|
135
134
|
it 'should return the right value' do
|
136
|
-
@
|
135
|
+
@generator.to.should == -2
|
137
136
|
end
|
138
137
|
end
|
139
138
|
describe 'from' do
|
140
139
|
it 'should return the right value' do
|
141
|
-
@
|
140
|
+
@generator.from.should == 4
|
142
141
|
end
|
143
142
|
end
|
144
143
|
describe 'generate_from' do
|
145
144
|
it 'should generate the right index' do
|
146
|
-
@
|
145
|
+
@generator.generate_from( :florian => [1], :flavia => [2] ).should == {
|
147
146
|
:floria => [1],
|
148
147
|
:flori => [1],
|
149
148
|
:flor => [1],
|
@@ -155,21 +154,21 @@ describe Cacher::Partial::Substring do
|
|
155
154
|
end
|
156
155
|
context 'to set' do
|
157
156
|
before(:each) do
|
158
|
-
@
|
157
|
+
@generator = described_class.new from: 4, to: 0
|
159
158
|
end
|
160
159
|
describe 'to' do
|
161
160
|
it 'should return the right value' do
|
162
|
-
@
|
161
|
+
@generator.to.should == 0
|
163
162
|
end
|
164
163
|
end
|
165
164
|
describe 'from' do
|
166
165
|
it 'should return the right value' do
|
167
|
-
@
|
166
|
+
@generator.from.should == 4
|
168
167
|
end
|
169
168
|
end
|
170
169
|
describe 'generate_from' do
|
171
170
|
it 'should generate the right index' do
|
172
|
-
@
|
171
|
+
@generator.generate_from( :florian => [1], :flavia => [2] ).should == {
|
173
172
|
:florian => [1],
|
174
173
|
:floria => [1],
|
175
174
|
:flori => [1],
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Internals::Generators::PartialGenerator do
|
4
4
|
|
5
5
|
context 'integration' do
|
6
6
|
it 'should generate the correct values with a given strategy' do
|
7
|
-
generator =
|
7
|
+
generator = described_class.new :meier => [1], :maier => [2]
|
8
8
|
|
9
|
-
generator.generate(
|
9
|
+
generator.generate(Internals::Generators::Partial::Substring.new).should == {
|
10
10
|
:meier => [1],
|
11
11
|
:meie => [1],
|
12
12
|
:mei => [1],
|
@@ -19,9 +19,9 @@ describe Cacher::PartialGenerator do
|
|
19
19
|
}
|
20
20
|
end
|
21
21
|
it 'should generate the correct values with a given specific strategy' do
|
22
|
-
generator =
|
22
|
+
generator = described_class.new :meier => [1], :maier => [2]
|
23
23
|
|
24
|
-
generator.generate(
|
24
|
+
generator.generate(Internals::Generators::Partial::Substring.new(:from => 3)).should == {
|
25
25
|
:meier => [1],
|
26
26
|
:meie => [1],
|
27
27
|
:mei => [1],
|
@@ -2,10 +2,10 @@
|
|
2
2
|
#
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe Internals::Generators::Similarity::DoubleLevenshtone do
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
@similarity =
|
8
|
+
@similarity = described_class.new
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.it_should_encode text, expected
|
@@ -30,7 +30,7 @@ describe Cacher::Similarity::DoubleLevenshtone do
|
|
30
30
|
|
31
31
|
describe 'with reduced amount' do
|
32
32
|
before(:each) do
|
33
|
-
@similarity =
|
33
|
+
@similarity = described_class.new(1)
|
34
34
|
end
|
35
35
|
it_should_generate_from({ :maier => nil, :meier => nil }, :MR => [:maier])
|
36
36
|
it_should_generate_from({ :susan => nil, :susanne => nil, :bruderer => nil }, :SSN => [:susan], :PRTR => [:bruderer])
|
@@ -59,7 +59,7 @@ describe Cacher::Similarity::DoubleLevenshtone do
|
|
59
59
|
|
60
60
|
context "alias" do
|
61
61
|
it "works also with Phonetic" do
|
62
|
-
lambda {
|
62
|
+
lambda { Internals::Generators::Similarity::Phonetic.new(1) }.should_not raise_error
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -2,10 +2,10 @@
|
|
2
2
|
#
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe Internals::Generators::Similarity::None do
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
@similarity =
|
8
|
+
@similarity = described_class.new
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "saved?" do
|
@@ -1,21 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Internals::Generators::SimilarityGenerator do
|
4
4
|
|
5
5
|
context 'integration' do
|
6
6
|
it 'should generate the correct values' do
|
7
|
-
generator =
|
7
|
+
generator = described_class.new :anything_really
|
8
8
|
|
9
9
|
generator.generate.should == {}
|
10
10
|
end
|
11
11
|
it 'should generate the correct values with a given strategy' do
|
12
|
-
generator =
|
12
|
+
generator = described_class.new :meier => nil,
|
13
13
|
:maier => nil,
|
14
14
|
:mayer => nil,
|
15
15
|
:meyer => nil,
|
16
16
|
:peter => nil
|
17
17
|
|
18
|
-
generator.generate(
|
18
|
+
generator.generate(Internals::Generators::Similarity::DoubleLevenshtone.new).should == { :MR => [:meier, :maier, :mayer, :meyer], :PTR => [:peter] }
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Internals::Generators::Weights::Logarithmic do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
@cacher =
|
6
|
+
@cacher = described_class.new
|
7
7
|
end
|
8
8
|
|
9
9
|
describe 'generate_from' do
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Internals::Generators::WeightsGenerator do
|
4
|
+
|
5
|
+
context 'integration' do
|
6
|
+
it 'should generate the correct values' do
|
7
|
+
generator = described_class.new :a => Array.new(0),
|
8
|
+
:b => Array.new(1),
|
9
|
+
:c => Array.new(10),
|
10
|
+
:d => Array.new(100),
|
11
|
+
:e => Array.new(1000)
|
12
|
+
|
13
|
+
result = generator.generate
|
14
|
+
|
15
|
+
result[:c].should be_close 2.3, 0.011
|
16
|
+
result[:d].should be_close 4.6, 0.011
|
17
|
+
result[:e].should be_close 6.9, 0.011
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
File without changes
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Index::File::Basic do
|
3
|
+
describe Internals::Index::File::Basic do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
@file =
|
6
|
+
@file = described_class.new "some/cache/path/to/file"
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "backup_file_path_of" do
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Index::Files do
|
3
|
+
describe Internals::Index::Files do
|
4
4
|
|
5
5
|
before(:each) do
|
6
6
|
index = stub :index, :name => :some_index
|
7
7
|
category = stub :category, :name => :some_category
|
8
8
|
configuration = Configuration::Index.new index, category
|
9
9
|
|
10
|
-
@files =
|
10
|
+
@files = described_class.new :some_name, configuration
|
11
11
|
|
12
12
|
@prepared = @files.prepared
|
13
13
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Indexed::Bundle do
|
3
|
+
describe Internals::Indexed::Bundle::Memory do
|
4
4
|
|
5
5
|
before(:each) do
|
6
6
|
@category = stub :category, :name => :some_category
|
@@ -8,13 +8,12 @@ describe Indexed::Bundle do
|
|
8
8
|
@configuration = Configuration::Index.new @index, @category
|
9
9
|
|
10
10
|
@similarity = stub :similarity
|
11
|
-
@
|
12
|
-
@bundle = @bundle_class.new :some_name, @configuration, @similarity
|
11
|
+
@bundle = described_class.new :some_name, @configuration, @similarity
|
13
12
|
end
|
14
13
|
|
15
14
|
describe 'identifier' do
|
16
15
|
it 'should return a specific identifier' do
|
17
|
-
@bundle.identifier.should == 'some_index
|
16
|
+
@bundle.identifier.should == 'some_index:some_category:some_name'
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
@@ -100,7 +99,7 @@ describe Indexed::Bundle do
|
|
100
99
|
@index = stub :index, :name => :some_index
|
101
100
|
@configuration = Configuration::Index.new @index, @category
|
102
101
|
|
103
|
-
@bundle =
|
102
|
+
@bundle = described_class.new :some_name, @configuration, :similarity
|
104
103
|
end
|
105
104
|
it 'should initialize the index correctly' do
|
106
105
|
@bundle.index.should == {}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Indexed::Categories do
|
3
|
+
describe Internals::Indexed::Categories do
|
4
4
|
context 'with option ignore_unassigned_tokens' do
|
5
5
|
context 'ignore_unassigned_tokens true' do
|
6
6
|
before(:each) do
|
7
|
-
@categories =
|
7
|
+
@categories = described_class.new ignore_unassigned_tokens: true
|
8
8
|
end
|
9
9
|
it 'should return the right value' do
|
10
10
|
@categories.ignore_unassigned_tokens.should == true
|
@@ -12,7 +12,7 @@ describe Indexed::Categories do
|
|
12
12
|
end
|
13
13
|
context 'ignore_unassigned_tokens false' do
|
14
14
|
before(:each) do
|
15
|
-
@categories =
|
15
|
+
@categories = described_class.new ignore_unassigned_tokens: false
|
16
16
|
end
|
17
17
|
it 'should return the right value' do
|
18
18
|
@categories.ignore_unassigned_tokens.should == false
|
@@ -24,14 +24,14 @@ describe Indexed::Categories do
|
|
24
24
|
before(:each) do
|
25
25
|
@index1 = stub :index1, :name => :some_index
|
26
26
|
|
27
|
-
@categories =
|
28
|
-
@categories << Indexed::Category.new(:category1, @index1)
|
29
|
-
@categories << Indexed::Category.new(:category2, @index1)
|
30
|
-
@categories << Indexed::Category.new(:category3, @index1)
|
27
|
+
@categories = described_class.new
|
28
|
+
@categories << Internals::Indexed::Category.new(:category1, @index1)
|
29
|
+
@categories << Internals::Indexed::Category.new(:category2, @index1)
|
30
|
+
@categories << Internals::Indexed::Category.new(:category3, @index1)
|
31
31
|
end
|
32
32
|
describe "similar_possible_for" do
|
33
33
|
before(:each) do
|
34
|
-
@token = Query::Token.processed 'similar~'
|
34
|
+
@token = Internals::Query::Token.processed 'similar~'
|
35
35
|
end
|
36
36
|
it "returns possible categories" do
|
37
37
|
@categories.similar_possible_for(@token).should == []
|
@@ -41,7 +41,7 @@ describe Indexed::Categories do
|
|
41
41
|
|
42
42
|
describe 'clear' do
|
43
43
|
before(:each) do
|
44
|
-
@categories =
|
44
|
+
@categories = described_class.new
|
45
45
|
end
|
46
46
|
it 'is clear right at the beginning' do
|
47
47
|
@categories.categories.should be_empty
|
@@ -67,11 +67,11 @@ describe Indexed::Categories do
|
|
67
67
|
before(:each) do
|
68
68
|
@index1 = stub :index1, :name => :some_index
|
69
69
|
|
70
|
-
@category1 = Indexed::Category.new :category1, @index1
|
71
|
-
@category2 = Indexed::Category.new :category2, @index1
|
72
|
-
@category3 = Indexed::Category.new :category3, @index1
|
70
|
+
@category1 = Internals::Indexed::Category.new :category1, @index1
|
71
|
+
@category2 = Internals::Indexed::Category.new :category2, @index1
|
72
|
+
@category3 = Internals::Indexed::Category.new :category3, @index1
|
73
73
|
|
74
|
-
@categories =
|
74
|
+
@categories = described_class.new
|
75
75
|
@categories << @category1
|
76
76
|
@categories << @category2
|
77
77
|
@categories << @category3
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Indexed::Category do
|
3
|
+
describe Internals::Indexed::Category do
|
4
4
|
|
5
5
|
before(:each) do
|
6
6
|
@index = stub :index, :name => :some_index
|
@@ -11,28 +11,49 @@ describe Indexed::Category do
|
|
11
11
|
@exact = stub :exact, :dump => nil
|
12
12
|
@partial = stub :partial, :dump => nil
|
13
13
|
|
14
|
-
@category =
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
:exact_index_bundle => @exact,
|
19
|
-
:partial_index_bundle => @partial
|
14
|
+
@category = described_class.new :some_name, @index, :partial => @partial_strategy,
|
15
|
+
:weights => @weights_strategy,
|
16
|
+
:similarity => @similarity_strategy,
|
17
|
+
:qualifiers => [:q, :qualifier]
|
20
18
|
|
21
19
|
@category.stub! :exclaim
|
22
20
|
end
|
23
21
|
|
24
22
|
describe 'partial' do
|
25
|
-
context '
|
23
|
+
context 'default' do
|
26
24
|
before(:each) do
|
27
|
-
@
|
25
|
+
@category = described_class.new :some_name, @index
|
28
26
|
end
|
29
|
-
|
30
|
-
|
27
|
+
context 'with a partial strategy that uses the exact index' do
|
28
|
+
before(:each) do
|
29
|
+
@partial_strategy.stub! :use_exact_for_partial? => true
|
30
|
+
end
|
31
|
+
it 'returns the partial index' do
|
32
|
+
@category.partial.should be_kind_of(Internals::Indexed::Bundle::Memory)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
context 'with a partial strategy that uses the partial index (default)' do
|
36
|
+
it 'returns the partial index' do
|
37
|
+
@category.partial.should be_kind_of(Internals::Indexed::Bundle::Memory)
|
38
|
+
end
|
31
39
|
end
|
32
40
|
end
|
33
|
-
context '
|
34
|
-
|
35
|
-
@category.
|
41
|
+
context 'indexed_bundle_class defined' do
|
42
|
+
before(:each) do
|
43
|
+
@category = described_class.new :some_name, @index, :indexed_bundle_class => Internals::Indexed::Bundle::Redis
|
44
|
+
end
|
45
|
+
context 'with a partial strategy that uses the exact index' do
|
46
|
+
before(:each) do
|
47
|
+
@partial_strategy.stub! :use_exact_for_partial? => true
|
48
|
+
end
|
49
|
+
it 'returns the partial index' do
|
50
|
+
@category.partial.should be_kind_of(Internals::Indexed::Bundle::Redis)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
context 'with a partial strategy that uses the partial index (default)' do
|
54
|
+
it 'returns the partial index' do
|
55
|
+
@category.partial.should be_kind_of(Internals::Indexed::Bundle::Redis)
|
56
|
+
end
|
36
57
|
end
|
37
58
|
end
|
38
59
|
end
|
@@ -122,35 +143,41 @@ describe Indexed::Category do
|
|
122
143
|
@category.stub! :weight => :some_weight, :bundle_for => :bundle
|
123
144
|
end
|
124
145
|
it 'should return a new combination' do
|
125
|
-
@category.combination_for(@token).should be_kind_of(::Query::Combination)
|
146
|
+
@category.combination_for(@token).should be_kind_of(Internals::Query::Combination)
|
126
147
|
end
|
127
148
|
it 'should create the combination correctly' do
|
128
|
-
::Query::Combination.should_receive(:new).once.with @token, @category
|
149
|
+
Internals::Query::Combination.should_receive(:new).once.with @token, @category
|
129
150
|
|
130
151
|
@category.combination_for @token
|
131
152
|
end
|
132
153
|
end
|
133
154
|
end
|
155
|
+
|
156
|
+
context 'stubbed exact/partial' do
|
157
|
+
before(:each) do
|
158
|
+
@category.stub! :exact => (@exact = stub :exact)
|
159
|
+
@category.stub! :partial => (@partial = stub :partial)
|
160
|
+
end
|
161
|
+
describe 'bundle_for' do
|
162
|
+
it 'should return the right bundle' do
|
163
|
+
token = stub :token, :partial? => false
|
134
164
|
|
135
|
-
|
136
|
-
|
137
|
-
|
165
|
+
@category.bundle_for(token).should == @exact
|
166
|
+
end
|
167
|
+
it 'should return the right bundle' do
|
168
|
+
token = stub :token, :partial? => true
|
138
169
|
|
139
|
-
|
170
|
+
@category.bundle_for(token).should == @partial
|
171
|
+
end
|
140
172
|
end
|
141
|
-
it 'should return the right bundle' do
|
142
|
-
token = stub :token, :partial? => true
|
143
173
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
@partial.should_receive(:load).once
|
152
|
-
|
153
|
-
@category.load_from_cache
|
174
|
+
describe 'load_from_cache' do
|
175
|
+
it 'should call two methods' do
|
176
|
+
@exact.should_receive(:load).once
|
177
|
+
@partial.should_receive(:load).once
|
178
|
+
|
179
|
+
@category.load_from_cache
|
180
|
+
end
|
154
181
|
end
|
155
182
|
end
|
156
183
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Indexed::Index do
|
3
|
+
describe Internals::Indexed::Index do
|
4
4
|
|
5
5
|
context 'without stubbed categories' do
|
6
6
|
before(:each) do
|
7
|
-
@index =
|
7
|
+
@index = described_class.new :some_index_name
|
8
8
|
end
|
9
9
|
|
10
10
|
describe 'define_category' do
|
@@ -14,7 +14,7 @@ describe Indexed::Index do
|
|
14
14
|
@index.categories.categories.size.should == 1
|
15
15
|
end
|
16
16
|
it 'returns the new category' do
|
17
|
-
@index.define_category(:some_category_name).should be_kind_of(Indexed::Category)
|
17
|
+
@index.define_category(:some_category_name).should be_kind_of(Internals::Indexed::Category)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -23,7 +23,7 @@ describe Indexed::Index do
|
|
23
23
|
before(:each) do
|
24
24
|
@categories = stub :categories
|
25
25
|
|
26
|
-
@index =
|
26
|
+
@index = described_class.new :some_name
|
27
27
|
@index.define_category :some_category_name1
|
28
28
|
@index.define_category :some_category_name2
|
29
29
|
|
@@ -48,7 +48,7 @@ describe Indexed::Index do
|
|
48
48
|
|
49
49
|
context "no categories" do
|
50
50
|
it "works" do
|
51
|
-
|
51
|
+
described_class.new :some_name
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
File without changes
|
File without changes
|