picky 4.17.1 → 4.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/lib/picky/backends/backend.rb +9 -15
- data/lib/picky/backends/prepared/text.rb +1 -1
- data/lib/picky/backends/sqlite/basic.rb +3 -10
- data/lib/picky/bundle.rb +2 -2
- data/lib/picky/category.rb +10 -5
- data/lib/picky/category_indexed.rb +2 -1
- data/lib/picky/category_realtime.rb +10 -3
- data/lib/picky/helpers/measuring.rb +4 -6
- data/lib/picky/index_indexing.rb +0 -2
- data/lib/picky/indexes.rb +2 -2
- data/lib/picky/query/allocation.rb +3 -2
- data/lib/picky/query/allocations.rb +2 -2
- data/lib/picky/query/boosts.rb +2 -0
- data/lib/picky/query/combination.rb +1 -1
- data/lib/picky/query/combinations.rb +1 -3
- data/lib/picky/query/indexes.rb +1 -1
- data/lib/picky/query/token.rb +44 -23
- data/lib/picky/search.rb +2 -0
- data/lib/picky/search_facets.rb +3 -1
- data/lib/picky/tokenizer.rb +3 -3
- data/spec/functional/allocations_uniq_by_definition_spec.rb +19 -14
- data/spec/functional/arrays_as_ids_spec.rb +8 -17
- data/spec/functional/automatic_segmentation_spec.rb +40 -37
- data/spec/functional/custom_delimiters_spec.rb +30 -20
- data/spec/functional/no_tokenize_spec.rb +2 -2
- data/spec/functional/or_spec.rb +74 -75
- data/spec/functional/pool_spec.rb +54 -53
- data/spec/functional/realtime_spec.rb +1 -1
- data/spec/lib/backends/backend_spec.rb +9 -9
- data/spec/lib/backends/sqlite/array_spec.rb +2 -8
- data/spec/lib/backends/sqlite/value_spec.rb +2 -2
- data/spec/lib/category_indexed_spec.rb +0 -12
- data/spec/lib/query/allocation_spec.rb +3 -3
- data/spec/lib/query/combinations_spec.rb +0 -17
- data/spec/lib/query/token_spec.rb +9 -4
- data/spec/lib/tokenizer_spec.rb +3 -3
- metadata +20 -21
@@ -22,69 +22,72 @@ describe "automatic splitting" do
|
|
22
22
|
index
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
automatic_splitter
|
25
|
+
context 'splitting the text automatically' do
|
26
|
+
let(:automatic_splitter) { Picky::Splitters::Automatic.new index[:text] }
|
27
27
|
|
28
28
|
# It splits the text correctly.
|
29
29
|
#
|
30
|
-
automatic_splitter.split('purplerainbow').should == ['purple', 'rain', 'bow']
|
31
|
-
automatic_splitter.split('purplerain').should == ['purple', 'rain']
|
32
|
-
automatic_splitter.split('purple').should == ['purple']
|
30
|
+
it { automatic_splitter.split('purplerainbow').should == ['purple', 'rain', 'bow'] }
|
31
|
+
it { automatic_splitter.split('purplerain').should == ['purple', 'rain'] }
|
32
|
+
it { automatic_splitter.split('purple').should == ['purple'] }
|
33
33
|
|
34
34
|
# When it can't, it splits it using the partial index (correctly).
|
35
35
|
#
|
36
|
-
automatic_splitter.split('purplerainbo').should == ['purple', 'rain']
|
37
|
-
automatic_splitter.split('purplerainb').should == ['purple', 'rain']
|
36
|
+
it { automatic_splitter.split('purplerainbo').should == ['purple', 'rain'] }
|
37
|
+
it { automatic_splitter.split('purplerainb').should == ['purple', 'rain'] }
|
38
38
|
#
|
39
|
-
automatic_splitter.split('purplerai').should == ['purple']
|
40
|
-
automatic_splitter.split('purplera').should == ['purple']
|
41
|
-
automatic_splitter.split('purpler').should == ['purple']
|
39
|
+
it { automatic_splitter.split('purplerai').should == ['purple'] }
|
40
|
+
it { automatic_splitter.split('purplera').should == ['purple'] }
|
41
|
+
it { automatic_splitter.split('purpler').should == ['purple'] }
|
42
42
|
#
|
43
|
-
automatic_splitter.split('purpl').should == []
|
44
|
-
automatic_splitter.split('purp').should == []
|
45
|
-
automatic_splitter.split('pur').should == []
|
46
|
-
automatic_splitter.split('pu').should == []
|
47
|
-
automatic_splitter.split('p').should == []
|
43
|
+
it { automatic_splitter.split('purpl').should == [] }
|
44
|
+
it { automatic_splitter.split('purp').should == [] }
|
45
|
+
it { automatic_splitter.split('pur').should == [] }
|
46
|
+
it { automatic_splitter.split('pu').should == [] }
|
47
|
+
it { automatic_splitter.split('p').should == [] }
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
automatic_splitter
|
50
|
+
context 'splitting text automatically (with partial)' do
|
51
|
+
let(:automatic_splitter) { Picky::Splitters::Automatic.new index[:text], partial: true }
|
52
52
|
|
53
53
|
# It splits the text correctly.
|
54
54
|
#
|
55
|
-
automatic_splitter.split('purplerainbow').should == ['purple', 'rain', 'bow']
|
56
|
-
automatic_splitter.split('purplerain').should == ['purple', 'rain']
|
57
|
-
automatic_splitter.split('purple').should == ['purple']
|
55
|
+
it { automatic_splitter.split('purplerainbow').should == ['purple', 'rain', 'bow'] }
|
56
|
+
it { automatic_splitter.split('purplerain').should == ['purple', 'rain'] }
|
57
|
+
it { automatic_splitter.split('purple').should == ['purple'] }
|
58
58
|
|
59
59
|
# When it can't, it splits it using the partial index (correctly).
|
60
60
|
#
|
61
|
-
automatic_splitter.split('purplerainbo').should == ['purple', 'rain', 'bo']
|
62
|
-
automatic_splitter.split('purplerainb').should == ['purple', 'rain', 'b']
|
61
|
+
it { automatic_splitter.split('purplerainbo').should == ['purple', 'rain', 'bo'] }
|
62
|
+
it { automatic_splitter.split('purplerainb').should == ['purple', 'rain', 'b'] }
|
63
63
|
#
|
64
|
-
automatic_splitter.split('purplerai').should == ['purple', 'rai']
|
65
|
-
automatic_splitter.split('purplera').should == ['purple', 'ra']
|
66
|
-
automatic_splitter.split('purpler').should == ['purple'] # No 'r' in partial index.
|
64
|
+
it { automatic_splitter.split('purplerai').should == ['purple', 'rai'] }
|
65
|
+
it { automatic_splitter.split('purplera').should == ['purple', 'ra'] }
|
66
|
+
it { automatic_splitter.split('purpler').should == ['purple'] } # No 'r' in partial index.
|
67
67
|
#
|
68
|
-
automatic_splitter.split('purpl').should == ['purpl']
|
69
|
-
automatic_splitter.split('purp').should == ['purp']
|
70
|
-
automatic_splitter.split('pur').should == [] # No 'pur' in partial index etc.
|
71
|
-
automatic_splitter.split('pu').should == []
|
72
|
-
automatic_splitter.split('p').should == []
|
68
|
+
it { automatic_splitter.split('purpl').should == ['purpl'] }
|
69
|
+
it { automatic_splitter.split('purp').should == ['purp'] }
|
70
|
+
it { automatic_splitter.split('pur').should == [] } # No 'pur' in partial index etc.
|
71
|
+
it { automatic_splitter.split('pu').should == [] }
|
72
|
+
it { automatic_splitter.split('p').should == [] }
|
73
73
|
|
74
|
-
try
|
75
|
-
|
74
|
+
let(:try) do
|
75
|
+
splitter = automatic_splitter
|
76
|
+
Picky::Search.new index do
|
77
|
+
searching splits_text_on: splitter
|
78
|
+
end
|
76
79
|
end
|
77
80
|
|
78
81
|
# Should find the one with all parts.
|
79
82
|
#
|
80
|
-
try.search('purplerainbow').ids.should == [1]
|
81
|
-
try.search('sunandrain').ids.should == [5]
|
83
|
+
it { try.search('purplerainbow').ids.should == [1] }
|
84
|
+
it { try.search('sunandrain').ids.should == [5] }
|
82
85
|
|
83
86
|
# Common parts are found in multiple examples.
|
84
87
|
#
|
85
|
-
try.search('colorpurple').ids.should == [4,1]
|
86
|
-
try.search('bownew').ids.should == [3,1]
|
87
|
-
try.search('spainisking').ids.should == [6,1]
|
88
|
+
it { try.search('colorpurple').ids.should == [4,1] }
|
89
|
+
it { try.search('bownew').ids.should == [3,1] }
|
90
|
+
it { try.search('spainisking').ids.should == [6,1] }
|
88
91
|
end
|
89
92
|
|
90
93
|
it 'is fast enough' do
|
@@ -14,26 +14,34 @@ describe 'custom delimiters' do
|
|
14
14
|
Picky::Query::Token.qualifiers_delimiter = ','
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
index
|
19
|
-
|
20
|
-
|
17
|
+
context 'offers custom partial delimiters to be set' do
|
18
|
+
let(:index) do
|
19
|
+
index = Picky::Index.new :custom_delimiters do
|
20
|
+
category :text1
|
21
|
+
category :text2
|
22
|
+
end
|
23
|
+
|
24
|
+
index.add Struct.new(:id, :text1, :text2).new(1, 'hello', 'world')
|
25
|
+
|
26
|
+
index
|
21
27
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
try.search("
|
27
|
-
try.search("hell* world").ids.should == [1]
|
28
|
-
try.search("hello world").ids.should == [1]
|
28
|
+
let(:try) { Picky::Search.new index }
|
29
|
+
|
30
|
+
it { try.search("hell world").ids.should == [] }
|
31
|
+
it { try.search("hell* world").ids.should == [1] }
|
32
|
+
it { try.search("hello world").ids.should == [1] }
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
it 'with changed partial character' do
|
35
|
+
try.search("hell! world").ids.should == []
|
36
|
+
Picky::Query::Token.partial_character = '!'
|
37
|
+
try.search("hell! world").ids.should == [1]
|
38
|
+
end
|
33
39
|
|
34
|
-
|
35
|
-
|
36
|
-
|
40
|
+
it 'with changed no-partial character' do
|
41
|
+
try.search('hell!" world').ids.should == []
|
42
|
+
Picky::Query::Token.no_partial_character = '\?'
|
43
|
+
try.search('hell!? world').ids.should == []
|
44
|
+
end
|
37
45
|
end
|
38
46
|
|
39
47
|
it 'offers custom similar delimiters to be set' do
|
@@ -52,13 +60,15 @@ describe 'custom delimiters' do
|
|
52
60
|
try.search("hell? world").ids.should == []
|
53
61
|
Picky::Query::Token.similar_character = '\?'
|
54
62
|
try.search("hell? world").ids.should == [1]
|
63
|
+
Picky::Query::Token.no_similar_character = '!'
|
64
|
+
try.search("hello?! world!").ids.should == [1]
|
55
65
|
|
56
66
|
try.search('hell?" world').ids.should == []
|
57
|
-
Picky::Query::Token.no_partial_character = '
|
58
|
-
try.search('
|
67
|
+
Picky::Query::Token.no_partial_character = '\#'
|
68
|
+
try.search('hello?# world#').ids.should == [1]
|
59
69
|
end
|
60
70
|
|
61
|
-
it 'offers custom
|
71
|
+
it 'offers custom qualifiers delimiters to be set' do
|
62
72
|
index = Picky::Index.new :custom_delimiters do
|
63
73
|
category :text1, similarity: Picky::Similarity::Soundex.new
|
64
74
|
category :text2
|
@@ -41,7 +41,7 @@ describe 'Category#tokenize(false)' do
|
|
41
41
|
index.add thing.new(1, ['already', 'tokenized'])
|
42
42
|
expect do
|
43
43
|
index.add thing.new(2, 'this should fail')
|
44
|
-
end.to raise_error('You probably set tokenize: false on category "text". It will need an Enumerator of previously tokenized tokens.
|
44
|
+
end.to raise_error(%Q{undefined method `each' for "this should fail":String. You probably set tokenize: false on category "text". It will need an Enumerator of previously tokenized tokens.})
|
45
45
|
|
46
46
|
try = Picky::Search.new index
|
47
47
|
|
@@ -56,7 +56,7 @@ describe 'Category#tokenize(false)' do
|
|
56
56
|
index.add thing.new(1, ['already', 'tokenized'])
|
57
57
|
expect do
|
58
58
|
index.add thing.new(2, 'this should fail')
|
59
|
-
end.to raise_error('You probably set tokenize: false on category "text". It will need an Enumerator of previously tokenized tokens.
|
59
|
+
end.to raise_error(%Q{undefined method `each' for "this should fail":String. You probably set tokenize: false on category "text". It will need an Enumerator of previously tokenized tokens.})
|
60
60
|
|
61
61
|
try = Picky::Search.new index
|
62
62
|
|
data/spec/functional/or_spec.rb
CHANGED
@@ -4,101 +4,100 @@ require 'spec_helper'
|
|
4
4
|
require 'ostruct'
|
5
5
|
|
6
6
|
describe "OR token" do
|
7
|
+
|
8
|
+
# We use the same search throughout.
|
9
|
+
#
|
10
|
+
let(:try) { Picky::Search.new index }
|
11
|
+
|
12
|
+
context 'simple cases' do
|
13
|
+
let(:index) do
|
14
|
+
index = Picky::Index.new :or do
|
15
|
+
category :text
|
16
|
+
end
|
17
|
+
thing = OpenStruct.new id: 1, text: "hello ohai"
|
18
|
+
other = OpenStruct.new id: 2, text: "hello kthxbye"
|
7
19
|
|
8
|
-
|
9
|
-
|
10
|
-
|
20
|
+
index.add thing
|
21
|
+
index.add other
|
22
|
+
|
23
|
+
index
|
11
24
|
end
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
index.add other
|
18
|
-
|
19
|
-
try = Picky::Search.new index
|
20
|
-
|
21
|
-
# With or, or |.
|
22
|
-
#
|
23
|
-
try.search("hello text:ohai|text:kthxbye").ids.should == [1, 2]
|
24
|
-
try.search("hello text:ohai|kthxbye").ids.should == [1, 2]
|
25
|
-
try.search("hello ohai|text:kthxbye").ids.should == [1, 2]
|
26
|
-
try.search("hello ohai|kthxbye").ids.should == [1, 2]
|
27
|
-
|
28
|
-
# Still works.
|
29
|
-
#
|
30
|
-
try.search("hello text:ohai").ids.should == [1]
|
25
|
+
it { try.search("hello text:ohai|text:kthxbye").ids.should == [1, 2] }
|
26
|
+
it { try.search("hello text:ohai|kthxbye").ids.should == [1, 2] }
|
27
|
+
it { try.search("hello ohai|text:kthxbye").ids.should == [1, 2] }
|
28
|
+
it { try.search("hello ohai|kthxbye").ids.should == [1, 2] }
|
29
|
+
it('still works') { try.search("hello text:ohai").ids.should == [1] }
|
31
30
|
end
|
32
31
|
|
33
|
-
|
34
|
-
index
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
context 'more complex cases' do
|
33
|
+
let(:index) do
|
34
|
+
index = Picky::Index.new :or do
|
35
|
+
category :text1
|
36
|
+
category :text2
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
39
|
+
thing = OpenStruct.new id: 1, text1: "hello world", text2: "ohai kthxbye"
|
40
|
+
other = OpenStruct.new id: 2, text1: "hello something else", text2: "to be or not to be"
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
index.add thing
|
43
|
+
index.add other
|
44
|
+
|
45
|
+
index
|
46
|
+
end
|
46
47
|
|
47
|
-
# With or, or |.
|
48
|
-
#
|
49
48
|
# Note that the order is changed.
|
50
49
|
#
|
51
|
-
try.search("hello ohai|not").ids.should == [1, 2]
|
52
|
-
try.search("hello not|ohai").ids.should == [2, 1]
|
53
|
-
try.search("hello ohai|kthxbye").ids.should == [1]
|
54
|
-
try.search("hello nonexisting|not").ids.should == [2]
|
55
|
-
try.search("hello nonexisting|alsononexisting").ids.should == []
|
56
|
-
try.search("hello text1:world|text2:not|text2:kthxbye").ids.should == [1, 2]
|
50
|
+
it { try.search("hello ohai|not").ids.should == [1, 2] }
|
51
|
+
it { try.search("hello not|ohai").ids.should == [2, 1] }
|
52
|
+
it { try.search("hello ohai|kthxbye").ids.should == [1] }
|
53
|
+
it { try.search("hello nonexisting|not").ids.should == [2] }
|
54
|
+
it { try.search("hello nonexisting|alsononexisting").ids.should == [] }
|
55
|
+
it { try.search("hello text1:world|text2:not|text2:kthxbye").ids.should == [1, 2] }
|
57
56
|
end
|
58
57
|
|
59
|
-
|
60
|
-
index
|
61
|
-
|
62
|
-
|
58
|
+
context 'even more complex cases' do
|
59
|
+
let(:index) do
|
60
|
+
index = Picky::Index.new :or do
|
61
|
+
category :text, similarity: Picky::Similarity::DoubleMetaphone.new(3)
|
62
|
+
end
|
63
63
|
|
64
|
-
|
65
|
-
|
64
|
+
thing = OpenStruct.new id: 1, text: "hello ohai tester 13"
|
65
|
+
other = OpenStruct.new id: 2, text: "hello kthxbye"
|
66
66
|
|
67
|
-
|
68
|
-
|
67
|
+
index.add thing
|
68
|
+
index.add other
|
69
69
|
|
70
|
-
|
70
|
+
index
|
71
|
+
end
|
71
72
|
|
72
|
-
|
73
|
-
|
74
|
-
try.search("
|
75
|
-
try.search("text:
|
76
|
-
try.search("text:
|
77
|
-
try.search("
|
78
|
-
try.search("hello text
|
79
|
-
try.search("hello something,other:ohai|kthxbye").ids.should == [2]
|
80
|
-
try.search("hello text:oh*|text:kthxbya~").ids.should == [1, 2]
|
73
|
+
it { try.search("something,other:ohai").ids.should == [] }
|
74
|
+
it { try.search("text:taster~|text:kthxbye hello").ids.should == [2, 1] }
|
75
|
+
it { try.search("text:test*|kthxbye hello").ids.should == [2, 1] }
|
76
|
+
it { try.search("text:11-15|kthxbye hello").ids.should == [2, 1] }
|
77
|
+
it { try.search("hello text,other:ohai|text:kthxbye").ids.should == [1, 2] }
|
78
|
+
it { try.search("hello something,other:ohai|kthxbye").ids.should == [2] }
|
79
|
+
it { try.search("hello text:oh*|text:kthxbya~").ids.should == [1, 2] }
|
81
80
|
end
|
82
81
|
|
83
|
-
|
84
|
-
index
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
thing = OpenStruct.new id: 1, text: "that thing"
|
89
|
-
something = OpenStruct.new id: 2, text: "and something"
|
90
|
-
other = OpenStruct.new id: 3, text: "or other"
|
82
|
+
context 'multi-ORs' do
|
83
|
+
let(:index) do
|
84
|
+
index = Picky::Index.new :or do
|
85
|
+
category :text, similarity: Picky::Similarity::DoubleMetaphone.new(3)
|
86
|
+
end
|
91
87
|
|
92
|
-
|
93
|
-
|
94
|
-
|
88
|
+
thing = OpenStruct.new id: 1, text: "that thing"
|
89
|
+
something = OpenStruct.new id: 2, text: "and something"
|
90
|
+
other = OpenStruct.new id: 3, text: "or other"
|
95
91
|
|
96
|
-
|
92
|
+
index.add thing
|
93
|
+
index.add something
|
94
|
+
index.add other
|
95
|
+
|
96
|
+
index
|
97
|
+
end
|
97
98
|
|
98
|
-
|
99
|
-
|
100
|
-
try.search("thing|something|other").ids.should == [1, 2, 3]
|
101
|
-
try.search("something|other").ids.should == [2, 3]
|
99
|
+
it { try.search("thing|something|other").ids.should == [1, 2, 3] }
|
100
|
+
it { try.search("something|other").ids.should == [2, 3] }
|
102
101
|
end
|
103
102
|
|
104
103
|
end
|
@@ -30,58 +30,59 @@ describe 'GC stats: searching' do
|
|
30
30
|
|
31
31
|
# TODO Why are both versions almost equally fast?
|
32
32
|
#
|
33
|
-
context 'without pool' do
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
end
|
33
|
+
# context 'without pool' do
|
34
|
+
# it 'runs the GC more' do
|
35
|
+
# # Quickly check if the pool is removed.
|
36
|
+
# #
|
37
|
+
# fail 'object pool still installed' if Picky::Query::Token.respond_to? :release_all
|
38
|
+
#
|
39
|
+
# try = search
|
40
|
+
# query = 'abracadabra mirgel'
|
41
|
+
# gc_runs_of do
|
42
|
+
# amount.times { try.search query }
|
43
|
+
# end.should >= 10
|
44
|
+
# end
|
45
|
+
# it 'is less (?) performant' do
|
46
|
+
# try = search
|
47
|
+
# query = 'abracadabra mirgel'
|
48
|
+
# performance_of do
|
49
|
+
# amount.times { try.search query }
|
50
|
+
# end.should <= 0.15
|
51
|
+
# end
|
52
|
+
# end
|
53
|
+
# context 'with pool' do
|
54
|
+
# before(:each) do
|
55
|
+
# Picky::Pool.install
|
56
|
+
# end
|
57
|
+
# after(:each) do
|
58
|
+
# # Reload since installing the Pool taints the classes.
|
59
|
+
# #
|
60
|
+
# Picky::Loader.load_framework
|
61
|
+
# end
|
62
|
+
# it 'runs the GC less' do
|
63
|
+
# # Quickly check that the pool is added.
|
64
|
+
# #
|
65
|
+
# fail 'object pool not installed' unless Picky::Query::Token.respond_to? :release_all
|
66
|
+
#
|
67
|
+
# try = search
|
68
|
+
# query = 'abracadabra mirgel'
|
69
|
+
# gc_runs_of do
|
70
|
+
# amount.times do |i|
|
71
|
+
# try.search query
|
72
|
+
# Picky::Pool.release_all if i % 5 == 0
|
73
|
+
# end
|
74
|
+
# end.should <= 1 # Definitely less GC runs.
|
75
|
+
# end
|
76
|
+
# it 'is more (?) performant' do
|
77
|
+
# try = search
|
78
|
+
# query = 'abracadabra it whatever mirgel'
|
79
|
+
# performance_of do
|
80
|
+
# amount.times do |i|
|
81
|
+
# try.search query
|
82
|
+
# Picky::Pool.release_all if i % 5 == 0
|
83
|
+
# end
|
84
|
+
# end.should <= 0.2
|
85
|
+
# end
|
86
|
+
# end
|
86
87
|
|
87
88
|
end
|
@@ -478,7 +478,7 @@ describe "Realtime Indexing" do
|
|
478
478
|
let(:index) do
|
479
479
|
Picky::Index.new(:books) do
|
480
480
|
backend Picky::Backends::Redis.new(realtime: true)
|
481
|
-
key_format :to_s
|
481
|
+
key_format :to_s
|
482
482
|
category :title
|
483
483
|
category :author, similarity: Picky::Generators::Similarity::DoubleMetaphone.new(3)
|
484
484
|
end
|
@@ -4,15 +4,15 @@ describe Picky::Backends::Backend do
|
|
4
4
|
|
5
5
|
let(:backend) { described_class.new }
|
6
6
|
|
7
|
-
describe '
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
7
|
+
# describe 'score' do
|
8
|
+
# it 'forwards to the parameter' do
|
9
|
+
# combinations = stub :combinations
|
10
|
+
#
|
11
|
+
# combinations.should_receive(:score).once.with()
|
12
|
+
#
|
13
|
+
# backend.score combinations
|
14
|
+
# end
|
15
|
+
# end
|
16
16
|
|
17
17
|
describe 'to_s' do
|
18
18
|
it 'is correct' do
|
@@ -25,19 +25,16 @@ describe Picky::Backends::SQLite::Array do
|
|
25
25
|
it 'initializes the client' do
|
26
26
|
client.stub! :execute
|
27
27
|
|
28
|
-
db.should_receive(:
|
28
|
+
db.should_receive(:db).exactly(4).times.with
|
29
29
|
|
30
30
|
db.dump_sqlite Hash.new
|
31
31
|
end
|
32
32
|
it 'executes something' do
|
33
|
-
db.stub! :lazily_initialize_client
|
34
|
-
|
35
33
|
client.should_receive(:execute).at_least(1).times
|
36
34
|
|
37
35
|
db.dump_sqlite Hash.new
|
38
36
|
end
|
39
37
|
it 'inserts keys and values' do
|
40
|
-
db.stub! :lazily_initialize_client
|
41
38
|
client.stub! :execute # We only want to test the insert statements.
|
42
39
|
|
43
40
|
client.should_receive(:execute).once.with 'insert into key_value values (?,?)', 'a', '[1,2,3]'
|
@@ -93,19 +90,16 @@ describe Picky::Backends::SQLite::Array do
|
|
93
90
|
it 'initializes the client' do
|
94
91
|
client.stub! :execute
|
95
92
|
|
96
|
-
db.should_receive(:
|
93
|
+
db.should_receive(:db).exactly(4).times.with
|
97
94
|
|
98
95
|
db.dump_sqlite Hash.new
|
99
96
|
end
|
100
97
|
it 'executes something' do
|
101
|
-
db.stub! :lazily_initialize_client
|
102
|
-
|
103
98
|
client.should_receive(:execute).at_least(1).times
|
104
99
|
|
105
100
|
db.dump_sqlite Hash.new
|
106
101
|
end
|
107
102
|
it 'inserts keys and values' do
|
108
|
-
db.stub! :lazily_initialize_client
|
109
103
|
client.stub! :execute # We only want to test the insert statements.
|
110
104
|
|
111
105
|
client.should_receive(:execute).once.with 'insert into key_value values (?,?)', 'a', '[1,2,3]'
|
@@ -25,7 +25,7 @@ describe Picky::Backends::SQLite::Value do
|
|
25
25
|
it 'initializes the client' do
|
26
26
|
client.stub! :execute
|
27
27
|
|
28
|
-
db.should_receive(:
|
28
|
+
db.should_receive(:db).exactly(4).times.with
|
29
29
|
|
30
30
|
db.dump_sqlite Hash.new
|
31
31
|
end
|
@@ -37,7 +37,7 @@ describe Picky::Backends::SQLite::Value do
|
|
37
37
|
db.dump_sqlite Hash.new
|
38
38
|
end
|
39
39
|
it 'inserts keys and values' do
|
40
|
-
db.stub! :
|
40
|
+
# db.stub! :db
|
41
41
|
client.stub! :execute # We only want to test the insert statements.
|
42
42
|
|
43
43
|
client.should_receive(:execute).once.with 'insert into key_value values (?,?)', 'a', '[1,2,3]'
|
@@ -212,18 +212,6 @@ describe Picky::Category do
|
|
212
212
|
@category.stub! :exact => (@exact = stub :exact)
|
213
213
|
@category.stub! :partial => (@partial = stub :partial)
|
214
214
|
end
|
215
|
-
describe 'bundle_for' do
|
216
|
-
it 'should return the right bundle' do
|
217
|
-
token = stub :token, :partial? => false
|
218
|
-
|
219
|
-
@category.bundle_for(token).should == @exact
|
220
|
-
end
|
221
|
-
it 'should return the right bundle' do
|
222
|
-
token = stub :token, :partial? => true
|
223
|
-
|
224
|
-
@category.bundle_for(token).should == @partial
|
225
|
-
end
|
226
|
-
end
|
227
215
|
|
228
216
|
describe 'load' do
|
229
217
|
it 'should call two methods' do
|
@@ -184,10 +184,10 @@ describe Picky::Query::Allocation do
|
|
184
184
|
describe "calculate_score" do
|
185
185
|
context 'non-empty combinations' do
|
186
186
|
it 'should forward to backend and combinations' do
|
187
|
-
@
|
188
|
-
|
187
|
+
@combinations.should_receive(:score).once.and_return 1
|
188
|
+
weights = stub :weights, :boost_for => 2
|
189
189
|
|
190
|
-
@allocation.calculate_score(
|
190
|
+
@allocation.calculate_score(weights).should == 3
|
191
191
|
end
|
192
192
|
end
|
193
193
|
end
|