CloudSesame 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/Gemfile.lock +1 -1
- data/cloud_sesame.gemspec +1 -1
- data/lib/cloud_sesame/query/dsl/any_term_methods.rb +5 -1
- data/lib/cloud_sesame/query/dsl/k_gram_phrase_methods.rb +2 -2
- data/spec/cloud_sesame/query/dsl/any_term_methods_spec.rb +17 -6
- data/spec/cloud_sesame/query/dsl/k_gram_phrase_methods_spec.rb +5 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5acd8fee5275581b3fc7fac1f332e5779b3aa064
|
4
|
+
data.tar.gz: 5f1313d23fb0297f89dcf0783d29fab8fe853af1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 294d90239e515d7f13da742a0c62169ff9630324c1209bc631b3f6733bfdec4059437ea5abd798dc64bcdee821fa8acb681c5ceabe7437b3378995b1de6591e1
|
7
|
+
data.tar.gz: 4292d9628ef96012dd6662fffd4d449c2d54b06338481c7bf2f3fbbfafbf708b7f5ef080d6bbae86d3edbf06b019f959fe11397473d488410fa0fce252f08692
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/cloud_sesame.gemspec
CHANGED
@@ -2,7 +2,11 @@ module CloudSesame
|
|
2
2
|
module Query
|
3
3
|
module DSL
|
4
4
|
module AnyTermMethods
|
5
|
-
|
5
|
+
DELIMITER = ' '.freeze
|
6
|
+
|
7
|
+
def any_term(field, phrase, options = {})
|
8
|
+
words = phrase&.split(DELIMITER)
|
9
|
+
|
6
10
|
if words && words.length > 0
|
7
11
|
or!(options) do
|
8
12
|
words.map do |word|
|
@@ -2,7 +2,7 @@ module CloudSesame
|
|
2
2
|
module Query
|
3
3
|
module DSL
|
4
4
|
module KGramPhraseMethods
|
5
|
-
DELIMITER =
|
5
|
+
DELIMITER = ' '.freeze
|
6
6
|
MULTIPLIER = 10 # Even number that controls the separation between k-grams
|
7
7
|
|
8
8
|
def k_gram_phrase(field, value, options = {})
|
@@ -26,7 +26,7 @@ module CloudSesame
|
|
26
26
|
end
|
27
27
|
|
28
28
|
literal field, term(value, boost: MULTIPLIER)
|
29
|
-
any_term(field, words)
|
29
|
+
any_term(field, words.join(' '))
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -14,27 +14,38 @@ module CloudSesame
|
|
14
14
|
let(:root) { cloudsearch.request.filter_query.root }
|
15
15
|
|
16
16
|
describe '#any_term' do
|
17
|
-
let(:
|
17
|
+
let(:phrase) { 'listerine mouth wash' }
|
18
18
|
|
19
19
|
it 'inserts an OR node at its scope level' do
|
20
|
-
expect { cloudsearch.any_term(:name,
|
20
|
+
expect { cloudsearch.any_term(:name, phrase) }.to change { root.children }.by([AST::Or])
|
21
21
|
end
|
22
22
|
|
23
23
|
describe 'in the OR node' do
|
24
24
|
let(:or_node) { root.children.first }
|
25
25
|
|
26
26
|
it 'builds a term node with each word' do
|
27
|
-
cloudsearch.any_term(:name,
|
27
|
+
cloudsearch.any_term(:name, phrase)
|
28
28
|
|
29
29
|
expect(or_node.children[0]).to be_kind_of AST::Term
|
30
30
|
expect(or_node.children[0].child.value).to eq('listerine')
|
31
31
|
end
|
32
|
+
|
33
|
+
context 'when - is in phrase' do
|
34
|
+
let(:phrase) { 'a-b c' }
|
35
|
+
|
36
|
+
it 'only splits on space' do
|
37
|
+
cloudsearch.any_term(:name, phrase)
|
38
|
+
|
39
|
+
expect(or_node.children.length).to eq(2)
|
40
|
+
end
|
41
|
+
end
|
32
42
|
end
|
33
43
|
|
34
|
-
context 'when
|
44
|
+
context 'when phrase is empty' do
|
45
|
+
let(:phrase) { nil }
|
46
|
+
|
35
47
|
it 'does not build anything' do
|
36
|
-
expect { cloudsearch.any_term(:name,
|
37
|
-
expect { cloudsearch.any_term(:name, []) }.to_not change { root.children }
|
48
|
+
expect { cloudsearch.any_term(:name, phrase) }.to_not change { root.children }
|
38
49
|
end
|
39
50
|
end
|
40
51
|
end
|
@@ -98,6 +98,11 @@ module CloudSesame
|
|
98
98
|
expect(node.children[2]).to be_kind_of(AST::Term)
|
99
99
|
expect(node.children[2].child.value).to eq('wash')
|
100
100
|
end
|
101
|
+
|
102
|
+
it 'splits the phrase on space and nothing else' do
|
103
|
+
cloudsearch.k_gram_phrase(:name, 'word-word2 word3')
|
104
|
+
expect(or_node.children.length).to eq(3)
|
105
|
+
end
|
101
106
|
end
|
102
107
|
|
103
108
|
context 'when phrase is empty' do
|
@@ -108,7 +113,6 @@ module CloudSesame
|
|
108
113
|
end
|
109
114
|
end
|
110
115
|
end
|
111
|
-
|
112
116
|
end
|
113
117
|
end
|
114
118
|
end
|