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
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Internals::Query::Indexes do
|
4
|
+
|
5
|
+
3.times do |i|
|
6
|
+
n = i + 1
|
7
|
+
name = :"index#{n}"
|
8
|
+
indexed = :"indexed#{n}"
|
9
|
+
let(name) { stub name, :indexed => stub(indexed) }
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:indexes) { described_class.new index1, index2, index3 }
|
13
|
+
|
14
|
+
describe 'expand_combinations_from' do
|
15
|
+
it 'generates all possible combinations from the given ones' do
|
16
|
+
combinations = [[1,2,3], [:a, :b, :c], [:k, :l]]
|
17
|
+
|
18
|
+
indexes.expand_combinations_from(combinations).should == [
|
19
|
+
[1, :a, :k],
|
20
|
+
[1, :a, :l],
|
21
|
+
[1, :b, :k],
|
22
|
+
[1, :b, :l],
|
23
|
+
[1, :c, :k],
|
24
|
+
[1, :c, :l],
|
25
|
+
[2, :a, :k],
|
26
|
+
[2, :a, :l],
|
27
|
+
[2, :b, :k],
|
28
|
+
[2, :b, :l],
|
29
|
+
[2, :c, :k],
|
30
|
+
[2, :c, :l],
|
31
|
+
[3, :a, :k],
|
32
|
+
[3, :a, :l],
|
33
|
+
[3, :b, :k],
|
34
|
+
[3, :b, :l],
|
35
|
+
[3, :c, :k],
|
36
|
+
[3, :c, :l]
|
37
|
+
]
|
38
|
+
end
|
39
|
+
it 'can handle small combinations' do
|
40
|
+
combinations = [[1], [2], [3]]
|
41
|
+
|
42
|
+
indexes.expand_combinations_from(combinations).should == [[1, 2, 3]]
|
43
|
+
end
|
44
|
+
it 'can handle empty combinations' do
|
45
|
+
combinations = [[1,2,3], [:a, :b, :c], []]
|
46
|
+
|
47
|
+
indexes.expand_combinations_from(combinations).should == nil
|
48
|
+
end
|
49
|
+
it 'can handle empty combinations' do
|
50
|
+
combinations = [[], [:a, :b, :c], []]
|
51
|
+
|
52
|
+
indexes.expand_combinations_from(combinations).should == nil
|
53
|
+
end
|
54
|
+
it 'can handle totally empty combinations' do
|
55
|
+
combinations = [[], [], []]
|
56
|
+
|
57
|
+
indexes.expand_combinations_from(combinations).should == nil
|
58
|
+
end
|
59
|
+
it 'is fast in a complicated case' do
|
60
|
+
combinations = [[1,2,3], [:a, :b, :c], [:k, :l]]
|
61
|
+
|
62
|
+
performance_of { indexes.expand_combinations_from(combinations) }.should < 0.00055
|
63
|
+
end
|
64
|
+
it 'is fast in a simple case' do
|
65
|
+
combinations = [[1], [2], [3]]
|
66
|
+
|
67
|
+
performance_of { indexes.expand_combinations_from(combinations) }.should < 0.00055
|
68
|
+
end
|
69
|
+
it 'is very fast in a 1-empty case' do
|
70
|
+
combinations = [[], [2], [3]]
|
71
|
+
|
72
|
+
performance_of { indexes.expand_combinations_from(combinations) }.should < 0.00045
|
73
|
+
end
|
74
|
+
it 'is very fast in a all-empty case' do
|
75
|
+
combinations = [[], [], []]
|
76
|
+
|
77
|
+
performance_of { indexes.expand_combinations_from(combinations) }.should < 0.00045
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
data/spec/lib/query/live_spec.rb
CHANGED
@@ -9,16 +9,16 @@ describe Query::Live do
|
|
9
9
|
|
10
10
|
describe 'result_type' do
|
11
11
|
before(:each) do
|
12
|
-
@query =
|
12
|
+
@query = described_class.new @index
|
13
13
|
end
|
14
14
|
it "should return a specific type" do
|
15
|
-
@query.result_type.should == Results::Live
|
15
|
+
@query.result_type.should == Internals::Results::Live
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
describe "execute" do
|
20
20
|
before(:each) do
|
21
|
-
@query =
|
21
|
+
@query = described_class.new @index
|
22
22
|
end
|
23
23
|
it "should get allocations" do
|
24
24
|
@query.result_type.should_receive :from
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Query::Qualifiers do
|
3
|
+
describe Internals::Query::Qualifiers do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
described_class.instance << Internals::Query::Qualifier.new(:test1, ['t1', 'tt1', 'ttt1'])
|
7
|
+
described_class.instance << Internals::Query::Qualifier.new(:test2, [:t2, :tt2, :ttt2])
|
8
|
+
described_class.instance << Internals::Query::Qualifier.new(:test3, [:t3, :tt3, :ttt3])
|
9
|
+
described_class.instance.prepare
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.it_should_normalize(qualifier, expected)
|
13
13
|
it "should map #{qualifier} to #{expected}" do
|
14
|
-
|
14
|
+
described_class.instance.normalize(qualifier).should == expected
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe Query::Token do
|
4
|
+
describe Internals::Query::Token do
|
5
5
|
|
6
6
|
before(:all) do
|
7
|
-
Query::Qualifiers.instance << Query::Qualifier.new(:specific, [:sp, :spec])
|
8
|
-
Query::Qualifiers.instance.prepare
|
7
|
+
Internals::Query::Qualifiers.instance << Internals::Query::Qualifier.new(:specific, [:sp, :spec])
|
8
|
+
Internals::Query::Qualifiers.instance.prepare
|
9
9
|
end
|
10
10
|
|
11
11
|
describe 'next_similar_token' do
|
@@ -13,7 +13,7 @@ describe Query::Token do
|
|
13
13
|
@bundle = stub :bundle, :similar => [:array, :of, :similar]
|
14
14
|
@category = stub :category, :bundle_for => @bundle
|
15
15
|
|
16
|
-
@token =
|
16
|
+
@token = described_class.processed 'similar~'
|
17
17
|
end
|
18
18
|
it 'returns the right next tokens' do
|
19
19
|
next_token = @token.next_similar_token @category
|
@@ -36,7 +36,7 @@ describe Query::Token do
|
|
36
36
|
before(:each) do
|
37
37
|
@bundle.stub! :similar => [:array, :of, :similar]
|
38
38
|
|
39
|
-
@token =
|
39
|
+
@token = described_class.processed 'similar~'
|
40
40
|
end
|
41
41
|
it 'should have a certain original text' do
|
42
42
|
@token.next_similar @bundle
|
@@ -50,7 +50,7 @@ describe Query::Token do
|
|
50
50
|
before(:each) do
|
51
51
|
@bundle.stub! :similar => [:array, :of, :similar]
|
52
52
|
|
53
|
-
@token =
|
53
|
+
@token = described_class.processed 'similar~'
|
54
54
|
end
|
55
55
|
it 'generates all similar' do
|
56
56
|
@token.next_similar(@bundle).should == :array
|
@@ -73,7 +73,7 @@ describe Query::Token do
|
|
73
73
|
before(:each) do
|
74
74
|
@bundle.stub! :similar => [:array, :of, :similar]
|
75
75
|
|
76
|
-
@token =
|
76
|
+
@token = described_class.processed 'nonsimilar'
|
77
77
|
end
|
78
78
|
it 'generates all similar' do
|
79
79
|
@token.next_similar(@bundle).should == nil
|
@@ -93,7 +93,7 @@ describe Query::Token do
|
|
93
93
|
before(:each) do
|
94
94
|
@bundle = stub :bundle
|
95
95
|
|
96
|
-
@token =
|
96
|
+
@token = described_class.processed 'flarb~'
|
97
97
|
end
|
98
98
|
context "with similar" do
|
99
99
|
before(:each) do
|
@@ -116,7 +116,7 @@ describe Query::Token do
|
|
116
116
|
describe 'to_solr' do
|
117
117
|
def self.it_should_solr text, expected_result
|
118
118
|
it "should solrify into #{expected_result} from #{text}" do
|
119
|
-
|
119
|
+
described_class.processed(text).to_solr.should == expected_result
|
120
120
|
end
|
121
121
|
end
|
122
122
|
it_should_solr 's', 's'
|
@@ -144,7 +144,7 @@ describe Query::Token do
|
|
144
144
|
describe 'qualify' do
|
145
145
|
def self.it_should_qualify text, expected_result
|
146
146
|
it "should extract the qualifier #{expected_result} from #{text}" do
|
147
|
-
|
147
|
+
described_class.new(text).qualify.should == expected_result
|
148
148
|
end
|
149
149
|
end
|
150
150
|
it_should_qualify 'spec:qualifier', :specific
|
@@ -159,7 +159,7 @@ describe Query::Token do
|
|
159
159
|
describe 'processed' do
|
160
160
|
it 'should have an order' do
|
161
161
|
token = stub :token
|
162
|
-
|
162
|
+
described_class.should_receive(:new).once.and_return token
|
163
163
|
|
164
164
|
token.should_receive(:qualify).once.ordered
|
165
165
|
token.should_receive(:extract_original).once.ordered
|
@@ -167,17 +167,17 @@ describe Query::Token do
|
|
167
167
|
token.should_receive(:similarize).once.ordered
|
168
168
|
token.should_receive(:remove_illegals).once.ordered
|
169
169
|
|
170
|
-
|
170
|
+
described_class.processed :any_text
|
171
171
|
end
|
172
172
|
it 'should return a new token' do
|
173
|
-
|
173
|
+
described_class.processed('some text').should be_kind_of(described_class)
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
177
177
|
describe 'partial?' do
|
178
178
|
context 'similar, partial' do
|
179
179
|
before(:each) do
|
180
|
-
@token =
|
180
|
+
@token = described_class.processed 'similar~'
|
181
181
|
@token.partial = true
|
182
182
|
end
|
183
183
|
it 'should be false' do
|
@@ -186,7 +186,7 @@ describe Query::Token do
|
|
186
186
|
end
|
187
187
|
context 'similar, not partial' do
|
188
188
|
before(:each) do
|
189
|
-
@token =
|
189
|
+
@token = described_class.processed 'similar~'
|
190
190
|
end
|
191
191
|
it 'should be false' do
|
192
192
|
@token.partial?.should == false
|
@@ -194,7 +194,7 @@ describe Query::Token do
|
|
194
194
|
end
|
195
195
|
context 'not similar, partial' do
|
196
196
|
before(:each) do
|
197
|
-
@token =
|
197
|
+
@token = described_class.processed 'not similar'
|
198
198
|
@token.partial = true
|
199
199
|
end
|
200
200
|
it 'should be true' do
|
@@ -203,7 +203,7 @@ describe Query::Token do
|
|
203
203
|
end
|
204
204
|
context 'not similar, not partial' do
|
205
205
|
before(:each) do
|
206
|
-
@token =
|
206
|
+
@token = described_class.processed 'not similar'
|
207
207
|
end
|
208
208
|
it 'should be nil' do
|
209
209
|
@token.partial?.should == nil
|
@@ -213,12 +213,12 @@ describe Query::Token do
|
|
213
213
|
|
214
214
|
describe 'similar' do
|
215
215
|
it 'should not change the original with the text' do
|
216
|
-
token =
|
216
|
+
token = described_class.processed "bla~"
|
217
217
|
token.text.should_not == token.original
|
218
218
|
end
|
219
219
|
def self.it_should_have_similarity text, expected_similarity_value
|
220
220
|
it "should have #{ "no" unless expected_similarity_value } similarity for '#{text}'" do
|
221
|
-
|
221
|
+
described_class.processed(text).similar?.should == expected_similarity_value
|
222
222
|
end
|
223
223
|
end
|
224
224
|
it_should_have_similarity 'name:', nil
|
@@ -238,7 +238,7 @@ describe Query::Token do
|
|
238
238
|
|
239
239
|
describe 'special cases' do
|
240
240
|
it 'should be blank on ""' do
|
241
|
-
token =
|
241
|
+
token = described_class.processed '""'
|
242
242
|
|
243
243
|
token.should be_blank
|
244
244
|
end
|
@@ -247,7 +247,7 @@ describe Query::Token do
|
|
247
247
|
describe 'split' do
|
248
248
|
def self.it_should_split text, expected_qualifier
|
249
249
|
it "should extract #{expected_qualifier} from #{text}" do
|
250
|
-
|
250
|
+
described_class.new('any').send(:split, text).should == expected_qualifier
|
251
251
|
end
|
252
252
|
end
|
253
253
|
it_should_split '""', [nil, '""']
|
@@ -261,7 +261,7 @@ describe Query::Token do
|
|
261
261
|
|
262
262
|
describe "original" do
|
263
263
|
it "should keep the original text even when processed" do
|
264
|
-
token =
|
264
|
+
token = described_class.processed "I'm the original token text."
|
265
265
|
|
266
266
|
token.original.should == "I'm the original token text."
|
267
267
|
end
|
@@ -269,12 +269,12 @@ describe Query::Token do
|
|
269
269
|
|
270
270
|
describe "blank?" do
|
271
271
|
it "should be blank if the token text itself is blank" do
|
272
|
-
token =
|
272
|
+
token = described_class.processed ''
|
273
273
|
|
274
274
|
token.blank?.should be_true
|
275
275
|
end
|
276
276
|
it "should be non-blank if the token text itself is non-blank" do
|
277
|
-
token =
|
277
|
+
token = described_class.processed 'not empty'
|
278
278
|
|
279
279
|
token.blank?.should be_false
|
280
280
|
end
|
@@ -283,14 +283,14 @@ describe Query::Token do
|
|
283
283
|
describe "to_s" do
|
284
284
|
describe "with qualifier" do
|
285
285
|
it "should display qualifier and text combined with a ':'" do
|
286
|
-
token =
|
286
|
+
token = described_class.processed('sp:qualifier')
|
287
287
|
|
288
288
|
token.to_s.should == 'specific:qualifier'
|
289
289
|
end
|
290
290
|
end
|
291
291
|
describe "without qualifier" do
|
292
292
|
it "should display just the text" do
|
293
|
-
token =
|
293
|
+
token = described_class.processed('text')
|
294
294
|
|
295
295
|
token.to_s.should == 'text'
|
296
296
|
end
|
@@ -300,7 +300,7 @@ describe Query::Token do
|
|
300
300
|
describe 'user_defined_category_name' do
|
301
301
|
context 'with qualifier' do
|
302
302
|
before(:each) do
|
303
|
-
@token =
|
303
|
+
@token = described_class.processed('sp:qualifier')
|
304
304
|
end
|
305
305
|
it 'should return the qualifier' do
|
306
306
|
@token.user_defined_category_name.should == :specific
|
@@ -308,7 +308,7 @@ describe Query::Token do
|
|
308
308
|
end
|
309
309
|
context 'without qualifier' do
|
310
310
|
before(:each) do
|
311
|
-
@token =
|
311
|
+
@token = described_class.processed('noqualifier')
|
312
312
|
end
|
313
313
|
it 'should return nil' do
|
314
314
|
@token.user_defined_category_name.should == nil
|
@@ -319,7 +319,7 @@ describe Query::Token do
|
|
319
319
|
describe "split" do
|
320
320
|
def self.it_should_split text, expected_result
|
321
321
|
it "should split #{expected_result} from #{text}" do
|
322
|
-
|
322
|
+
described_class.new('any').send(:split, text).should == expected_result
|
323
323
|
end
|
324
324
|
end
|
325
325
|
it_should_split ':', [nil, '']
|
@@ -335,7 +335,7 @@ describe Query::Token do
|
|
335
335
|
describe 'partial=' do
|
336
336
|
context 'partial nil' do
|
337
337
|
before(:each) do
|
338
|
-
@token =
|
338
|
+
@token = described_class.new 'text'
|
339
339
|
end
|
340
340
|
it 'should set partial' do
|
341
341
|
@token.partial = true
|
@@ -350,7 +350,7 @@ describe Query::Token do
|
|
350
350
|
end
|
351
351
|
context 'partial not nil' do
|
352
352
|
before(:each) do
|
353
|
-
@token =
|
353
|
+
@token = described_class.processed 'text*'
|
354
354
|
end
|
355
355
|
it 'should not set partial' do
|
356
356
|
@token.partial = false
|
@@ -362,17 +362,17 @@ describe Query::Token do
|
|
362
362
|
|
363
363
|
describe 'partialize!' do
|
364
364
|
it 'should not partialize a token if the text ends with "' do
|
365
|
-
token =
|
365
|
+
token = described_class.processed 'text"'
|
366
366
|
|
367
367
|
token.instance_variable_get(:@partial).should be_false
|
368
368
|
end
|
369
369
|
it 'should partialize a token if the text ends with *' do
|
370
|
-
token =
|
370
|
+
token = described_class.processed 'text*'
|
371
371
|
|
372
372
|
token.instance_variable_get(:@partial).should be_true
|
373
373
|
end
|
374
374
|
it 'should not partialize a token if the text ends with ~' do
|
375
|
-
token =
|
375
|
+
token = described_class.processed 'text~'
|
376
376
|
|
377
377
|
token.instance_variable_get(:@partial).should be_nil
|
378
378
|
end
|
@@ -380,22 +380,22 @@ describe Query::Token do
|
|
380
380
|
|
381
381
|
describe "processed" do
|
382
382
|
it 'should remove *' do
|
383
|
-
token =
|
383
|
+
token = described_class.processed 'text*'
|
384
384
|
|
385
385
|
token.text.should == 'text'
|
386
386
|
end
|
387
387
|
it 'should remove ~' do
|
388
|
-
token =
|
388
|
+
token = described_class.processed 'text~'
|
389
389
|
|
390
390
|
token.text.should == 'text'
|
391
391
|
end
|
392
392
|
it 'should remove "' do
|
393
|
-
token =
|
393
|
+
token = described_class.processed 'text"'
|
394
394
|
|
395
395
|
token.text.should == 'text'
|
396
396
|
end
|
397
397
|
it "should pass on a processed text" do
|
398
|
-
|
398
|
+
described_class.processed('text').text.should == 'text'
|
399
399
|
end
|
400
400
|
end
|
401
401
|
|
@@ -1,21 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Query::Tokens do
|
3
|
+
describe Internals::Query::Tokens do
|
4
4
|
|
5
5
|
before(:all) do
|
6
|
-
Query::Qualifiers.instance << Query::Qualifier.new(:specific, [:sp, :spec])
|
7
|
-
Query::Qualifiers.instance.prepare
|
6
|
+
Internals::Query::Qualifiers.instance << Internals::Query::Qualifier.new(:specific, [:sp, :spec])
|
7
|
+
Internals::Query::Qualifiers.instance.prepare
|
8
8
|
end
|
9
9
|
|
10
10
|
describe 'to_solr_query' do
|
11
11
|
context 'many tokens' do
|
12
12
|
before(:each) do
|
13
|
-
@tokens =
|
14
|
-
Query::Token.processed('this~'),
|
15
|
-
Query::Token.processed('is'),
|
16
|
-
Query::Token.processed('a'),
|
17
|
-
Query::Token.processed('sp:solr'),
|
18
|
-
Query::Token.processed('query"')
|
13
|
+
@tokens = described_class.new [
|
14
|
+
Internals::Query::Token.processed('this~'),
|
15
|
+
Internals::Query::Token.processed('is'),
|
16
|
+
Internals::Query::Token.processed('a'),
|
17
|
+
Internals::Query::Token.processed('sp:solr'),
|
18
|
+
Internals::Query::Token.processed('query"')
|
19
19
|
]
|
20
20
|
end
|
21
21
|
it 'should output a correct solr query' do
|
@@ -28,7 +28,7 @@ describe Query::Tokens do
|
|
28
28
|
before(:each) do
|
29
29
|
@blank = stub :blank, :blank? => true
|
30
30
|
@nonblank = stub :nonblank, :blank? => false
|
31
|
-
@tokens =
|
31
|
+
@tokens = described_class.new [@blank, @nonblank, @blank, @blank, @nonblank]
|
32
32
|
end
|
33
33
|
it 'should not cut it down' do
|
34
34
|
@tokens.reject
|
@@ -40,8 +40,8 @@ describe Query::Tokens do
|
|
40
40
|
describe 'cap' do
|
41
41
|
context 'one token' do
|
42
42
|
before(:each) do
|
43
|
-
@token = Query::Token.processed 'Token'
|
44
|
-
@tokens =
|
43
|
+
@token = Internals::Query::Token.processed 'Token'
|
44
|
+
@tokens = described_class.new [@token]
|
45
45
|
end
|
46
46
|
it 'does not cut it down' do
|
47
47
|
@tokens.cap 5
|
@@ -56,15 +56,15 @@ describe Query::Tokens do
|
|
56
56
|
end
|
57
57
|
context 'many tokens' do
|
58
58
|
before(:each) do
|
59
|
-
@first = Query::Token.processed 'Hello'
|
60
|
-
@second = Query::Token.processed 'I'
|
61
|
-
@third = Query::Token.processed 'Am'
|
62
|
-
@tokens = Query::Tokens.new [
|
59
|
+
@first = Internals::Query::Token.processed 'Hello'
|
60
|
+
@second = Internals::Query::Token.processed 'I'
|
61
|
+
@third = Internals::Query::Token.processed 'Am'
|
62
|
+
@tokens = Internals::Query::Tokens.new [
|
63
63
|
@first,
|
64
64
|
@second,
|
65
65
|
@third,
|
66
|
-
Query::Token.processed('A'),
|
67
|
-
Query::Token.processed('Token')
|
66
|
+
Internals::Query::Token.processed('A'),
|
67
|
+
Internals::Query::Token.processed('Token')
|
68
68
|
]
|
69
69
|
end
|
70
70
|
it 'should cap the number of tokens' do
|
@@ -78,8 +78,8 @@ describe Query::Tokens do
|
|
78
78
|
describe 'partialize_last' do
|
79
79
|
context 'special case' do
|
80
80
|
before(:each) do
|
81
|
-
@token = Query::Token.processed 'a*'
|
82
|
-
@tokens =
|
81
|
+
@token = Internals::Query::Token.processed 'a*'
|
82
|
+
@tokens = described_class.new [@token]
|
83
83
|
end
|
84
84
|
it 'should have a last partialized token' do
|
85
85
|
@token.should be_partial
|
@@ -92,8 +92,8 @@ describe Query::Tokens do
|
|
92
92
|
end
|
93
93
|
context 'one token' do
|
94
94
|
before(:each) do
|
95
|
-
@token = Query::Token.processed 'Token'
|
96
|
-
@tokens =
|
95
|
+
@token = Internals::Query::Token.processed 'Token'
|
96
|
+
@tokens = described_class.new [@token]
|
97
97
|
end
|
98
98
|
it 'should not have a last partialized token' do
|
99
99
|
@token.should_not be_partial
|
@@ -106,13 +106,13 @@ describe Query::Tokens do
|
|
106
106
|
end
|
107
107
|
context 'many tokens' do
|
108
108
|
before(:each) do
|
109
|
-
@first
|
110
|
-
@last
|
111
|
-
@tokens =
|
109
|
+
@first = Internals::Query::Token.processed 'Hello'
|
110
|
+
@last = Internals::Query::Token.processed 'Token'
|
111
|
+
@tokens = described_class.new [
|
112
112
|
@first,
|
113
|
-
Query::Token.processed('I'),
|
114
|
-
Query::Token.processed('Am'),
|
115
|
-
Query::Token.processed('A'),
|
113
|
+
Internals::Query::Token.processed('I'),
|
114
|
+
Internals::Query::Token.processed('Am'),
|
115
|
+
Internals::Query::Token.processed('A'),
|
116
116
|
@last
|
117
117
|
]
|
118
118
|
end
|
@@ -134,12 +134,12 @@ describe Query::Tokens do
|
|
134
134
|
|
135
135
|
describe 'to_s' do
|
136
136
|
before(:each) do
|
137
|
-
@tokens =
|
138
|
-
Query::Token.processed('Hello~'),
|
139
|
-
Query::Token.processed('I~'),
|
140
|
-
Query::Token.processed('Am'),
|
141
|
-
Query::Token.processed('A*'),
|
142
|
-
Query::Token.processed('Token~')
|
137
|
+
@tokens = described_class.new [
|
138
|
+
Internals::Query::Token.processed('Hello~'),
|
139
|
+
Internals::Query::Token.processed('I~'),
|
140
|
+
Internals::Query::Token.processed('Am'),
|
141
|
+
Internals::Query::Token.processed('A*'),
|
142
|
+
Internals::Query::Token.processed('Token~')
|
143
143
|
]
|
144
144
|
end
|
145
145
|
it 'should work correctly' do
|
@@ -151,7 +151,7 @@ describe Query::Tokens do
|
|
151
151
|
describe name do
|
152
152
|
before(:each) do
|
153
153
|
@internal_tokens = mock :internal_tokens
|
154
|
-
@tokens =
|
154
|
+
@tokens = described_class.new @internal_tokens
|
155
155
|
end
|
156
156
|
it "should delegate #{name} to the internal tokens" do
|
157
157
|
proc_stub = lambda {}
|
data/spec/lib/sources/db_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe Sources::DB do
|
|
10
10
|
|
11
11
|
@select_statement = stub :statement
|
12
12
|
|
13
|
-
@source =
|
13
|
+
@source = described_class.new @select_statement, :option => :some_options
|
14
14
|
|
15
15
|
@source.stub! :database => @adapter
|
16
16
|
@source.stub! :connect_backend
|
@@ -21,27 +21,32 @@ describe Sources::DB do
|
|
21
21
|
@type = stub :type, :name => :some_type
|
22
22
|
@category = stub :category, :from => :some_category
|
23
23
|
end
|
24
|
-
context '
|
25
|
-
|
24
|
+
context 'mysql' do
|
25
|
+
before(:each) do
|
26
|
+
@connection.stub! :adapter_name => 'mysql'
|
27
|
+
end
|
28
|
+
context 'no data' do
|
29
|
+
it "delegates to the connection" do
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
+
@connection.should_receive(:execute).
|
32
|
+
once.
|
33
|
+
with('SELECT indexed_id, some_category FROM some_type_type_index st WHERE st.id > some_offset LIMIT 25000').
|
34
|
+
and_return []
|
31
35
|
|
32
|
-
|
36
|
+
@source.get_data @type, @category, :some_offset
|
37
|
+
end
|
33
38
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
and_return [[1, 'text']]
|
39
|
+
context 'with data' do
|
40
|
+
it 'yields to the caller' do
|
41
|
+
@connection.should_receive(:execute).
|
42
|
+
any_number_of_times.
|
43
|
+
with('SELECT indexed_id, some_category FROM some_type_type_index st WHERE st.id > some_offset LIMIT 25000').
|
44
|
+
and_return [[1, 'text']]
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
@source.get_data @type, @category, :some_offset do |id, text|
|
47
|
+
id.should == 1
|
48
|
+
text.should == 'text'
|
49
|
+
end
|
45
50
|
end
|
46
51
|
end
|
47
52
|
end
|