CloudSesame 0.9.0 → 0.9.1
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/cloud_sesame.gemspec +2 -2
- data/lib/cloud_sesame/query/builder.rb +1 -0
- data/lib/cloud_sesame/query/domain/block.rb +1 -0
- data/lib/cloud_sesame/query/dsl/any_term_methods.rb +19 -0
- data/lib/cloud_sesame/query/dsl/k_gram_phrase_methods.rb +8 -7
- data/lib/cloud_sesame.rb +1 -0
- data/spec/cloud_sesame/query/dsl/any_term_methods_spec.rb +44 -0
- data/spec/cloud_sesame/query/dsl/k_gram_phrase_methods_spec.rb +27 -11
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45e91a7582d996276e3fc0b28078ab0bf8ca64cd
|
4
|
+
data.tar.gz: 5d7ac46418e7ff5ca948b70c4abea3ae265b3794
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fab65fb6973916daf9462762667db1a8b8016113e569403ac709eeab784f6ddb36994cb63d0ba9064c554486d832e942ab734a3503f7f3adf8e9abaa1f6cb12
|
7
|
+
data.tar.gz: 144650056b9cef90fabf98ea06e91c654b314c51022f18dd8db4bfee51b5885675010f30f6e18202c6a88f6fceb8712250e1cdecc070b71467195e85474b73cc
|
data/Gemfile.lock
CHANGED
data/cloud_sesame.gemspec
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
module CloudSesame
|
2
|
+
module Query
|
3
|
+
module DSL
|
4
|
+
module AnyTermMethods
|
5
|
+
def any_term(field, words, options = {})
|
6
|
+
if words && words.length > 0
|
7
|
+
or!(options) do
|
8
|
+
words.map do |word|
|
9
|
+
literal field, term(word)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
_return != _scope ? _return : self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -3,29 +3,30 @@ module CloudSesame
|
|
3
3
|
module DSL
|
4
4
|
module KGramPhraseMethods
|
5
5
|
DELIMITER = / |-/.freeze
|
6
|
-
MULTIPLIER =
|
6
|
+
MULTIPLIER = 10 # Even number that controls the separation between k-grams
|
7
7
|
|
8
8
|
def k_gram_phrase(field, value, options = {})
|
9
9
|
if value && !value.empty?
|
10
10
|
words = value.split(DELIMITER).compact
|
11
11
|
|
12
12
|
or!(options) do
|
13
|
-
literal field, phrase(value, boost: MULTIPLIER * words.size)
|
13
|
+
literal field, phrase(value, boost: MULTIPLIER * words.size + MULTIPLIER)
|
14
14
|
|
15
15
|
each_k_gram_combination(words, options[:min]) do |combination, original|
|
16
16
|
remaining_terms = (original - combination).join(' ')
|
17
17
|
unique_phrase = combination.join(' ')
|
18
|
-
|
18
|
+
boost = MULTIPLIER * combination.size
|
19
19
|
|
20
|
-
and!(boost:
|
20
|
+
and!(boost: boost + MULTIPLIER / 2) do
|
21
21
|
literal field, phrase(unique_phrase)
|
22
22
|
literal field, term(remaining_terms)
|
23
23
|
end
|
24
24
|
|
25
|
-
literal field, phrase(unique_phrase, boost:
|
25
|
+
literal field, phrase(unique_phrase, boost: boost)
|
26
26
|
end
|
27
27
|
|
28
|
-
literal field, term(value)
|
28
|
+
literal field, term(value, boost: MULTIPLIER)
|
29
|
+
any_term(field, words)
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
@@ -47,4 +48,4 @@ module CloudSesame
|
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
50
|
-
end
|
51
|
+
end
|
data/lib/cloud_sesame.rb
CHANGED
@@ -38,6 +38,7 @@ require 'cloud_sesame/query/dsl/response_methods'
|
|
38
38
|
require 'cloud_sesame/query/dsl/return_methods'
|
39
39
|
require 'cloud_sesame/query/dsl/sort_methods'
|
40
40
|
require 'cloud_sesame/query/dsl/k_gram_phrase_methods'
|
41
|
+
require 'cloud_sesame/query/dsl/any_term_methods'
|
41
42
|
|
42
43
|
# Query Query Domain Objects
|
43
44
|
# ===============================================
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module CloudSesame
|
2
|
+
module Query
|
3
|
+
module DSL
|
4
|
+
describe AnyTermMethods do
|
5
|
+
class Product
|
6
|
+
include CloudSesame
|
7
|
+
define_cloudsearch do
|
8
|
+
field :name, query: { weight: 2 }, type: :string
|
9
|
+
field :description, query: { weight: 0.4 }, type: :string
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
subject(:cloudsearch) { Product.cloudsearch.builder }
|
14
|
+
let(:root) { cloudsearch.request.filter_query.root }
|
15
|
+
|
16
|
+
describe '#any_term' do
|
17
|
+
let(:words) { %w(listerine mouth wash) }
|
18
|
+
|
19
|
+
it 'inserts an OR node at its scope level' do
|
20
|
+
expect { cloudsearch.any_term(:name, words) }.to change { root.children }.by([AST::Or])
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'in the OR node' do
|
24
|
+
let(:or_node) { root.children.first }
|
25
|
+
|
26
|
+
it 'builds a term node with each word' do
|
27
|
+
cloudsearch.any_term(:name, words)
|
28
|
+
|
29
|
+
expect(or_node.children[0]).to be_kind_of AST::Term
|
30
|
+
expect(or_node.children[0].child.value).to eq('listerine')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when words is empty or nil' do
|
35
|
+
it 'does not build anything' do
|
36
|
+
expect { cloudsearch.any_term(:name, nil) }.to_not change { root.children }
|
37
|
+
expect { cloudsearch.any_term(:name, []) }.to_not change { root.children }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -30,38 +30,40 @@ module CloudSesame
|
|
30
30
|
phrase_node = or_node.children.first
|
31
31
|
expect(phrase_node).to be_kind_of AST::Phrase
|
32
32
|
expect(phrase_node.child.value).to eq(phrase)
|
33
|
+
expect(phrase_node.options[:boost]).to eq(KGramPhraseMethods::MULTIPLIER * 3 + KGramPhraseMethods::MULTIPLIER)
|
33
34
|
end
|
34
35
|
|
35
36
|
it 'builds a term node with original term' do
|
36
37
|
cloudsearch.k_gram_phrase(:name, phrase)
|
37
38
|
|
38
|
-
term_node = or_node.children
|
39
|
+
term_node = or_node.children[-2]
|
39
40
|
expect(term_node).to be_kind_of AST::Term
|
40
41
|
expect(term_node.child.value).to eq(phrase)
|
42
|
+
expect(term_node.options[:boost]).to eq(KGramPhraseMethods::MULTIPLIER)
|
41
43
|
end
|
42
44
|
|
43
45
|
it 'builds bunch of phrase nodes with k grams' do
|
44
46
|
cloudsearch.k_gram_phrase(:name, phrase)
|
45
|
-
k_nodes = or_node.children[1..-
|
47
|
+
k_nodes = or_node.children[1..-2]
|
46
48
|
|
47
49
|
expect(k_nodes[0]).to be_kind_of AST::And
|
48
50
|
|
49
51
|
expect(k_nodes[1]).to be_kind_of AST::Phrase
|
50
|
-
expect(k_nodes[1].options[:boost]).to eq(
|
52
|
+
expect(k_nodes[1].options[:boost]).to eq(KGramPhraseMethods::MULTIPLIER * 2)
|
51
53
|
expect(k_nodes[1].child.value).to eq('listerine mouth')
|
52
54
|
|
53
55
|
expect(k_nodes[2]).to be_kind_of AST::And
|
54
56
|
|
55
57
|
expect(k_nodes[3]).to be_kind_of AST::Phrase
|
56
|
-
expect(k_nodes[3].options[:boost]).to eq(
|
58
|
+
expect(k_nodes[3].options[:boost]).to eq(KGramPhraseMethods::MULTIPLIER * 2)
|
57
59
|
expect(k_nodes[3].child.value).to eq('mouth wash')
|
58
60
|
end
|
59
61
|
|
60
|
-
it 'builds the correct first And node' do
|
62
|
+
it 'builds the correct first And node (for k-gram plus excluded terms)' do
|
61
63
|
cloudsearch.k_gram_phrase(:name, phrase)
|
62
|
-
and_node = or_node.children[1..-
|
64
|
+
and_node = or_node.children[1..-2][0]
|
63
65
|
|
64
|
-
expect(and_node.options[:boost]).to eq(
|
66
|
+
expect(and_node.options[:boost]).to eq(KGramPhraseMethods::MULTIPLIER * 2 + KGramPhraseMethods::MULTIPLIER / 2)
|
65
67
|
|
66
68
|
expect(and_node.children.first).to be_kind_of AST::Phrase
|
67
69
|
expect(and_node.children.first.child.value).to eq('listerine mouth')
|
@@ -70,11 +72,11 @@ module CloudSesame
|
|
70
72
|
expect(and_node.children.last.child.value).to eq('wash')
|
71
73
|
end
|
72
74
|
|
73
|
-
it 'builds the correct second And node' do
|
75
|
+
it 'builds the correct second And node (for k-gram plus excluded terms)' do
|
74
76
|
cloudsearch.k_gram_phrase(:name, phrase)
|
75
|
-
and_node = or_node.children[1..-
|
77
|
+
and_node = or_node.children[1..-2][2]
|
76
78
|
|
77
|
-
expect(and_node.options[:boost]).to eq(
|
79
|
+
expect(and_node.options[:boost]).to eq(KGramPhraseMethods::MULTIPLIER * 2 + KGramPhraseMethods::MULTIPLIER / 2)
|
78
80
|
|
79
81
|
expect(and_node.children.first).to be_kind_of AST::Phrase
|
80
82
|
expect(and_node.children.first.child.value).to eq('mouth wash')
|
@@ -82,6 +84,20 @@ module CloudSesame
|
|
82
84
|
expect(and_node.children.last).to be_kind_of AST::Term
|
83
85
|
expect(and_node.children.last.child.value).to eq('listerine')
|
84
86
|
end
|
87
|
+
|
88
|
+
it 'builds an or node with term nodes for each word' do
|
89
|
+
cloudsearch.k_gram_phrase(:name, phrase)
|
90
|
+
node = or_node.children.last
|
91
|
+
|
92
|
+
expect(node).to be_kind_of(AST::Or)
|
93
|
+
expect(node.children.length).to eq(3)
|
94
|
+
expect(node.children[0]).to be_kind_of(AST::Term)
|
95
|
+
expect(node.children[0].child.value).to eq('listerine')
|
96
|
+
expect(node.children[1]).to be_kind_of(AST::Term)
|
97
|
+
expect(node.children[1].child.value).to eq('mouth')
|
98
|
+
expect(node.children[2]).to be_kind_of(AST::Term)
|
99
|
+
expect(node.children[2].child.value).to eq('wash')
|
100
|
+
end
|
85
101
|
end
|
86
102
|
|
87
103
|
context 'when phrase is empty' do
|
@@ -96,4 +112,4 @@ module CloudSesame
|
|
96
112
|
end
|
97
113
|
end
|
98
114
|
end
|
99
|
-
end
|
115
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: CloudSesame
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Chu
|
@@ -16,7 +16,7 @@ authors:
|
|
16
16
|
autorequire:
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
|
-
date: 2016-09-
|
19
|
+
date: 2016-09-12 00:00:00.000000000 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: aws-sdk
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- lib/cloud_sesame/query/domain/block.rb
|
185
185
|
- lib/cloud_sesame/query/domain/chaining_block.rb
|
186
186
|
- lib/cloud_sesame/query/domain/literal.rb
|
187
|
+
- lib/cloud_sesame/query/dsl/any_term_methods.rb
|
187
188
|
- lib/cloud_sesame/query/dsl/applied_filter_query.rb
|
188
189
|
- lib/cloud_sesame/query/dsl/bind_caller.rb
|
189
190
|
- lib/cloud_sesame/query/dsl/block_styled_operators.rb
|
@@ -245,6 +246,7 @@ files:
|
|
245
246
|
- spec/cloud_sesame/query/ast/value_spec.rb
|
246
247
|
- spec/cloud_sesame/query/builder_spec.rb
|
247
248
|
- spec/cloud_sesame/query/domain/block_spec.rb
|
249
|
+
- spec/cloud_sesame/query/dsl/any_term_methods_spec.rb
|
248
250
|
- spec/cloud_sesame/query/dsl/applied_filter_query_spec.rb
|
249
251
|
- spec/cloud_sesame/query/dsl/block_styled_operators_spec.rb
|
250
252
|
- spec/cloud_sesame/query/dsl/k_gram_phrase_methods_spec.rb
|
@@ -287,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
287
289
|
version: '0'
|
288
290
|
requirements: []
|
289
291
|
rubyforge_project:
|
290
|
-
rubygems_version: 2.
|
292
|
+
rubygems_version: 2.6.4
|
291
293
|
signing_key:
|
292
294
|
specification_version: 4
|
293
295
|
summary: AWS CloudSearch Query DSL
|
@@ -318,6 +320,7 @@ test_files:
|
|
318
320
|
- spec/cloud_sesame/query/ast/value_spec.rb
|
319
321
|
- spec/cloud_sesame/query/builder_spec.rb
|
320
322
|
- spec/cloud_sesame/query/domain/block_spec.rb
|
323
|
+
- spec/cloud_sesame/query/dsl/any_term_methods_spec.rb
|
321
324
|
- spec/cloud_sesame/query/dsl/applied_filter_query_spec.rb
|
322
325
|
- spec/cloud_sesame/query/dsl/block_styled_operators_spec.rb
|
323
326
|
- spec/cloud_sesame/query/dsl/k_gram_phrase_methods_spec.rb
|