picky 2.7.0 → 3.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/picky/adapters/rack/base.rb +20 -16
- data/lib/picky/adapters/rack/live_parameters.rb +28 -24
- data/lib/picky/adapters/rack/search.rb +67 -0
- data/lib/picky/adapters/rack.rb +27 -23
- data/lib/picky/application.rb +246 -236
- data/lib/picky/backend/base.rb +115 -119
- data/lib/picky/backend/file/basic.rb +102 -98
- data/lib/picky/backend/file/json.rb +27 -23
- data/lib/picky/backend/file/marshal.rb +32 -28
- data/lib/picky/backend/file/text.rb +45 -41
- data/lib/picky/backend/files.rb +19 -15
- data/lib/picky/backend/redis/basic.rb +76 -72
- data/lib/picky/backend/redis/list_hash.rb +40 -36
- data/lib/picky/backend/redis/string_hash.rb +30 -26
- data/lib/picky/backend/redis.rb +32 -28
- data/lib/picky/bundle.rb +82 -57
- data/lib/{bundling.rb → picky/bundling.rb} +0 -0
- data/lib/picky/calculations/location.rb +51 -47
- data/lib/picky/categories.rb +60 -56
- data/lib/picky/categories_indexed.rb +73 -82
- data/lib/picky/categories_indexing.rb +12 -8
- data/lib/picky/category.rb +109 -120
- data/lib/picky/category_indexed.rb +39 -41
- data/lib/picky/category_indexing.rb +123 -125
- data/lib/picky/character_substituters/west_european.rb +32 -26
- data/lib/{constants.rb → picky/constants.rb} +0 -0
- data/lib/picky/cores.rb +96 -92
- data/lib/{deployment.rb → picky/deployment.rb} +0 -0
- data/lib/picky/frontend_adapters/rack.rb +133 -118
- data/lib/picky/generators/aliases.rb +5 -3
- data/lib/picky/generators/base.rb +11 -7
- data/lib/picky/generators/partial/default.rb +7 -3
- data/lib/picky/generators/partial/none.rb +24 -20
- data/lib/picky/generators/partial/strategy.rb +20 -16
- data/lib/picky/generators/partial/substring.rb +94 -90
- data/lib/picky/generators/partial_generator.rb +11 -7
- data/lib/picky/generators/similarity/default.rb +9 -5
- data/lib/picky/generators/similarity/double_metaphone.rb +20 -16
- data/lib/picky/generators/similarity/metaphone.rb +20 -16
- data/lib/picky/generators/similarity/none.rb +23 -19
- data/lib/picky/generators/similarity/phonetic.rb +49 -45
- data/lib/picky/generators/similarity/soundex.rb +20 -16
- data/lib/picky/generators/similarity/strategy.rb +10 -6
- data/lib/picky/generators/similarity_generator.rb +11 -7
- data/lib/picky/generators/strategy.rb +14 -10
- data/lib/picky/generators/weights/default.rb +9 -5
- data/lib/picky/generators/weights/logarithmic.rb +30 -26
- data/lib/picky/generators/weights/strategy.rb +10 -6
- data/lib/picky/generators/weights_generator.rb +11 -7
- data/lib/picky/helpers/measuring.rb +20 -16
- data/lib/picky/indexed/bundle/base.rb +39 -37
- data/lib/picky/indexed/bundle/memory.rb +68 -64
- data/lib/picky/indexed/bundle/redis.rb +73 -69
- data/lib/picky/indexed/wrappers/bundle/calculation.rb +26 -22
- data/lib/picky/indexed/wrappers/bundle/location.rb +30 -26
- data/lib/picky/indexed/wrappers/bundle/wrapper.rb +36 -32
- data/lib/picky/indexed/wrappers/category/location.rb +17 -13
- data/lib/picky/indexed/wrappers/exact_first.rb +46 -42
- data/lib/picky/indexers/base.rb +26 -22
- data/lib/picky/indexers/parallel.rb +62 -58
- data/lib/picky/indexers/serial.rb +41 -37
- data/lib/picky/indexes/index.rb +400 -0
- data/lib/picky/indexes/index_indexed.rb +24 -0
- data/lib/picky/indexes/index_indexing.rb +138 -0
- data/lib/picky/indexes/memory.rb +20 -0
- data/lib/picky/indexes/redis.rb +20 -0
- data/lib/picky/indexes.rb +68 -61
- data/lib/picky/indexes_indexed.rb +16 -12
- data/lib/picky/indexes_indexing.rb +41 -37
- data/lib/picky/indexing/bundle/base.rb +216 -205
- data/lib/picky/indexing/bundle/memory.rb +16 -11
- data/lib/picky/indexing/bundle/redis.rb +14 -12
- data/lib/picky/indexing/wrappers/category/location.rb +17 -13
- data/lib/picky/interfaces/live_parameters.rb +159 -154
- data/lib/picky/loader.rb +267 -304
- data/lib/picky/loggers/search.rb +20 -13
- data/lib/picky/no_source_specified_exception.rb +7 -3
- data/lib/picky/performant.rb +6 -2
- data/lib/picky/query/allocation.rb +71 -67
- data/lib/picky/query/allocations.rb +99 -94
- data/lib/picky/query/combination.rb +70 -66
- data/lib/picky/query/combinations/base.rb +56 -52
- data/lib/picky/query/combinations/memory.rb +36 -32
- data/lib/picky/query/combinations/redis.rb +66 -62
- data/lib/picky/query/indexes.rb +175 -160
- data/lib/picky/query/qualifier_category_mapper.rb +43 -0
- data/lib/picky/query/token.rb +165 -172
- data/lib/picky/query/tokens.rb +86 -82
- data/lib/picky/query/weights.rb +44 -48
- data/lib/picky/query.rb +5 -1
- data/lib/picky/rack/harakiri.rb +51 -47
- data/lib/picky/results.rb +81 -77
- data/lib/picky/search.rb +169 -158
- data/lib/picky/sinatra.rb +34 -0
- data/lib/picky/sources/base.rb +73 -70
- data/lib/picky/sources/couch.rb +61 -57
- data/lib/picky/sources/csv.rb +68 -64
- data/lib/picky/sources/db.rb +139 -135
- data/lib/picky/sources/delicious.rb +52 -48
- data/lib/picky/sources/mongo.rb +68 -63
- data/lib/picky/sources/wrappers/base.rb +20 -16
- data/lib/picky/sources/wrappers/location.rb +37 -33
- data/lib/picky/statistics.rb +46 -43
- data/lib/picky/tasks.rb +3 -0
- data/lib/picky/tokenizers/base.rb +192 -187
- data/lib/picky/tokenizers/index.rb +25 -21
- data/lib/picky/tokenizers/location.rb +33 -29
- data/lib/picky/tokenizers/query.rb +49 -43
- data/lib/picky.rb +21 -13
- data/lib/tasks/application.rake +1 -1
- data/lib/tasks/index.rake +3 -3
- data/lib/tasks/routes.rake +1 -1
- data/lib/tasks/server.rake +1 -1
- data/spec/lib/adapters/rack/base_spec.rb +1 -1
- data/spec/lib/adapters/rack/live_parameters_spec.rb +1 -1
- data/spec/lib/adapters/rack/query_spec.rb +1 -1
- data/spec/lib/application_spec.rb +39 -32
- data/spec/lib/backend/file/basic_spec.rb +2 -2
- data/spec/lib/backend/file/json_spec.rb +2 -2
- data/spec/lib/backend/file/marshal_spec.rb +2 -2
- data/spec/lib/backend/file/text_spec.rb +1 -1
- data/spec/lib/backend/files_spec.rb +14 -24
- data/spec/lib/backend/redis/basic_spec.rb +2 -2
- data/spec/lib/backend/redis/list_hash_spec.rb +3 -3
- data/spec/lib/backend/redis/string_hash_spec.rb +3 -3
- data/spec/lib/backend/redis_spec.rb +20 -13
- data/spec/lib/calculations/location_spec.rb +1 -1
- data/spec/lib/categories_indexed_spec.rb +16 -34
- data/spec/lib/category_indexed_spec.rb +9 -27
- data/spec/lib/category_indexing_spec.rb +2 -3
- data/spec/lib/category_spec.rb +10 -10
- data/spec/lib/character_substituters/west_european_spec.rb +6 -5
- data/spec/lib/cores_spec.rb +17 -17
- data/spec/lib/extensions/symbol_spec.rb +15 -1
- data/spec/lib/frontend_adapters/rack_spec.rb +20 -20
- data/spec/lib/generators/aliases_spec.rb +3 -3
- data/spec/lib/generators/cacher_strategy_spec.rb +1 -1
- data/spec/lib/generators/partial/default_spec.rb +3 -3
- data/spec/lib/generators/partial/none_spec.rb +2 -2
- data/spec/lib/generators/partial/substring_spec.rb +1 -1
- data/spec/lib/generators/partial_generator_spec.rb +3 -3
- data/spec/lib/generators/similarity/double_metaphone_spec.rb +1 -1
- data/spec/lib/generators/similarity/metaphone_spec.rb +1 -1
- data/spec/lib/generators/similarity/none_spec.rb +1 -1
- data/spec/lib/generators/similarity/phonetic_spec.rb +1 -1
- data/spec/lib/generators/similarity/soundex_spec.rb +1 -1
- data/spec/lib/generators/similarity_generator_spec.rb +2 -2
- data/spec/lib/generators/weights/logarithmic_spec.rb +1 -1
- data/spec/lib/generators/weights_generator_spec.rb +1 -1
- data/spec/lib/helpers/measuring_spec.rb +2 -2
- data/spec/lib/indexed/bundle/memory_spec.rb +6 -6
- data/spec/lib/indexed/bundle/redis_spec.rb +4 -4
- data/spec/lib/indexed/wrappers/bundle/calculation_spec.rb +2 -3
- data/spec/lib/indexed/wrappers/bundle/wrapper_spec.rb +2 -2
- data/spec/lib/indexed/wrappers/exact_first_spec.rb +5 -5
- data/spec/lib/indexers/base_spec.rb +1 -1
- data/spec/lib/indexers/parallel_spec.rb +1 -1
- data/spec/lib/indexers/serial_spec.rb +1 -1
- data/spec/lib/{index/base_indexed_spec.rb → indexes/index_indexed_spec.rb} +3 -3
- data/spec/lib/{index/base_indexing_spec.rb → indexes/index_indexing_spec.rb} +19 -2
- data/spec/lib/{index/base_spec.rb → indexes/index_spec.rb} +6 -25
- data/spec/lib/{index → indexes}/redis_spec.rb +1 -1
- data/spec/lib/indexes_class_spec.rb +2 -2
- data/spec/lib/indexes_indexed_spec.rb +1 -1
- data/spec/lib/indexes_indexing_spec.rb +1 -1
- data/spec/lib/indexes_spec.rb +1 -1
- data/spec/lib/indexing/bundle/base_spec.rb +7 -5
- data/spec/lib/indexing/bundle/memory_partial_generation_speed_spec.rb +4 -4
- data/spec/lib/indexing/bundle/memory_spec.rb +15 -15
- data/spec/lib/indexing/bundle/redis_spec.rb +9 -9
- data/spec/lib/interfaces/live_parameters_spec.rb +5 -5
- data/spec/lib/loader_spec.rb +17 -19
- data/spec/lib/loggers/search_spec.rb +2 -2
- data/spec/lib/query/allocation_spec.rb +1 -1
- data/spec/lib/query/allocations_spec.rb +1 -1
- data/spec/lib/query/combination_spec.rb +4 -4
- data/spec/lib/query/combinations/base_spec.rb +1 -1
- data/spec/lib/query/combinations/memory_spec.rb +1 -1
- data/spec/lib/query/combinations/redis_spec.rb +1 -1
- data/spec/lib/query/indexes_spec.rb +7 -2
- data/spec/lib/query/qualifier_category_mapper_spec.rb +34 -0
- data/spec/lib/query/token_spec.rb +32 -53
- data/spec/lib/query/tokens_spec.rb +30 -35
- data/spec/lib/query/weights_spec.rb +16 -16
- data/spec/lib/rack/harakiri_spec.rb +5 -5
- data/spec/lib/results_spec.rb +1 -1
- data/spec/lib/search_spec.rb +24 -22
- data/spec/lib/sinatra_spec.rb +36 -0
- data/spec/lib/sources/base_spec.rb +1 -1
- data/spec/lib/sources/couch_spec.rb +9 -9
- data/spec/lib/sources/csv_spec.rb +7 -7
- data/spec/lib/sources/db_spec.rb +2 -2
- data/spec/lib/sources/delicious_spec.rb +5 -5
- data/spec/lib/sources/mongo_spec.rb +7 -7
- data/spec/lib/sources/wrappers/base_spec.rb +2 -2
- data/spec/lib/sources/wrappers/location_spec.rb +1 -1
- data/spec/lib/statistics_spec.rb +1 -1
- data/spec/lib/tokenizers/base_spec.rb +2 -2
- data/spec/lib/tokenizers/index_spec.rb +1 -1
- data/spec/lib/tokenizers/query_spec.rb +1 -1
- metadata +30 -30
- data/lib/picky/adapters/rack/query.rb +0 -65
- data/lib/picky/index/base.rb +0 -409
- data/lib/picky/index/base_indexed.rb +0 -29
- data/lib/picky/index/base_indexing.rb +0 -127
- data/lib/picky/index/memory.rb +0 -16
- data/lib/picky/index/redis.rb +0 -16
- data/lib/picky/query/qualifiers.rb +0 -76
- data/lib/picky/query/solr.rb +0 -60
- data/lib/picky/signals.rb +0 -8
- data/lib/picky-tasks.rb +0 -6
- data/lib/tasks/spec.rake +0 -11
- data/spec/lib/query/qualifiers_spec.rb +0 -31
@@ -1,20 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Query::Tokens do
|
4
|
-
|
5
|
-
before(:all) do
|
6
|
-
Query::Qualifiers.instance << Query::Qualifier.new(:specific, [:sp, :spec])
|
7
|
-
Query::Qualifiers.instance.prepare
|
8
|
-
end
|
3
|
+
describe Picky::Query::Tokens do
|
9
4
|
|
10
5
|
describe '.processed' do
|
11
6
|
it 'generates processed tokens from all words' do
|
12
7
|
expected = [
|
13
|
-
Query::Token.processed('this~'),
|
14
|
-
Query::Token.processed('is'),
|
15
|
-
Query::Token.processed('a'),
|
16
|
-
Query::Token.processed('sp:solr'),
|
17
|
-
Query::Token.processed('query"')
|
8
|
+
Picky::Query::Token.processed('this~'),
|
9
|
+
Picky::Query::Token.processed('is'),
|
10
|
+
Picky::Query::Token.processed('a'),
|
11
|
+
Picky::Query::Token.processed('sp:solr'),
|
12
|
+
Picky::Query::Token.processed('query"')
|
18
13
|
]
|
19
14
|
|
20
15
|
described_class.should_receive(:new).once.with expected
|
@@ -23,11 +18,11 @@ describe Query::Tokens do
|
|
23
18
|
end
|
24
19
|
it 'generates processed tokens from all words' do
|
25
20
|
expected = [
|
26
|
-
Query::Token.processed('this~', false),
|
27
|
-
Query::Token.processed('is', false),
|
28
|
-
Query::Token.processed('a', false),
|
29
|
-
Query::Token.processed('sp:solr', false),
|
30
|
-
Query::Token.processed('query"', false)
|
21
|
+
Picky::Query::Token.processed('this~', false),
|
22
|
+
Picky::Query::Token.processed('is', false),
|
23
|
+
Picky::Query::Token.processed('a', false),
|
24
|
+
Picky::Query::Token.processed('sp:solr', false),
|
25
|
+
Picky::Query::Token.processed('query"', false)
|
31
26
|
]
|
32
27
|
|
33
28
|
described_class.should_receive(:new).once.with expected
|
@@ -52,7 +47,7 @@ describe Query::Tokens do
|
|
52
47
|
describe 'cap' do
|
53
48
|
context 'one token' do
|
54
49
|
before(:each) do
|
55
|
-
@token = Query::Token.processed 'Token'
|
50
|
+
@token = Picky::Query::Token.processed 'Token'
|
56
51
|
@tokens = described_class.new [@token]
|
57
52
|
end
|
58
53
|
it 'does not cut it down' do
|
@@ -68,15 +63,15 @@ describe Query::Tokens do
|
|
68
63
|
end
|
69
64
|
context 'many tokens' do
|
70
65
|
before(:each) do
|
71
|
-
@first
|
72
|
-
@second = Query::Token.processed 'I'
|
73
|
-
@third
|
74
|
-
@tokens =
|
66
|
+
@first = Picky::Query::Token.processed 'Hello'
|
67
|
+
@second = Picky::Query::Token.processed 'I'
|
68
|
+
@third = Picky::Query::Token.processed 'Am'
|
69
|
+
@tokens = described_class.new [
|
75
70
|
@first,
|
76
71
|
@second,
|
77
72
|
@third,
|
78
|
-
Query::Token.processed('A'),
|
79
|
-
Query::Token.processed('Token')
|
73
|
+
Picky::Query::Token.processed('A'),
|
74
|
+
Picky::Query::Token.processed('Token')
|
80
75
|
]
|
81
76
|
end
|
82
77
|
it 'should cap the number of tokens' do
|
@@ -90,7 +85,7 @@ describe Query::Tokens do
|
|
90
85
|
describe 'partialize_last' do
|
91
86
|
context 'special case' do
|
92
87
|
before(:each) do
|
93
|
-
@token = Query::Token.processed 'a*'
|
88
|
+
@token = Picky::Query::Token.processed 'a*'
|
94
89
|
@tokens = described_class.new [@token]
|
95
90
|
end
|
96
91
|
it 'should have a last partialized token' do
|
@@ -104,7 +99,7 @@ describe Query::Tokens do
|
|
104
99
|
end
|
105
100
|
context 'one token' do
|
106
101
|
before(:each) do
|
107
|
-
@token = Query::Token.processed 'Token'
|
102
|
+
@token = Picky::Query::Token.processed 'Token'
|
108
103
|
@tokens = described_class.new [@token]
|
109
104
|
end
|
110
105
|
it 'should not have a last partialized token' do
|
@@ -118,13 +113,13 @@ describe Query::Tokens do
|
|
118
113
|
end
|
119
114
|
context 'many tokens' do
|
120
115
|
before(:each) do
|
121
|
-
@first = Query::Token.processed 'Hello'
|
122
|
-
@last = Query::Token.processed 'Token'
|
116
|
+
@first = Picky::Query::Token.processed 'Hello'
|
117
|
+
@last = Picky::Query::Token.processed 'Token'
|
123
118
|
@tokens = described_class.new [
|
124
119
|
@first,
|
125
|
-
Query::Token.processed('I'),
|
126
|
-
Query::Token.processed('Am'),
|
127
|
-
Query::Token.processed('A'),
|
120
|
+
Picky::Query::Token.processed('I'),
|
121
|
+
Picky::Query::Token.processed('Am'),
|
122
|
+
Picky::Query::Token.processed('A'),
|
128
123
|
@last
|
129
124
|
]
|
130
125
|
end
|
@@ -178,11 +173,11 @@ describe Query::Tokens do
|
|
178
173
|
describe 'to_s' do
|
179
174
|
before(:each) do
|
180
175
|
@tokens = described_class.new [
|
181
|
-
Query::Token.processed('Hello~'),
|
182
|
-
Query::Token.processed('I~'),
|
183
|
-
Query::Token.processed('Am'),
|
184
|
-
Query::Token.processed('A*'),
|
185
|
-
Query::Token.processed('Token~')
|
176
|
+
Picky::Query::Token.processed('Hello~'),
|
177
|
+
Picky::Query::Token.processed('I~'),
|
178
|
+
Picky::Query::Token.processed('Am'),
|
179
|
+
Picky::Query::Token.processed('A*'),
|
180
|
+
Picky::Query::Token.processed('Token~')
|
186
181
|
]
|
187
182
|
end
|
188
183
|
it 'should work correctly' do
|
@@ -1,22 +1,22 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Query::Weights do
|
3
|
+
describe Picky::Query::Weights do
|
4
4
|
|
5
5
|
context 'with weights' do
|
6
6
|
before(:each) do
|
7
|
-
@weights =
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
7
|
+
@weights = described_class.new [:test1, :test2] => 6,
|
8
|
+
[:test1] => 5,
|
9
|
+
[:test3] => 3,
|
10
|
+
[:test3, :test2] => 4,
|
11
|
+
[:test1, :test4] => 5,
|
12
|
+
[:test4, :test1] => 5,
|
13
|
+
[:test4, :test1, :test2] => 4,
|
14
|
+
[:test1, :test4, :test2] => 4,
|
15
|
+
[:test4, :test5] => 3,
|
16
|
+
[:test5, :test1] => 2,
|
17
|
+
[:test1, :test5] => 2,
|
18
|
+
[:test3, :test1] => 2,
|
19
|
+
[:test1, :test3] => 2
|
20
20
|
end
|
21
21
|
|
22
22
|
describe "weight_for" do
|
@@ -47,7 +47,7 @@ describe Query::Weights do
|
|
47
47
|
|
48
48
|
describe 'to_s' do
|
49
49
|
it 'is correct' do
|
50
|
-
@weights.to_s.should == "{[:test1, :test2]=>6, [:test1]=>5, [:test3]=>3, [:test3, :test2]=>4, [:test1, :test4]=>5, [:test4, :test1]=>5, [:test4, :test1, :test2]=>4, [:test1, :test4, :test2]=>4, [:test4, :test5]=>3, [:test5, :test1]=>2, [:test1, :test5]=>2, [:test3, :test1]=>2, [:test1, :test3]=>2}"
|
50
|
+
@weights.to_s.should == "Picky::Query::Weights({[:test1, :test2]=>6, [:test1]=>5, [:test3]=>3, [:test3, :test2]=>4, [:test1, :test4]=>5, [:test4, :test1]=>5, [:test4, :test1, :test2]=>4, [:test1, :test4, :test2]=>4, [:test4, :test5]=>3, [:test5, :test1]=>2, [:test1, :test5]=>2, [:test3, :test1]=>2, [:test1, :test3]=>2})"
|
51
51
|
end
|
52
52
|
end
|
53
53
|
describe 'empty?' do
|
@@ -58,7 +58,7 @@ describe Query::Weights do
|
|
58
58
|
end
|
59
59
|
context 'without weights' do
|
60
60
|
before(:each) do
|
61
|
-
@weights =
|
61
|
+
@weights = described_class.new
|
62
62
|
end
|
63
63
|
describe 'empty?' do
|
64
64
|
it 'is correct' do
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe Rack::Harakiri do
|
4
|
+
describe Picky::Rack::Harakiri do
|
5
5
|
before(:each) do
|
6
6
|
@app = stub :app
|
7
7
|
Process.stub! :kill # not taking any chances
|
8
8
|
end
|
9
9
|
context "defaults" do
|
10
10
|
before(:each) do
|
11
|
-
@ronin =
|
11
|
+
@ronin = described_class.new @app
|
12
12
|
end
|
13
13
|
it "should quit after a default amount of requests" do
|
14
14
|
@ronin.instance_variable_get(:@quit_after_requests).should == 50
|
@@ -56,11 +56,11 @@ describe Rack::Harakiri do
|
|
56
56
|
end
|
57
57
|
context "with harakiri set" do
|
58
58
|
before(:each) do
|
59
|
-
|
60
|
-
@ronin =
|
59
|
+
described_class.after = 100
|
60
|
+
@ronin = described_class.new @app
|
61
61
|
end
|
62
62
|
after(:each) do
|
63
|
-
|
63
|
+
described_class.after = nil
|
64
64
|
end
|
65
65
|
it "should quit after an amount of requests" do
|
66
66
|
@ronin.instance_variable_get(:@quit_after_requests).should == 100
|
data/spec/lib/results_spec.rb
CHANGED
data/spec/lib/search_spec.rb
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
#
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Search do
|
5
|
+
describe Picky::Search do
|
6
6
|
|
7
7
|
before(:each) do
|
8
8
|
@type = stub :type
|
9
|
-
@index = stub :some_index, :internal_indexed => @type
|
9
|
+
@index = stub :some_index, :internal_indexed => @type, :each_category => []
|
10
10
|
end
|
11
11
|
|
12
12
|
describe 'tokenized' do
|
@@ -29,7 +29,7 @@ describe Search do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
it 'works' do
|
32
|
-
search.weights.should == Query::Weights.new([:a, :b] => 3, [:c, :d] => -1)
|
32
|
+
search.weights.should == Picky::Query::Weights.new([:a, :b] => 3, [:c, :d] => -1)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -37,7 +37,7 @@ describe Search do
|
|
37
37
|
context 'no tokenizer predefined' do
|
38
38
|
let(:search) { described_class.new }
|
39
39
|
it 'returns the default tokenizer' do
|
40
|
-
search.tokenizer.should == Tokenizers::Query.default
|
40
|
+
search.tokenizer.should == Picky::Tokenizers::Query.default
|
41
41
|
end
|
42
42
|
end
|
43
43
|
context 'tokenizer predefined' do
|
@@ -62,18 +62,18 @@ describe Search do
|
|
62
62
|
let(:search) { described_class.new }
|
63
63
|
it 'returns a specific Combination for a specific input' do
|
64
64
|
some_source = stub(:source, :harvest => nil)
|
65
|
-
search.combinations_type_for([
|
65
|
+
search.combinations_type_for([Picky::Indexes::Memory.new(:gu, source: some_source)]).should == Picky::Query::Combinations::Memory
|
66
66
|
end
|
67
67
|
it 'just works on the same types' do
|
68
|
-
search.combinations_type_for([:blorf, :blarf]).should == Query::Combinations::Memory
|
68
|
+
search.combinations_type_for([:blorf, :blarf]).should == Picky::Query::Combinations::Memory
|
69
69
|
end
|
70
70
|
it 'just uses standard combinations' do
|
71
|
-
search.combinations_type_for([:blorf]).should == Query::Combinations::Memory
|
71
|
+
search.combinations_type_for([:blorf]).should == Picky::Query::Combinations::Memory
|
72
72
|
end
|
73
73
|
it 'raises on multiple types' do
|
74
74
|
expect do
|
75
75
|
search.combinations_type_for [:blorf, "blarf"]
|
76
|
-
end.to raise_error(Search::DifferentTypesError)
|
76
|
+
end.to raise_error(Picky::Search::DifferentTypesError)
|
77
77
|
end
|
78
78
|
it 'raises with the right message on multiple types' do
|
79
79
|
expect do
|
@@ -86,35 +86,37 @@ describe Search do
|
|
86
86
|
it "creates a default weight when no weights are given" do
|
87
87
|
search = described_class.new
|
88
88
|
|
89
|
-
search.weights.should be_kind_of(Query::Weights)
|
89
|
+
search.weights.should be_kind_of(Picky::Query::Weights)
|
90
90
|
end
|
91
91
|
it "handles :weights options when not yet wrapped" do
|
92
92
|
search = described_class.new :weights => { [:a, :b] => +3 }
|
93
93
|
|
94
|
-
search.weights.should be_kind_of(Query::Weights)
|
94
|
+
search.weights.should be_kind_of(Picky::Query::Weights)
|
95
95
|
end
|
96
96
|
it "handles :weights options when already wrapped" do
|
97
|
-
search = described_class.new :weights => Query::Weights.new([:a, :b] => +3)
|
97
|
+
search = described_class.new :weights => Picky::Query::Weights.new([:a, :b] => +3)
|
98
98
|
|
99
|
-
search.weights.should be_kind_of(Query::Weights)
|
99
|
+
search.weights.should be_kind_of(Picky::Query::Weights)
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
103
|
describe "search_with_text" do
|
104
104
|
before(:each) do
|
105
|
-
@search =
|
105
|
+
@search = described_class.new
|
106
106
|
end
|
107
107
|
it "delegates to search" do
|
108
108
|
@search.stub! :tokenized => :tokens
|
109
109
|
|
110
|
-
@search.should_receive(:search).once.with :tokens,
|
110
|
+
@search.should_receive(:search).once.with :tokens, 20, 0
|
111
111
|
|
112
|
-
@search.search_with_text :text,
|
112
|
+
@search.search_with_text :text, 20, 0
|
113
113
|
end
|
114
114
|
it "uses the tokenizer" do
|
115
|
+
@search.stub! :search
|
116
|
+
|
115
117
|
@search.should_receive(:tokenized).once.with :text
|
116
118
|
|
117
|
-
@search.search_with_text :text,
|
119
|
+
@search.search_with_text :text, 20 # (unimportant)
|
118
120
|
end
|
119
121
|
end
|
120
122
|
|
@@ -122,7 +124,7 @@ describe Search do
|
|
122
124
|
context 'with tokenizer' do
|
123
125
|
before(:each) do
|
124
126
|
@tokenizer = stub :tokenizer, :tokenize => :some_tokenized_text
|
125
|
-
@search =
|
127
|
+
@search = described_class.new @index, tokenizer: @tokenizer
|
126
128
|
end
|
127
129
|
it 'should tokenize using the tokenizer' do
|
128
130
|
@search.tokenized('some text').should == :some_tokenized_text
|
@@ -132,22 +134,22 @@ describe Search do
|
|
132
134
|
|
133
135
|
describe 'to_s' do
|
134
136
|
before(:each) do
|
135
|
-
@index.stub! :name => :some_index
|
137
|
+
@index.stub! :name => :some_index, :each_category => []
|
136
138
|
end
|
137
139
|
context 'with weights' do
|
138
140
|
before(:each) do
|
139
|
-
@search =
|
141
|
+
@search = described_class.new @index, weights: :some_weights
|
140
142
|
end
|
141
143
|
it 'works correctly' do
|
142
|
-
@search.to_s.should == 'Search(some_index, weights: some_weights)'
|
144
|
+
@search.to_s.should == 'Picky::Search(some_index, weights: some_weights)'
|
143
145
|
end
|
144
146
|
end
|
145
147
|
context 'without weights' do
|
146
148
|
before(:each) do
|
147
|
-
@search =
|
149
|
+
@search = described_class.new @index
|
148
150
|
end
|
149
151
|
it 'works correctly' do
|
150
|
-
@search.to_s.should == 'Search(some_index)'
|
152
|
+
@search.to_s.should == 'Picky::Search(some_index)'
|
151
153
|
end
|
152
154
|
end
|
153
155
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Picky::Sinatra do
|
4
|
+
|
5
|
+
let(:extendee) { Class.new {} }
|
6
|
+
|
7
|
+
it 'has no Picky specific methods' do
|
8
|
+
lambda { extendee.indexing }.should raise_error
|
9
|
+
end
|
10
|
+
it 'has no Picky specific methods' do
|
11
|
+
lambda { extendee.searching }.should raise_error
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'after extending' do
|
15
|
+
before(:each) do
|
16
|
+
extendee.extend Picky::Sinatra
|
17
|
+
end
|
18
|
+
it 'has Picky specific methods' do
|
19
|
+
extendee.send :indexing, some: 'option'
|
20
|
+
end
|
21
|
+
it 'has Picky specific methods' do
|
22
|
+
extendee.send :searching, some: 'option'
|
23
|
+
end
|
24
|
+
it 'gets delegated correctly' do
|
25
|
+
Picky::Application.should_receive(:indexing).once.with some: 'option'
|
26
|
+
|
27
|
+
extendee.send :indexing, some: 'option'
|
28
|
+
end
|
29
|
+
it 'gets delegated correctly' do
|
30
|
+
Picky::Application.should_receive(:searching).once.with some: 'option'
|
31
|
+
|
32
|
+
extendee.send :searching, some: 'option'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Sources::Couch do
|
3
|
+
describe Picky::Sources::Couch do
|
4
4
|
|
5
5
|
describe 'key_format' do
|
6
6
|
context 'default' do
|
7
|
-
let(:source) {
|
7
|
+
let(:source) { described_class.new(:a, :b, url: 'bla') }
|
8
8
|
it 'is correct' do
|
9
9
|
source.key_format.should == :to_sym
|
10
10
|
end
|
11
11
|
end
|
12
12
|
context 'non-default' do
|
13
|
-
let(:source) {
|
13
|
+
let(:source) { described_class.new(:a, :b, url: 'bla', key_format: 'some_key_method') }
|
14
14
|
it 'is correct' do
|
15
15
|
source.key_format.should == :some_key_method
|
16
16
|
end
|
@@ -18,9 +18,9 @@ describe Sources::Couch do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
describe 'to_s' do
|
21
|
-
let(:source) {
|
21
|
+
let(:source) { described_class.new(:a, :b, :url => 'bla') }
|
22
22
|
it 'is correct' do
|
23
|
-
source.to_s.should == 'Sources::Couch'
|
23
|
+
source.to_s.should == 'Picky::Sources::Couch'
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -28,7 +28,7 @@ describe Sources::Couch do
|
|
28
28
|
context 'uuid keys' do
|
29
29
|
context "with database" do
|
30
30
|
before(:each) do
|
31
|
-
@source =
|
31
|
+
@source = described_class.new :a, :b, :c, url: 'http://localhost:5984/picky'
|
32
32
|
RestClient::Request.should_receive(:execute).any_number_of_times.and_return %{{"rows":[{"doc":{"_id":"550e8400-e29b-41d4-a716-446655440000","a":"a data","b":"b data","c":"c data"}}]}}
|
33
33
|
end
|
34
34
|
|
@@ -54,7 +54,7 @@ describe Sources::Couch do
|
|
54
54
|
context 'integer keys' do
|
55
55
|
context "with database" do
|
56
56
|
before(:each) do
|
57
|
-
@source =
|
57
|
+
@source = described_class.new :a, :b, :c, url: 'http://localhost:5984/picky'
|
58
58
|
RestClient::Request.should_receive(:execute).any_number_of_times.and_return %{{"rows":[{"doc":{"_id":"123","a":"a data","b":"b data","c":"c data"}}]}}
|
59
59
|
end
|
60
60
|
|
@@ -82,13 +82,13 @@ describe Sources::Couch do
|
|
82
82
|
context 'default keys' do
|
83
83
|
context "without database" do
|
84
84
|
it "should fail correctly" do
|
85
|
-
lambda {
|
85
|
+
lambda { described_class.new(:a, :b, :c) }.should raise_error(described_class::NoDBGiven)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
context "with database" do
|
90
90
|
before(:each) do
|
91
|
-
@source =
|
91
|
+
@source = described_class.new :a, :b, :c, url: 'http://localhost:5984/picky'
|
92
92
|
RestClient::Request.should_receive(:execute).any_number_of_times.and_return %{{"rows":[{"doc":{"_id":"7f","a":"a data","b":"b data","c":"c data"}}]}}
|
93
93
|
end
|
94
94
|
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'csv'
|
3
3
|
|
4
|
-
describe Sources::CSV do
|
4
|
+
describe Picky::Sources::CSV do
|
5
5
|
|
6
6
|
describe 'to_s' do
|
7
7
|
let(:source) { described_class.new :a, :b, :c, file:'some/file.csv' }
|
8
8
|
it 'outputs the correct string' do
|
9
|
-
source.to_s.should == 'Sources::CSV(a, b, c, {:file=>"some/file.csv"})'
|
9
|
+
source.to_s.should == 'Picky::Sources::CSV(a, b, c, {:file=>"some/file.csv"})'
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
describe 'without separator' do
|
14
14
|
before(:each) do
|
15
|
-
@source =
|
15
|
+
@source = described_class.new :a, :b, :c, :file => :some_file
|
16
16
|
end
|
17
17
|
it 'calls foreach correctly' do
|
18
18
|
block = lambda { |*args| }
|
@@ -24,7 +24,7 @@ describe Sources::CSV do
|
|
24
24
|
end
|
25
25
|
describe 'with separator' do
|
26
26
|
before(:each) do
|
27
|
-
@source =
|
27
|
+
@source = described_class.new :a, :b, :c, :file => :some_file, :col_sep => 'some_separator'
|
28
28
|
end
|
29
29
|
it 'calls foreach correctly' do
|
30
30
|
block = lambda { |*args| }
|
@@ -37,7 +37,7 @@ describe Sources::CSV do
|
|
37
37
|
|
38
38
|
context "without file" do
|
39
39
|
it "should fail correctly" do
|
40
|
-
lambda { @source =
|
40
|
+
lambda { @source = described_class.new(:a, :b, :c) }.should raise_error(described_class::NoFileGiven)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
context "with file" do
|
@@ -46,7 +46,7 @@ describe Sources::CSV do
|
|
46
46
|
end
|
47
47
|
context 'without separator' do
|
48
48
|
before(:each) do
|
49
|
-
@source =
|
49
|
+
@source = described_class.new :a, :b, :c, :file => :some_file
|
50
50
|
end
|
51
51
|
describe "harvest" do
|
52
52
|
it "should yield the right data" do
|
@@ -66,7 +66,7 @@ describe Sources::CSV do
|
|
66
66
|
end
|
67
67
|
context 'with key_format method' do
|
68
68
|
before(:each) do
|
69
|
-
@source =
|
69
|
+
@source = described_class.new :a, :b, :c, :file => :some_file, :key_format => :strip
|
70
70
|
end
|
71
71
|
describe "harvest" do
|
72
72
|
it "should yield the right data" do
|
data/spec/lib/sources/db_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Sources::DB do
|
3
|
+
describe Picky::Sources::DB do
|
4
4
|
|
5
5
|
before(:each) do
|
6
6
|
@connection = stub :connection
|
@@ -16,7 +16,7 @@ describe Sources::DB do
|
|
16
16
|
|
17
17
|
describe 'to_s' do
|
18
18
|
it 'does something' do
|
19
|
-
@source.to_s.should == 'Sources::DB("some statement", {:option=>:some_options})'
|
19
|
+
@source.to_s.should == 'Picky::Sources::DB("some statement", {:option=>:some_options})'
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Sources::Delicious do
|
3
|
+
describe Picky::Sources::Delicious do
|
4
4
|
|
5
5
|
context "with file" do
|
6
6
|
|
7
7
|
describe 'to_s' do
|
8
8
|
it 'outputs correctly' do
|
9
|
-
described_class.new(:username, :password).to_s.should == 'Sources::Delicious(username)'
|
9
|
+
described_class.new(:username, :password).to_s.should == 'Picky::Sources::Delicious(username)'
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
describe "check_gem" do
|
14
14
|
before(:each) do
|
15
|
-
@source =
|
15
|
+
@source = described_class.allocate
|
16
16
|
end
|
17
17
|
context "doesn't find www/delicious" do
|
18
18
|
before(:each) do
|
@@ -37,7 +37,7 @@ describe Sources::Delicious do
|
|
37
37
|
|
38
38
|
describe "harvest" do
|
39
39
|
before(:each) do
|
40
|
-
@source =
|
40
|
+
@source = described_class.new(:username, :password)
|
41
41
|
|
42
42
|
post1 = WWW::Delicious::Post.new
|
43
43
|
post1.uid = "5045d67b3f251e4ae966dffe71501763"
|
@@ -70,7 +70,7 @@ describe Sources::Delicious do
|
|
70
70
|
end
|
71
71
|
describe "get_data" do
|
72
72
|
before(:each) do
|
73
|
-
@source =
|
73
|
+
@source = described_class.new(:username, :password)
|
74
74
|
|
75
75
|
post1 = WWW::Delicious::Post.new
|
76
76
|
post1.uid = "5045d67b3f251e4ae966dffe71501763"
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Sources::Mongo do
|
3
|
+
describe Picky::Sources::Mongo do
|
4
4
|
|
5
5
|
describe 'key_format' do
|
6
6
|
context 'default' do
|
7
|
-
let(:source) {
|
7
|
+
let(:source) { described_class.new(:a, :b, :url => 'someurl', :db => 'somedb') }
|
8
8
|
it 'is correct' do
|
9
9
|
source.key_format.should == :to_sym
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
context 'non-default' do
|
14
|
-
let(:source) {
|
14
|
+
let(:source) { described_class.new(:a, :b, :url => 'bla', :db => 'somedb', :key_format => 'some_key_method') }
|
15
15
|
it 'is correct' do
|
16
16
|
source.key_format.should == :some_key_method
|
17
17
|
end
|
@@ -19,21 +19,21 @@ describe Sources::Mongo do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
describe 'to_s' do
|
22
|
-
let(:source) {
|
22
|
+
let(:source) { described_class.new(:a, :b, :url => 'someurl', :db => 'somedb') }
|
23
23
|
it 'is correct' do
|
24
|
-
source.to_s.should == 'Sources::Mongo'
|
24
|
+
source.to_s.should == 'Picky::Sources::Mongo'
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
context "without database" do
|
29
29
|
it "should fail correctly" do
|
30
|
-
lambda { @source =
|
30
|
+
lambda { @source = described_class.new(:a, :b, :url => 'someurl') }.should raise_error(described_class::NoDBGiven)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
context "with database" do
|
35
35
|
before(:each) do
|
36
|
-
@source =
|
36
|
+
@source = described_class.new :a, :b, :url => 'someurl', :db => 'somedb'
|
37
37
|
RestClient::Request.should_receive(:execute).any_number_of_times.and_return %{{"rows":[{"_id":"7f","a":"a data","b":"b data","c":"c data"}]}}
|
38
38
|
end
|
39
39
|
|