CloudSesame 0.9.3 → 0.9.4
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/Gemfile.lock +1 -1
- data/cloud_sesame.gemspec +1 -1
- data/lib/cloud_sesame.rb +0 -1
- data/lib/cloud_sesame/query/builder.rb +0 -1
- data/lib/cloud_sesame/query/domain/block.rb +0 -1
- metadata +1 -4
- data/lib/cloud_sesame/query/dsl/k_gram_phrase_methods.rb +0 -51
- data/spec/cloud_sesame/query/dsl/k_gram_phrase_methods_spec.rb +0 -119
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02f14e8cadd284a12b337f3e28fb7744e1065227
|
4
|
+
data.tar.gz: 565265a014c5a268368eeda35351ce1ae1d992ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b92efd2b60322029bd31fb265cef7af32e3103cb1a9c170698561128269950853cb47bc036a4ba6e5fd477ce5ab200a8a3ced3eb65c43689aa039f44a835b0ec
|
7
|
+
data.tar.gz: 3b4d7b871accdebdd3cfa671074911be4407fce7973de202db242f8390600724751958c8f64ac4b0967bec26e43075e09adecb133c9a3e9884362a34e1d00768
|
data/Gemfile.lock
CHANGED
data/cloud_sesame.gemspec
CHANGED
data/lib/cloud_sesame.rb
CHANGED
@@ -37,7 +37,6 @@ require 'cloud_sesame/query/dsl/range_helper'
|
|
37
37
|
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
|
-
require 'cloud_sesame/query/dsl/k_gram_phrase_methods'
|
41
40
|
require 'cloud_sesame/query/dsl/any_term_methods'
|
42
41
|
|
43
42
|
# Query Query Domain Objects
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Chu
|
@@ -189,7 +189,6 @@ files:
|
|
189
189
|
- lib/cloud_sesame/query/dsl/bind_caller.rb
|
190
190
|
- lib/cloud_sesame/query/dsl/block_styled_operators.rb
|
191
191
|
- lib/cloud_sesame/query/dsl/inspect_method.rb
|
192
|
-
- lib/cloud_sesame/query/dsl/k_gram_phrase_methods.rb
|
193
192
|
- lib/cloud_sesame/query/dsl/literal_chaining_methods.rb
|
194
193
|
- lib/cloud_sesame/query/dsl/literal_methods.rb
|
195
194
|
- lib/cloud_sesame/query/dsl/operators.rb
|
@@ -249,7 +248,6 @@ files:
|
|
249
248
|
- spec/cloud_sesame/query/dsl/any_term_methods_spec.rb
|
250
249
|
- spec/cloud_sesame/query/dsl/applied_filter_query_spec.rb
|
251
250
|
- spec/cloud_sesame/query/dsl/block_styled_operators_spec.rb
|
252
|
-
- spec/cloud_sesame/query/dsl/k_gram_phrase_methods_spec.rb
|
253
251
|
- spec/cloud_sesame/query/dsl/literal_chaining_methods_spec.rb
|
254
252
|
- spec/cloud_sesame/query/dsl/literal_methods_spec.rb
|
255
253
|
- spec/cloud_sesame/query/node/abstract_spec.rb
|
@@ -323,7 +321,6 @@ test_files:
|
|
323
321
|
- spec/cloud_sesame/query/dsl/any_term_methods_spec.rb
|
324
322
|
- spec/cloud_sesame/query/dsl/applied_filter_query_spec.rb
|
325
323
|
- spec/cloud_sesame/query/dsl/block_styled_operators_spec.rb
|
326
|
-
- spec/cloud_sesame/query/dsl/k_gram_phrase_methods_spec.rb
|
327
324
|
- spec/cloud_sesame/query/dsl/literal_chaining_methods_spec.rb
|
328
325
|
- spec/cloud_sesame/query/dsl/literal_methods_spec.rb
|
329
326
|
- spec/cloud_sesame/query/node/abstract_spec.rb
|
@@ -1,51 +0,0 @@
|
|
1
|
-
module CloudSesame
|
2
|
-
module Query
|
3
|
-
module DSL
|
4
|
-
module KGramPhraseMethods
|
5
|
-
DELIMITER = ' '.freeze
|
6
|
-
MULTIPLIER = 10 # Even number that controls the separation between k-grams
|
7
|
-
|
8
|
-
def k_gram_phrase(field, value, options = {})
|
9
|
-
if value && !value.empty?
|
10
|
-
words = value.split(DELIMITER).compact
|
11
|
-
|
12
|
-
or!(options) do
|
13
|
-
literal field, phrase(value, boost: MULTIPLIER * words.size + MULTIPLIER)
|
14
|
-
|
15
|
-
each_k_gram_combination(words, options[:min]) do |combination, original|
|
16
|
-
remaining_terms = (original - combination).join(' ')
|
17
|
-
unique_phrase = combination.join(' ')
|
18
|
-
boost = MULTIPLIER * combination.size
|
19
|
-
|
20
|
-
and!(boost: boost + MULTIPLIER / 2 + MULTIPLIER) do
|
21
|
-
literal field, phrase(unique_phrase)
|
22
|
-
literal field, term(remaining_terms)
|
23
|
-
end
|
24
|
-
|
25
|
-
literal field, phrase(unique_phrase, boost: boost / 2)
|
26
|
-
end
|
27
|
-
|
28
|
-
literal field, term(value, boost: MULTIPLIER + MULTIPLIER)
|
29
|
-
any_term(field, words.join(' '))
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
_return != _scope ? _return : self
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def each_k_gram_combination(array, min)
|
39
|
-
min ||= 4
|
40
|
-
size = array.size
|
41
|
-
m = [size - min, 1].max
|
42
|
-
n = size - 1
|
43
|
-
while n > m
|
44
|
-
array.each_cons(n) { |con| yield(con, array) }
|
45
|
-
n -= 1
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,119 +0,0 @@
|
|
1
|
-
module CloudSesame
|
2
|
-
module Query
|
3
|
-
module DSL
|
4
|
-
describe KGramPhraseMethods do
|
5
|
-
|
6
|
-
class Product
|
7
|
-
include CloudSesame
|
8
|
-
define_cloudsearch do
|
9
|
-
field :name, query: { weight: 2 }, type: :string
|
10
|
-
field :description, query: { weight: 0.4 }, type: :string
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
subject(:cloudsearch) { Product.cloudsearch.builder }
|
15
|
-
let(:root) { cloudsearch.request.filter_query.root }
|
16
|
-
|
17
|
-
describe '#k_gram_phrase' do
|
18
|
-
let(:phrase) { 'listerine mouth wash' }
|
19
|
-
|
20
|
-
it 'inserts an OR node at its scope level' do
|
21
|
-
expect { cloudsearch.k_gram_phrase(:name, phrase) }.to change { root.children }.by([AST::Or])
|
22
|
-
end
|
23
|
-
|
24
|
-
describe 'in the OR node' do
|
25
|
-
let(:or_node) { root.children.first }
|
26
|
-
|
27
|
-
it 'builds a phrase node with original term' do
|
28
|
-
cloudsearch.k_gram_phrase(:name, phrase)
|
29
|
-
|
30
|
-
phrase_node = or_node.children.first
|
31
|
-
expect(phrase_node).to be_kind_of AST::Phrase
|
32
|
-
expect(phrase_node.child.value).to eq(phrase)
|
33
|
-
expect(phrase_node.options[:boost]).to eq(KGramPhraseMethods::MULTIPLIER * 3 + KGramPhraseMethods::MULTIPLIER)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'builds a term node with original term' do
|
37
|
-
cloudsearch.k_gram_phrase(:name, phrase)
|
38
|
-
|
39
|
-
term_node = or_node.children[-2]
|
40
|
-
expect(term_node).to be_kind_of AST::Term
|
41
|
-
expect(term_node.child.value).to eq(phrase)
|
42
|
-
expect(term_node.options[:boost]).to eq(KGramPhraseMethods::MULTIPLIER + KGramPhraseMethods::MULTIPLIER)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'builds bunch of phrase nodes with k grams' do
|
46
|
-
cloudsearch.k_gram_phrase(:name, phrase)
|
47
|
-
k_nodes = or_node.children[1..-2]
|
48
|
-
|
49
|
-
expect(k_nodes[0]).to be_kind_of AST::And
|
50
|
-
|
51
|
-
expect(k_nodes[1]).to be_kind_of AST::Phrase
|
52
|
-
expect(k_nodes[1].options[:boost]).to eq(KGramPhraseMethods::MULTIPLIER * 2 / 2)
|
53
|
-
expect(k_nodes[1].child.value).to eq('listerine mouth')
|
54
|
-
|
55
|
-
expect(k_nodes[2]).to be_kind_of AST::And
|
56
|
-
|
57
|
-
expect(k_nodes[3]).to be_kind_of AST::Phrase
|
58
|
-
expect(k_nodes[3].options[:boost]).to eq(KGramPhraseMethods::MULTIPLIER * 2 / 2)
|
59
|
-
expect(k_nodes[3].child.value).to eq('mouth wash')
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'builds the correct first And node (for k-gram plus excluded terms)' do
|
63
|
-
cloudsearch.k_gram_phrase(:name, phrase)
|
64
|
-
and_node = or_node.children[1..-2][0]
|
65
|
-
|
66
|
-
expect(and_node.options[:boost]).to eq(KGramPhraseMethods::MULTIPLIER * 2 + KGramPhraseMethods::MULTIPLIER / 2 + KGramPhraseMethods::MULTIPLIER)
|
67
|
-
|
68
|
-
expect(and_node.children.first).to be_kind_of AST::Phrase
|
69
|
-
expect(and_node.children.first.child.value).to eq('listerine mouth')
|
70
|
-
|
71
|
-
expect(and_node.children.last).to be_kind_of AST::Term
|
72
|
-
expect(and_node.children.last.child.value).to eq('wash')
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'builds the correct second And node (for k-gram plus excluded terms)' do
|
76
|
-
cloudsearch.k_gram_phrase(:name, phrase)
|
77
|
-
and_node = or_node.children[1..-2][2]
|
78
|
-
|
79
|
-
expect(and_node.options[:boost]).to eq(KGramPhraseMethods::MULTIPLIER * 2 + KGramPhraseMethods::MULTIPLIER / 2 + KGramPhraseMethods::MULTIPLIER)
|
80
|
-
|
81
|
-
expect(and_node.children.first).to be_kind_of AST::Phrase
|
82
|
-
expect(and_node.children.first.child.value).to eq('mouth wash')
|
83
|
-
|
84
|
-
expect(and_node.children.last).to be_kind_of AST::Term
|
85
|
-
expect(and_node.children.last.child.value).to eq('listerine')
|
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
|
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
|
106
|
-
end
|
107
|
-
|
108
|
-
context 'when phrase is empty' do
|
109
|
-
let(:phrase) { nil }
|
110
|
-
|
111
|
-
it 'does not build anything' do
|
112
|
-
expect { cloudsearch.k_gram_phrase(:name, phrase) }.to_not change { root.children }
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|