CloudSesame 0.6.7 → 0.6.8
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/coverage/.last_run.json +1 -1
- data/coverage/.resultset.json +294 -288
- data/lib/cloud_sesame/domain/base.rb +0 -1
- data/lib/cloud_sesame/domain/client_module/caching/rails_cache.rb +2 -0
- data/lib/cloud_sesame/query/node/query.rb +9 -4
- data/spec/cloud_sesame/domain/client_module/caching_spec.rb +11 -5
- data/spec/cloud_sesame/query/ast/single_expression_operator_spec.rb +0 -6
- data/spec/cloud_sesame/query/node/query_spec.rb +82 -38
- metadata +1 -1
@@ -11,10 +11,15 @@ module CloudSesame
|
|
11
11
|
|
12
12
|
def compile
|
13
13
|
if query && !query.empty?
|
14
|
-
compiled =
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
compiled = "(#{ query })"
|
15
|
+
|
16
|
+
[fuzziness, sloppiness].each do |parser|
|
17
|
+
if parser && (parsed = parser.compile(query))
|
18
|
+
compiled << "|" << parsed
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
{ query: compiled }
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
@@ -49,19 +49,25 @@ module CloudSesame
|
|
49
49
|
end
|
50
50
|
|
51
51
|
describe 'executor getter' do
|
52
|
+
it 'should return an Caching::NoCache executor by default' do
|
53
|
+
expect(subject.executor).to be_kind_of(Caching::NoCache)
|
54
|
+
end
|
52
55
|
it 'should default to Caching::NoCache' do
|
53
56
|
expect(Caching::NoCache).to receive(:new).with(subject.searchable) do |_, &lazy_client|
|
54
|
-
expect(lazy_client.call).to eq subject.
|
55
|
-
end
|
56
|
-
|
57
|
+
expect(lazy_client.call).to eq subject.aws_client
|
58
|
+
end
|
59
|
+
subject.executor
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
60
63
|
describe 'executor setter' do
|
61
64
|
it 'should accept a caching module' do
|
62
65
|
expect(Caching::GoodCache).to receive(:new).with(subject.searchable) do |_, &lazy_client|
|
63
|
-
expect(lazy_client.call).to eq subject.
|
64
|
-
end
|
66
|
+
expect(lazy_client.call).to eq subject.aws_client
|
67
|
+
end
|
68
|
+
subject.executor = Caching::GoodCache
|
69
|
+
end
|
70
|
+
it 'should return a Caching::GoodCache instance' do
|
65
71
|
subject.executor = Caching::GoodCache
|
66
72
|
expect(subject.executor).to be_kind_of Caching::GoodCache
|
67
73
|
end
|
@@ -35,12 +35,6 @@ module CloudSesame
|
|
35
35
|
subject.is_excluded
|
36
36
|
end
|
37
37
|
end
|
38
|
-
context 'when child not exist' do
|
39
|
-
it 'should call #is_excluded on it\'s child' do
|
40
|
-
expect(subject.child).to_not receive(:is_excluded)
|
41
|
-
subject.is_excluded
|
42
|
-
end
|
43
|
-
end
|
44
38
|
end
|
45
39
|
|
46
40
|
describe '#<<' do
|
@@ -4,56 +4,100 @@ module CloudSesame
|
|
4
4
|
module Query
|
5
5
|
module Node
|
6
6
|
describe Query do
|
7
|
-
let(:
|
8
|
-
let(:node) { Query.new(
|
7
|
+
let(:context) {{ }}
|
8
|
+
let(:node) { Query.new(context) }
|
9
|
+
subject { Query.new(context) }
|
9
10
|
|
10
|
-
describe '#
|
11
|
-
context 'when
|
12
|
-
let(:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
it 'should accept query as args and initialize query' do
|
17
|
-
arguments[:query] = "hello world"
|
18
|
-
expect(node.query).to eq "hello world"
|
11
|
+
describe '#query' do
|
12
|
+
context 'when context include query on initialize' do
|
13
|
+
let(:query_string) { "hello world" }
|
14
|
+
let(:context) { { query: query_string }}
|
15
|
+
it 'should set query to context query' do
|
16
|
+
expect(subject.query).to eq query_string
|
19
17
|
end
|
20
18
|
end
|
21
|
-
context 'when
|
22
|
-
it 'should
|
23
|
-
expect(
|
19
|
+
context 'when context does not include query on initialize' do
|
20
|
+
it 'should just return nil' do
|
21
|
+
expect(subject.query).to eq nil
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
28
|
-
describe '#query' do
|
29
|
-
it 'should return the query string' do
|
30
|
-
node.query = ["term1", "term2", "term3", "-term4"].join(' ')
|
31
|
-
expect(node.query).to eq "term1 term2 term3 -term4"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
26
|
describe '#compile' do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
27
|
+
|
28
|
+
shared_examples 'common query compile actions' do
|
29
|
+
context 'and query is nil' do
|
30
|
+
let(:query_string) { nil }
|
31
|
+
it 'should return nil' do
|
32
|
+
expect(subject.compile).to eq nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
context 'and query is empty' do
|
36
|
+
let(:query_string) { "" }
|
37
|
+
it 'should return nil' do
|
38
|
+
expect(subject.compile).to eq nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
context 'and query contains one word' do
|
42
|
+
let(:query_string) { "oneword" }
|
43
|
+
it 'should include the original string inside parenthesis' do
|
44
|
+
expect(subject.compile[:query]).to include("(#{ query_string })")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
context 'and query contains multiple words' do
|
48
|
+
let(:query_string) { "one three fourty longword" }
|
49
|
+
it 'should include the original string inside parenthesis' do
|
50
|
+
expect(subject.compile[:query]).to include("(#{ query_string })")
|
51
|
+
end
|
43
52
|
end
|
44
53
|
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
54
|
+
|
55
|
+
shared_examples 'with additional parser defined' do |parser_name|
|
56
|
+
context 'and query string is nil' do
|
57
|
+
let(:query_string) { nil }
|
58
|
+
it "should not trigger #{ parser_name }" do
|
59
|
+
expect(parser).to_not receive(:compile)
|
60
|
+
subject.compile
|
61
|
+
end
|
62
|
+
end
|
63
|
+
context 'and query string is empty' do
|
64
|
+
let(:query_string) { "" }
|
65
|
+
it "should not trigger #{ parser_name }" do
|
66
|
+
expect(parser).to_not receive(:compile)
|
67
|
+
subject.compile
|
68
|
+
end
|
69
|
+
end
|
70
|
+
context 'and query string exist and not empty' do
|
71
|
+
let(:query_string) { "not empty" }
|
72
|
+
it "should trigger #{ parser_name }" do
|
73
|
+
result = parser.compile(query_string)
|
74
|
+
expect(parser).to receive(:compile).with(query_string).and_call_original
|
75
|
+
expect(subject.compile[:query]).to include(result)
|
76
|
+
end
|
52
77
|
end
|
53
78
|
end
|
54
|
-
|
55
|
-
|
56
|
-
|
79
|
+
|
80
|
+
context 'when both fuzziness and sloppiness are not defined' do
|
81
|
+
let(:context) {{ query: query_string }}
|
82
|
+
include_examples 'common query compile actions'
|
83
|
+
end
|
84
|
+
context 'when fuzziness is defined' do
|
85
|
+
let(:parser) { Fuzziness.new }
|
86
|
+
let(:context) {{
|
87
|
+
query: query_string,
|
88
|
+
fuzziness: parser
|
89
|
+
}}
|
90
|
+
include_examples 'common query compile actions'
|
91
|
+
include_examples 'with additional parser defined', "fuzziness"
|
92
|
+
end
|
93
|
+
context 'when sloppiness is defined' do
|
94
|
+
let(:parser) { Sloppiness.new(3) }
|
95
|
+
let(:context) {{
|
96
|
+
query: query_string,
|
97
|
+
sloppiness: parser
|
98
|
+
}}
|
99
|
+
include_examples 'common query compile actions'
|
100
|
+
include_examples 'with additional parser defined', "sloppiness"
|
57
101
|
end
|
58
102
|
end
|
59
103
|
|