picky 3.4.3 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/aux/picky/cli.rb +1 -1
- data/lib/picky/backends/memory/json.rb +1 -1
- data/lib/picky/backends/memory/text.rb +2 -2
- data/lib/picky/backends/redis/string.rb +6 -0
- data/lib/picky/bundle.rb +0 -1
- data/lib/picky/bundle_indexing.rb +11 -107
- data/lib/picky/bundle_realtime.rb +16 -8
- data/lib/picky/calculations/location.rb +18 -14
- data/lib/picky/categories.rb +1 -1
- data/lib/picky/category.rb +7 -1
- data/lib/picky/category_indexed.rb +1 -0
- data/lib/picky/category_indexing.rb +17 -17
- data/lib/picky/category_realtime.rb +23 -11
- data/lib/picky/deployment.rb +33 -33
- data/lib/picky/generators/partial/substring.rb +0 -2
- data/lib/picky/generators/similarity/double_metaphone.rb +1 -1
- data/lib/picky/generators/similarity/metaphone.rb +1 -1
- data/lib/picky/generators/similarity/soundex.rb +1 -1
- data/lib/picky/index.rb +22 -5
- data/lib/picky/index_indexing.rb +3 -15
- data/lib/picky/indexers/base.rb +7 -3
- data/lib/picky/indexers/parallel.rb +1 -10
- data/lib/picky/indexers/serial.rb +1 -10
- data/lib/picky/indexes.rb +1 -1
- data/lib/picky/loader.rb +2 -6
- data/lib/picky/query/qualifier_category_mapper.rb +2 -2
- data/lib/picky/query/token.rb +1 -2
- data/lib/picky/query/tokens.rb +6 -0
- data/lib/picky/search.rb +1 -0
- data/lib/picky/sources/couch.rb +1 -1
- data/lib/picky/sources/csv.rb +1 -1
- data/lib/picky/sources/mongo.rb +1 -1
- data/lib/picky/wrappers/bundle/calculation.rb +8 -8
- data/lib/picky/wrappers/bundle/delegators.rb +4 -1
- data/lib/picky/wrappers/bundle/exact_partial.rb +1 -1
- data/lib/picky/wrappers/bundle/location.rb +30 -13
- data/lib/picky/wrappers/category/location.rb +14 -9
- data/lib/tasks/try.rb +2 -2
- data/spec/lib/backends/memory/text_spec.rb +6 -6
- data/spec/lib/bundle_spec.rb +4 -4
- data/spec/lib/calculations/location_spec.rb +27 -29
- data/spec/lib/category_indexed_spec.rb +1 -0
- data/spec/lib/category_indexing_spec.rb +23 -36
- data/spec/lib/category_spec.rb +2 -0
- data/spec/lib/extensions/string_spec.rb +1 -1
- data/spec/lib/generators/partial/infix_spec.rb +2 -2
- data/spec/lib/index_indexing_spec.rb +5 -3
- data/spec/lib/indexed/bundle_spec.rb +2 -2
- data/spec/lib/indexers/base_spec.rb +2 -4
- data/spec/lib/indexers/serial_spec.rb +3 -19
- data/spec/lib/indexing/bundle_partial_generation_speed_spec.rb +42 -42
- data/spec/lib/indexing/bundle_spec.rb +4 -133
- data/spec/lib/query/combination_spec.rb +6 -6
- data/spec/lib/query/token_spec.rb +32 -19
- data/spec/lib/query/tokens_spec.rb +23 -10
- metadata +27 -34
- data/lib/picky/no_source_specified_exception.rb +0 -7
- data/lib/picky/wrappers/sources/base.rb +0 -35
- data/lib/picky/wrappers/sources/location.rb +0 -56
- data/spec/lib/sources/wrappers/base_spec.rb +0 -38
- data/spec/lib/sources/wrappers/location_spec.rb +0 -55
@@ -6,23 +6,28 @@ module Picky
|
|
6
6
|
|
7
7
|
# THINK Is this the best way to do this?
|
8
8
|
#
|
9
|
-
def self.wrap category, grid, precision = 1
|
10
|
-
wrapped_exact = Wrappers::Bundle::Location.new category.exact, grid: grid, precision: precision
|
11
|
-
new_source = Wrappers::Sources::Location.new category.source, grid, precision
|
9
|
+
def self.wrap category, grid, precision = 1, anchor = 0.0
|
10
|
+
wrapped_exact = Wrappers::Bundle::Location.new category.exact, grid: grid, precision: precision, anchor: anchor
|
12
11
|
|
13
12
|
category.class_eval do
|
13
|
+
|
14
|
+
# Uses a basic tokenizer.
|
15
|
+
#
|
16
|
+
def tokenizer
|
17
|
+
@tokenizer ||= Tokenizer.new
|
18
|
+
end
|
19
|
+
|
20
|
+
# Both use the exact index.
|
21
|
+
#
|
22
|
+
# TODO Necessary to wrap?
|
23
|
+
#
|
14
24
|
define_method :exact do
|
15
25
|
wrapped_exact
|
16
26
|
end
|
17
27
|
define_method :partial do
|
18
28
|
wrapped_exact
|
19
29
|
end
|
20
|
-
|
21
|
-
@tokenizer ||= Tokenizer.new
|
22
|
-
end
|
23
|
-
define_method :source do
|
24
|
-
new_source
|
25
|
-
end
|
30
|
+
|
26
31
|
end
|
27
32
|
end
|
28
33
|
|
data/lib/tasks/try.rb
CHANGED
@@ -7,8 +7,8 @@ module Picky
|
|
7
7
|
def initialize text, index = nil, category = nil
|
8
8
|
@text = text
|
9
9
|
@specific = Picky::Indexes
|
10
|
-
@specific = @specific[index.
|
11
|
-
@specific = @specific[category.
|
10
|
+
@specific = @specific[index.intern] if index
|
11
|
+
@specific = @specific[category.intern] if category
|
12
12
|
end
|
13
13
|
|
14
14
|
def saved
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Picky::Backends::Memory::Text do
|
4
|
-
|
4
|
+
|
5
5
|
let(:text) { described_class.new "some_cache_path" }
|
6
|
-
|
6
|
+
|
7
7
|
describe 'extension' do
|
8
8
|
it 'is correct' do
|
9
9
|
text.extension.should == :txt
|
@@ -17,7 +17,7 @@ describe Picky::Backends::Memory::Text do
|
|
17
17
|
}.to raise_error("Can't have an initial content from text file. Use JSON or Marshal.")
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
describe "load" do
|
22
22
|
it "raises" do
|
23
23
|
lambda do
|
@@ -41,12 +41,12 @@ describe Picky::Backends::Memory::Text do
|
|
41
41
|
it "yields split lines and returns the id and token text" do
|
42
42
|
text.retrieve do |id, token|
|
43
43
|
id.should == '123456'
|
44
|
-
token.should ==
|
44
|
+
token.should == 'some_nice_token'
|
45
45
|
end
|
46
46
|
end
|
47
47
|
it "is fast" do
|
48
|
-
performance_of { text.retrieve { |id, token| } }.should < 0.
|
48
|
+
performance_of { text.retrieve { |id, token| } }.should < 0.00006
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
end
|
data/spec/lib/bundle_spec.rb
CHANGED
@@ -14,13 +14,13 @@ describe Picky::Bundle do
|
|
14
14
|
Picky::Generators::Partial::Default,
|
15
15
|
Picky::Generators::Similarity::DoubleMetaphone.new(3)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
describe 'identifier' do
|
19
19
|
it 'is correct' do
|
20
|
-
bundle.identifier.should == '
|
20
|
+
bundle.identifier.should == 'some_index:some_category:some_name'
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
describe 'index_path' do
|
25
25
|
it 'is correct' do
|
26
26
|
bundle.index_path(:some_type).should == 'spec/test_directory/index/test/some_index/some_category_some_name_some_type'
|
@@ -29,5 +29,5 @@ describe Picky::Bundle do
|
|
29
29
|
bundle.index_path.should == 'spec/test_directory/index/test/some_index/some_category_some_name'
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
end
|
@@ -1,58 +1,56 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Picky::Calculations::Location do
|
4
|
-
|
4
|
+
|
5
5
|
context 'with precision 1' do
|
6
6
|
before(:each) do
|
7
|
-
@calculation = described_class.new 1.5, 1
|
8
|
-
@calculation.minimum = 42.7
|
7
|
+
@calculation = described_class.new 1.5, 42.7, 1
|
9
8
|
end
|
10
|
-
describe '
|
9
|
+
describe 'calculated_range' do
|
11
10
|
it 'returns the right range' do
|
12
|
-
@calculation.
|
11
|
+
@calculation.calculated_range(40.0).should == (-2..0)
|
13
12
|
end
|
14
13
|
it 'returns the right range' do
|
15
|
-
@calculation.
|
14
|
+
@calculation.calculated_range(41.0).should == (-1..1)
|
16
15
|
end
|
17
16
|
it 'returns the right range' do
|
18
|
-
@calculation.
|
17
|
+
@calculation.calculated_range(0).should == (-42..-40)
|
19
18
|
end
|
20
19
|
end
|
21
|
-
describe '
|
22
|
-
it 'sets the
|
23
|
-
@calculation.
|
20
|
+
describe 'calculate' do
|
21
|
+
it 'sets the anchor close value to the minimum minus user grid' do
|
22
|
+
@calculation.calculate(41.2).should == 1
|
24
23
|
end
|
25
|
-
it 'sets the
|
26
|
-
@calculation.
|
24
|
+
it 'sets the anchor value to 1 plus precision' do
|
25
|
+
@calculation.calculate(42.7).should == 2
|
27
26
|
end
|
28
|
-
it 'sets the
|
29
|
-
@calculation.
|
27
|
+
it 'sets the anchor value plus 2/3 of the grid size to 2 plus 1 grid length' do
|
28
|
+
@calculation.calculate(43.7).should == 3
|
30
29
|
end
|
31
|
-
it 'sets the
|
32
|
-
@calculation.
|
30
|
+
it 'sets the anchor value plus 20/3 of the grid size to 2 plus 10 grid length' do
|
31
|
+
@calculation.calculate(52.7).should == 12
|
33
32
|
end
|
34
33
|
end
|
35
34
|
end
|
36
|
-
|
35
|
+
|
37
36
|
context 'with precision 3' do
|
38
37
|
before(:each) do
|
39
|
-
@calculation = described_class.new 1.5, 3
|
40
|
-
@calculation.minimum = 42.7
|
38
|
+
@calculation = described_class.new 1.5, 42.7, 3
|
41
39
|
end
|
42
|
-
describe '
|
43
|
-
it 'sets the
|
44
|
-
@calculation.
|
40
|
+
describe 'calculate' do
|
41
|
+
it 'sets the anchor close value to the minimum minus user grid' do
|
42
|
+
@calculation.calculate(41.2).should == 1
|
45
43
|
end
|
46
|
-
it 'sets the
|
47
|
-
@calculation.
|
44
|
+
it 'sets the anchor value to 1 plus precision' do
|
45
|
+
@calculation.calculate(42.7).should == 4
|
48
46
|
end
|
49
|
-
it 'sets the
|
50
|
-
@calculation.
|
47
|
+
it 'sets the anchor value plus 2/3 of the grid size plus 1 plus precision plus 1 grid length' do
|
48
|
+
@calculation.calculate(43.7).should == 6
|
51
49
|
end
|
52
|
-
it 'sets the
|
53
|
-
@calculation.
|
50
|
+
it 'sets the anchor value plus 20/3 of the grid size to 2 plus 10 grid length' do
|
51
|
+
@calculation.calculate(52.7).should == 27
|
54
52
|
end
|
55
53
|
end
|
56
54
|
end
|
57
|
-
|
55
|
+
|
58
56
|
end
|
@@ -62,50 +62,37 @@ describe Picky::Category do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
describe 'generate_caches_from_memory' do
|
66
|
-
it 'should delegate to partial' do
|
67
|
-
partial.should_receive(:generate_caches_from_memory).once.with
|
68
|
-
|
69
|
-
category.generate_caches_from_memory
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe 'generate_partial' do
|
74
|
-
it 'should return whatever the partial generation returns' do
|
75
|
-
exact.stub! :index
|
76
|
-
partial.stub! :generate_partial_from => :generation_returns
|
77
|
-
|
78
|
-
category.generate_partial
|
79
|
-
end
|
80
|
-
it 'should use the exact index to generate the partial index' do
|
81
|
-
exact_index = stub :exact_index
|
82
|
-
exact.stub! :inverted => exact_index
|
83
|
-
partial.should_receive(:generate_partial_from).once.with(exact_index)
|
84
|
-
|
85
|
-
category.generate_partial
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe 'generate_caches_from_source' do
|
90
|
-
it 'should delegate to exact' do
|
91
|
-
exact.should_receive(:generate_caches_from_source).once.with
|
92
|
-
|
93
|
-
category.generate_caches_from_source
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
65
|
describe 'cache' do
|
98
66
|
it 'should call multiple methods in order' do
|
99
|
-
category.should_receive(:
|
100
|
-
category.should_receive(:
|
101
|
-
category.should_receive(:generate_caches_from_memory).once.with().ordered
|
67
|
+
category.should_receive(:empty).once.with().ordered
|
68
|
+
category.should_receive(:retrieve).once.with().ordered
|
102
69
|
category.should_receive(:dump).once.with().ordered
|
103
|
-
category.should_receive(:timed_exclaim).once.ordered
|
104
70
|
|
105
71
|
category.cache
|
106
72
|
end
|
107
73
|
end
|
108
74
|
|
75
|
+
describe 'retrieve' do
|
76
|
+
it 'call the right thing' do
|
77
|
+
prepared = stub :prepared
|
78
|
+
prepared.should_receive(:retrieve).any_number_of_times
|
79
|
+
.and_yield(1, :some_token)
|
80
|
+
.and_yield(2, :some_token)
|
81
|
+
.and_yield(3, :some_token)
|
82
|
+
.and_yield(4, :some_token)
|
83
|
+
.and_yield(5, :some_token)
|
84
|
+
category.stub! :prepared => prepared
|
85
|
+
|
86
|
+
category.should_receive(:add_tokenized_token).once.with(1, :some_token, :<<)
|
87
|
+
category.should_receive(:add_tokenized_token).once.with(2, :some_token, :<<)
|
88
|
+
category.should_receive(:add_tokenized_token).once.with(3, :some_token, :<<)
|
89
|
+
category.should_receive(:add_tokenized_token).once.with(4, :some_token, :<<)
|
90
|
+
category.should_receive(:add_tokenized_token).once.with(5, :some_token, :<<)
|
91
|
+
|
92
|
+
category.retrieve
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
109
96
|
describe 'key_format' do
|
110
97
|
context 'source has key_format' do
|
111
98
|
before(:each) do
|
data/spec/lib/category_spec.rb
CHANGED
@@ -17,6 +17,8 @@ describe Picky::Category do
|
|
17
17
|
category.exact.similarity_strategy.should == Picky::Generators::Similarity::Default
|
18
18
|
|
19
19
|
category.partial.similarity_strategy.should be_kind_of(Picky::Generators::Similarity::None)
|
20
|
+
|
21
|
+
category.instance_variable_get(:@symbols).should == nil
|
20
22
|
end
|
21
23
|
|
22
24
|
end
|
@@ -7,7 +7,7 @@ describe String do
|
|
7
7
|
context 'performance' do
|
8
8
|
include Picky::Helpers::Measuring
|
9
9
|
before(:each) do
|
10
|
-
@token = (((0..9).to_a)*10).to_s
|
10
|
+
@token = (((0..9).to_a)*10).to_s
|
11
11
|
end
|
12
12
|
it "is fast" do
|
13
13
|
performance_of { @token.each_subtoken { |subtoken| } }.should < 0.00065
|
@@ -157,7 +157,7 @@ describe Picky::Generators::Partial::Infix do
|
|
157
157
|
end
|
158
158
|
end
|
159
159
|
it "should be fast" do
|
160
|
-
performance_of { @generator.generate_from(@index) }.should < 0.
|
160
|
+
performance_of { @generator.generate_from(@index) }.should < 0.07
|
161
161
|
end
|
162
162
|
end
|
163
163
|
describe "a bigger example with almost identical symbols" do
|
@@ -169,7 +169,7 @@ describe Picky::Generators::Partial::Infix do
|
|
169
169
|
end
|
170
170
|
end
|
171
171
|
it "should be fast" do
|
172
|
-
performance_of { @generator.generate_from(@index) }.should < 0.
|
172
|
+
performance_of { @generator.generate_from(@index) }.should < 0.07
|
173
173
|
end
|
174
174
|
end
|
175
175
|
end
|
@@ -97,9 +97,11 @@ describe Picky::Index do
|
|
97
97
|
@index.define_category :some_category_name1
|
98
98
|
@index.define_category :some_category_name2
|
99
99
|
end
|
100
|
-
describe "
|
101
|
-
it "should
|
102
|
-
|
100
|
+
describe "warn_no_source" do
|
101
|
+
it "should warn" do
|
102
|
+
@index.should_receive(:warn).once.with "No source given for index some_name."
|
103
|
+
|
104
|
+
@index.warn_no_source
|
103
105
|
end
|
104
106
|
end
|
105
107
|
describe 'define_source' do
|
@@ -14,7 +14,7 @@ describe Picky::Bundle do
|
|
14
14
|
|
15
15
|
describe 'to_s' do
|
16
16
|
it 'does something' do
|
17
|
-
@bundle.to_s.should == "Picky::Bundle(
|
17
|
+
@bundle.to_s.should == "Picky::Bundle(some_index:some_category:some_name)"
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -73,7 +73,7 @@ describe Picky::Bundle do
|
|
73
73
|
|
74
74
|
describe 'identifier' do
|
75
75
|
it 'should return a specific identifier' do
|
76
|
-
@bundle.identifier.should == '
|
76
|
+
@bundle.identifier.should == 'some_index:some_category:some_name'
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -20,10 +20,8 @@ describe Picky::Indexers::Base do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
describe 'index' do
|
23
|
-
it '
|
24
|
-
indexer.should_receive(:
|
25
|
-
indexer.should_receive(:process).once.with(:categories).ordered
|
26
|
-
indexer.should_receive(:finish_indexing_message).once.with.ordered
|
23
|
+
it 'processes' do
|
24
|
+
indexer.should_receive(:process).once.with :categories
|
27
25
|
|
28
26
|
indexer.index :categories
|
29
27
|
end
|
@@ -9,31 +9,15 @@ describe Picky::Indexers::Serial do
|
|
9
9
|
:identifier => :some_identifier,
|
10
10
|
:tokenizer => @tokenizer,
|
11
11
|
:source => @source
|
12
|
-
|
12
|
+
|
13
13
|
@indexer = described_class.new @category
|
14
14
|
@indexer.stub! :timed_exclaim
|
15
15
|
end
|
16
|
-
|
17
|
-
describe "start_indexing_message" do
|
18
|
-
it "informs the user about what it is going to index" do
|
19
|
-
@indexer.should_receive(:timed_exclaim).once.with '"some_identifier": Starting serial data preparation.'
|
20
|
-
|
21
|
-
@indexer.start_indexing_message
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "finish_indexing_message" do
|
26
|
-
it "informs the user about what it is going to index" do
|
27
|
-
@indexer.should_receive(:timed_exclaim).once.with '"some_identifier": Finished serial data preparation.'
|
28
|
-
|
29
|
-
@indexer.finish_indexing_message
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
16
|
+
|
33
17
|
describe "source" do
|
34
18
|
it "returns the one given to is" do
|
35
19
|
@indexer.source.should == @source
|
36
20
|
end
|
37
21
|
end
|
38
|
-
|
22
|
+
|
39
23
|
end
|
@@ -1,42 +1,42 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Picky::Bundle do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
1
|
+
# require 'spec_helper'
|
2
|
+
#
|
3
|
+
# describe Picky::Bundle do
|
4
|
+
#
|
5
|
+
# before(:each) do
|
6
|
+
# @index = Picky::Index.new :some_index
|
7
|
+
# @category = Picky::Category.new :some_category, @index
|
8
|
+
#
|
9
|
+
# @partial_strategy = Picky::Generators::Partial::Substring.new :from => 1
|
10
|
+
# @exact = described_class.new :some_name, @category, Picky::Backends::Memory.new, nil, @partial_strategy, nil
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# def generate_random_keys amount
|
14
|
+
# alphabet = ('a'..'z').to_a
|
15
|
+
# (1..amount).to_a.collect! do |n|
|
16
|
+
# Array.new(20).collect! { alphabet[rand(26)] }.join.to_sym
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
# def generate_random_ids amount
|
20
|
+
# (1..amount).to_a.collect! do |_|
|
21
|
+
# Array.new(rand(100)+5).collect! do |_|
|
22
|
+
# rand(5_000_000)
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# describe 'speed' do
|
28
|
+
# context 'medium arrays' do
|
29
|
+
# before(:each) do
|
30
|
+
# random_keys = generate_random_keys 300
|
31
|
+
# random_ids = generate_random_ids 300
|
32
|
+
# @exact.inverted = Hash[random_keys.zip(random_ids)]
|
33
|
+
# end
|
34
|
+
# it 'should be fast' do
|
35
|
+
# performance_of do
|
36
|
+
# @exact.generate_partial
|
37
|
+
# end.should < 0.1
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# end
|
@@ -11,7 +11,7 @@ describe Picky::Bundle do
|
|
11
11
|
|
12
12
|
describe 'identifier' do
|
13
13
|
it 'is correct' do
|
14
|
-
bundle.identifier.should == '
|
14
|
+
bundle.identifier.should == 'some_index:some_category:some_name'
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -37,13 +37,13 @@ describe Picky::Bundle do
|
|
37
37
|
it 'does something' do
|
38
38
|
expect {
|
39
39
|
bundle.raise_cache_missing :similarity
|
40
|
-
}.to raise_error("Error: The similarity cache for
|
40
|
+
}.to raise_error("Error: The similarity cache for some_index:some_category:some_name is missing.")
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
describe 'warn_cache_small' do
|
45
45
|
it 'warns the user' do
|
46
|
-
bundle.should_receive(:warn).once.with "Warning: similarity cache for
|
46
|
+
bundle.should_receive(:warn).once.with "Warning: similarity cache for some_index:some_category:some_name smaller than 16 bytes."
|
47
47
|
|
48
48
|
bundle.warn_cache_small :similarity
|
49
49
|
end
|
@@ -51,136 +51,7 @@ describe Picky::Bundle do
|
|
51
51
|
|
52
52
|
describe 'identifier' do
|
53
53
|
it 'should return a specific identifier' do
|
54
|
-
bundle.identifier.should == '
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe 'initialize_index_for' do
|
59
|
-
context 'token not yet assigned' do
|
60
|
-
before(:each) do
|
61
|
-
bundle.stub! :index => {}
|
62
|
-
end
|
63
|
-
it 'should assign it an empty array' do
|
64
|
-
bundle.initialize_inverted_index_for :some_token
|
65
|
-
|
66
|
-
bundle.inverted[:some_token].should == []
|
67
|
-
end
|
68
|
-
end
|
69
|
-
context 'token already assigned' do
|
70
|
-
before(:each) do
|
71
|
-
bundle.stub! :index => { :some_token => :already_assigned }
|
72
|
-
end
|
73
|
-
it 'should not assign it anymore' do
|
74
|
-
bundle.initialize_inverted_index_for :some_token
|
75
|
-
|
76
|
-
bundle.index[:some_token].should == :already_assigned
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe 'retrieve' do
|
82
|
-
before(:each) do
|
83
|
-
@ary = []
|
84
|
-
|
85
|
-
prepared = stub :prepared
|
86
|
-
prepared.should_receive(:retrieve).once.and_yield(' 1', :some_token)
|
87
|
-
.and_yield('1 ', :some_token)
|
88
|
-
.and_yield('1', :some_token)
|
89
|
-
.and_yield(' 2', :some_token)
|
90
|
-
.and_yield('3', :some_token)
|
91
|
-
.and_yield(' 3 ', :some_token)
|
92
|
-
.and_yield(' 1234', :some_token)
|
93
|
-
|
94
|
-
bundle.stub! :prepared => prepared
|
95
|
-
|
96
|
-
@inverted = stub :inverted, :[] => @ary
|
97
|
-
bundle.stub! :inverted => @inverted
|
98
|
-
end
|
99
|
-
context 'uniqueness' do
|
100
|
-
before(:each) do
|
101
|
-
@category.stub! :key_format => :to_i
|
102
|
-
@inverted = { :test => @ary }
|
103
|
-
end
|
104
|
-
it 'is correct' do
|
105
|
-
bundle.retrieve
|
106
|
-
|
107
|
-
bundle.inverted[:test].should == [1,2,3,1234]
|
108
|
-
end
|
109
|
-
end
|
110
|
-
context 'id key format' do
|
111
|
-
before(:each) do
|
112
|
-
@category.stub! :key_format => :to_i
|
113
|
-
end
|
114
|
-
it 'should call the other methods correctly' do
|
115
|
-
@ary.should_receive(:<<).once.ordered.with 1
|
116
|
-
@ary.should_receive(:<<).once.ordered.with 2
|
117
|
-
@ary.should_receive(:<<).once.ordered.with 3
|
118
|
-
@ary.should_receive(:<<).once.ordered.with 1234
|
119
|
-
|
120
|
-
bundle.retrieve
|
121
|
-
end
|
122
|
-
end
|
123
|
-
context 'other key format' do
|
124
|
-
before(:each) do
|
125
|
-
@category.stub! :key_format => :strip
|
126
|
-
end
|
127
|
-
it 'should call the other methods correctly' do
|
128
|
-
@ary.should_receive(:<<).once.ordered.with '1'
|
129
|
-
@ary.should_receive(:<<).once.ordered.with '2'
|
130
|
-
@ary.should_receive(:<<).once.ordered.with '3'
|
131
|
-
@ary.should_receive(:<<).once.ordered.with '1234'
|
132
|
-
|
133
|
-
bundle.retrieve
|
134
|
-
end
|
135
|
-
end
|
136
|
-
context 'no key format - default' do
|
137
|
-
before(:each) do
|
138
|
-
@category.stub! :key_format => nil
|
139
|
-
end
|
140
|
-
it 'should call the other methods correctly' do
|
141
|
-
@ary.should_receive(:<<).once.ordered.with 1
|
142
|
-
@ary.should_receive(:<<).once.ordered.with 2
|
143
|
-
@ary.should_receive(:<<).once.ordered.with 3
|
144
|
-
@ary.should_receive(:<<).once.ordered.with 1234
|
145
|
-
|
146
|
-
bundle.retrieve
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe 'load_from_index_file' do
|
152
|
-
it 'should call two methods in order' do
|
153
|
-
bundle.should_receive(:load_from_prepared_index_generation_message).once.ordered
|
154
|
-
bundle.should_receive(:retrieve).once.ordered
|
155
|
-
|
156
|
-
bundle.load_from_prepared_index_file
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe 'generate_derived' do
|
161
|
-
it 'should call two methods in order' do
|
162
|
-
bundle.should_receive(:generate_weights).once.ordered
|
163
|
-
bundle.should_receive(:generate_similarity).once.ordered
|
164
|
-
|
165
|
-
bundle.generate_derived
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
describe 'generate_caches_from_memory' do
|
170
|
-
it 'should call two methods in order' do
|
171
|
-
bundle.should_receive(:cache_from_memory_generation_message).once.ordered
|
172
|
-
bundle.should_receive(:generate_derived).once.ordered
|
173
|
-
|
174
|
-
bundle.generate_caches_from_memory
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
describe 'generate_caches_from_source' do
|
179
|
-
it 'should call two methods in order' do
|
180
|
-
bundle.should_receive(:load_from_prepared_index_file).once.ordered
|
181
|
-
bundle.should_receive(:generate_caches_from_memory).once.ordered
|
182
|
-
|
183
|
-
bundle.generate_caches_from_source
|
54
|
+
bundle.identifier.should == 'some_index:some_category:some_name'
|
184
55
|
end
|
185
56
|
end
|
186
57
|
|