CloudSesame 0.1.5 → 0.1.6

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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +57 -0
  4. data/cloud_sesame.gemspec +1 -1
  5. data/lib/cloud_sesame.rb +9 -5
  6. data/lib/cloud_sesame/domain/base.rb +4 -12
  7. data/lib/cloud_sesame/query/ast/compound_array.rb +30 -35
  8. data/lib/cloud_sesame/query/ast/date_value.rb +1 -9
  9. data/lib/cloud_sesame/query/ast/literal.rb +20 -20
  10. data/lib/cloud_sesame/query/ast/multi_branch.rb +1 -1
  11. data/lib/cloud_sesame/query/ast/multi_expression_operator.rb +2 -4
  12. data/lib/cloud_sesame/query/ast/near.rb +11 -2
  13. data/lib/cloud_sesame/query/ast/phrase.rb +14 -0
  14. data/lib/cloud_sesame/query/ast/prefix.rb +1 -2
  15. data/lib/cloud_sesame/query/ast/range_value.rb +16 -41
  16. data/lib/cloud_sesame/query/ast/root.rb +3 -13
  17. data/lib/cloud_sesame/query/ast/single_branch.rb +5 -2
  18. data/lib/cloud_sesame/query/ast/single_expression_operator.rb +2 -4
  19. data/lib/cloud_sesame/query/ast/term.rb +14 -0
  20. data/lib/cloud_sesame/query/ast/value.rb +10 -2
  21. data/lib/cloud_sesame/query/builder.rb +30 -5
  22. data/lib/cloud_sesame/query/dsl/boost.rb +20 -0
  23. data/lib/cloud_sesame/query/dsl/filter_query.rb +11 -20
  24. data/lib/cloud_sesame/query/dsl/literal.rb +48 -8
  25. data/lib/cloud_sesame/query/dsl/page.rb +4 -0
  26. data/lib/cloud_sesame/query/dsl/return.rb +21 -0
  27. data/lib/cloud_sesame/query/dsl/value.rb +28 -0
  28. data/lib/cloud_sesame/query/node/request.rb +6 -1
  29. data/lib/cloud_sesame/query/node/return.rb +21 -0
  30. data/spec/cloud_sesame/query/ast/multi_branch_spec.rb +1 -1
  31. data/spec/cloud_sesame/query/ast/multi_expression_operator_spec.rb +0 -4
  32. data/spec/cloud_sesame/query/dsl/filter_query_spec.rb +6 -56
  33. data/spec/cloud_sesame/query/node/request_spec.rb +2 -2
  34. data/spec/cloud_sesame_spec.rb +22 -7
  35. metadata +8 -3
  36. data/lib/cloud_sesame/query/dsl/literal_helper.rb +0 -17
  37. data/lib/cloud_sesame/query/dsl/range.rb +0 -41
@@ -55,7 +55,7 @@ module CloudSesame
55
55
 
56
56
  describe 'Query DSL' do
57
57
  it 'should be included' do
58
- expect(node).to respond_to(:and, :or, :literal)
58
+ expect(node).to respond_to(:and, :or)
59
59
  end
60
60
  end
61
61
 
@@ -9,10 +9,6 @@ module CloudSesame
9
9
  before { MultiExpressionOperator.symbol = :symbol }
10
10
 
11
11
  describe '#compile' do
12
- it 'should raise an error if operator symbol has not being set' do
13
- MultiExpressionOperator.symbol = nil
14
- expect{ operator.compile }.to raise_error(Error::MissingOperatorSymbol)
15
- end
16
12
 
17
13
  it 'should return nil if children are empty' do
18
14
  expect(operator.compile).to eq(nil)
@@ -9,7 +9,7 @@ module CloudSesame
9
9
  def initialize
10
10
  end
11
11
  def children
12
- @children ||= AST::CompoundArray.new.set_scope(self)
12
+ @children ||= AST::CompoundArray.new.scope_to self
13
13
  end
14
14
  def context
15
15
  @context ||= {}
@@ -46,73 +46,24 @@ module CloudSesame
46
46
  end
47
47
  end
48
48
 
49
- describe 'literal' do
50
-
51
- it 'should create a literal node' do
52
- expect(AST::Literal).to receive(:new).with('description', '123', Hash)
53
- subject.literal('description', '123')
54
- end
55
- it 'should add the literal node to it\'s children' do
56
- expect{ subject.literal('description', '123') }.to change{ subject.children.size }.by(1)
57
- end
58
- it 'should return the literal node' do
59
- expect(subject.literal('description', '123')).to be_kind_of(AST::Literal)
60
- end
61
-
62
- context 'when field is define in context' do
63
- before { subject.context[:fields] = { description: {} } }
64
- # it 'should be triggered by calling the field name as a method' do
65
- # expect(subject).to receive(:literal).with(:description, '123', {})
66
- # subject.description "123"
67
- # end
68
- # it 'should accept multiple values' do
69
- # expect(subject).to receive(:literal).exactly(3).times
70
- # subject.description "123", "456", "789"
71
- # end
72
-
73
- it 'should return literal nodes in an array' do
74
- result = subject.description("123", "456", "789")
75
- expect(result).to include(AST::Literal)
76
- end
77
- end
78
-
79
- context 'when field is not defined' do
80
- it 'should raise method missing error when calling the field name as a method' do
81
- expect{ subject.not_defined() }.to raise_error(NoMethodError)
82
- end
83
- end
84
- end
85
-
86
- # describe 'prefix' do
87
- # it 'should set the literal prefix option to true' do
88
- # literals = (1..3).map { |i| AST::Literal.new(:int, i) }
89
- # subject.prefix(literals)
90
-
91
- # literals.each do |literal|
92
- # expect(literal.options).to include(prefix: true)
93
- # end
94
-
95
- # end
96
- # end
97
-
98
49
  describe 'included?' do
99
50
  before { subject.context[:fields] = { tags: {}, description: {} } }
100
51
  context 'when there is a field and no value' do
101
52
  it 'should return true if the request contains the field in the filter query' do
102
- subject.and{tags('women')}
53
+ subject.and { tags 'women' }
103
54
  expect(subject.included?(:tags)).to be_truthy
104
55
  end
105
56
 
106
57
  it 'should return false if the request does not contain the field in the filter query' do
107
- subject.and{tags.not('women')}
58
+ subject.and { tags.not 'women' }
108
59
  expect(subject.included?(:tags)).to be_falsey
109
60
  end
110
61
 
111
62
  end
112
63
  context 'when there is a field and a value' do
113
64
  it 'should return true if the request contains the field and the value in the filter query' do
114
- subject.and{tags('women')}
115
- expect(subject.included?(:tags, 'women')).to be_truthy
65
+ subject.and { tags("women") }
66
+ expect(subject.included?(:tags, "women")).to be_truthy
116
67
  end
117
68
 
118
69
  it 'should return false if the request does not contain the field or the value in the filter query' do
@@ -123,12 +74,11 @@ module CloudSesame
123
74
  end
124
75
  end
125
76
 
126
-
127
77
  describe 'excluded?' do
128
78
  before { subject.context[:fields] = { tags: {}, description: {} } }
129
79
  context 'when there is a field and no value' do
130
80
  it 'should return true if the request excludes the field in the filter query' do
131
- subject.and{tags('women')}
81
+ subject.and { tags 'women' }
132
82
  expect(subject.excluded?(:tags)).to be_falsey
133
83
  end
134
84
 
@@ -4,7 +4,7 @@ module CloudSesame
4
4
  module Query
5
5
  module Node
6
6
  describe Request do
7
- let(:context) { Domain::Context.new }
7
+ let(:context) { Domain::Context.new(filter_query: { fields: { tags: {} } }) }
8
8
  let(:request) { Request.new(context) }
9
9
 
10
10
  describe '#compile' do
@@ -38,7 +38,7 @@ module CloudSesame
38
38
  end
39
39
  end
40
40
  context 'when theres filter query' do
41
- before { request.filter_query.root.and{ literal(:tags, "sale") } }
41
+ before { request.filter_query.root.and { tags "sale" } }
42
42
  let(:compiled) { request.filter_query.compile }
43
43
  context 'with query' do
44
44
  before { request.query.query = "hello" }
@@ -9,6 +9,8 @@ describe CloudSesame do
9
9
  # end
10
10
 
11
11
  # # Domain Initializer /config/initializers/cloudsearch.rb
12
+ # require 'cloud_sesame'
13
+
12
14
  # CloudSesame::Domain::Client.configure do |config|
13
15
  # config.access_key = ENV['AWS_ACCESS_KEY_ID']
14
16
  # config.secret_key = ENV['AWS_SECRET_ACCESS_KEY']
@@ -24,6 +26,13 @@ describe CloudSesame do
24
26
  # config.region = ENV['AWS_REGION']
25
27
 
26
28
  # default_size 100
29
+
30
+ # # describe_fuzziness do
31
+ # # max_fuzziness 3
32
+ # # min_word_length 6
33
+ # # fuzzy_percentage 0.17
34
+ # # end
35
+
27
36
  # field :searchable_text, query: { weight: 2 }
28
37
  # field :description, query: true
29
38
  # field :tags
@@ -36,8 +45,11 @@ describe CloudSesame do
36
45
  # field :category_string, facet: { sort: 'bucket', size: 10_000 }
37
46
  # field :created_at
38
47
 
39
- # scope :men_tag, -> { tags "men" }
40
- # scope :and_mens, -> { and! { tags "men"} }
48
+ # scope :men_tag, ->(date) { created_at date }
49
+ # scope :and_mens do
50
+ # and! { tags "men"}
51
+ # end
52
+ # scope :men_stuff, -> { query("men").sort().page }
41
53
 
42
54
  # end
43
55
 
@@ -48,14 +60,17 @@ describe CloudSesame do
48
60
 
49
61
  # define_cloudsearch do
50
62
  # field :searchable_text, query: { weight: 4 }
63
+ # field :name, as: :text1
51
64
  # end
52
65
  # end
66
+
67
+
68
+
69
+
53
70
  # # Example Query
54
- # result = Product.cloudsearch.query("shoes")
55
- # .or {
56
- # created_at "[#{ d(Date.today - 3) },}"
57
- # created_at r.gte(d(Date.today - 3))
58
- # }
71
+ # query = Product.cloudsearch.query("nike pants").create_at(Date.today)
72
+
73
+
59
74
  # binding.pry
60
75
 
61
76
  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.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chu
@@ -98,6 +98,7 @@ files:
98
98
  - Gemfile
99
99
  - Gemfile.lock
100
100
  - Guardfile
101
+ - README.md
101
102
  - cloud_sesame.gemspec
102
103
  - lib/abstract_object.rb
103
104
  - lib/cloud_sesame.rb
@@ -116,24 +117,27 @@ files:
116
117
  - lib/cloud_sesame/query/ast/near.rb
117
118
  - lib/cloud_sesame/query/ast/not.rb
118
119
  - lib/cloud_sesame/query/ast/or.rb
120
+ - lib/cloud_sesame/query/ast/phrase.rb
119
121
  - lib/cloud_sesame/query/ast/prefix.rb
120
122
  - lib/cloud_sesame/query/ast/range_value.rb
121
123
  - lib/cloud_sesame/query/ast/root.rb
122
124
  - lib/cloud_sesame/query/ast/single_branch.rb
123
125
  - lib/cloud_sesame/query/ast/single_expression_operator.rb
126
+ - lib/cloud_sesame/query/ast/term.rb
124
127
  - lib/cloud_sesame/query/ast/value.rb
125
128
  - lib/cloud_sesame/query/builder.rb
126
129
  - lib/cloud_sesame/query/dsl/and.rb
127
130
  - lib/cloud_sesame/query/dsl/base.rb
131
+ - lib/cloud_sesame/query/dsl/boost.rb
128
132
  - lib/cloud_sesame/query/dsl/filter_query.rb
129
133
  - lib/cloud_sesame/query/dsl/literal.rb
130
- - lib/cloud_sesame/query/dsl/literal_helper.rb
131
134
  - lib/cloud_sesame/query/dsl/or.rb
132
135
  - lib/cloud_sesame/query/dsl/page.rb
133
136
  - lib/cloud_sesame/query/dsl/query.rb
134
- - lib/cloud_sesame/query/dsl/range.rb
137
+ - lib/cloud_sesame/query/dsl/return.rb
135
138
  - lib/cloud_sesame/query/dsl/scope.rb
136
139
  - lib/cloud_sesame/query/dsl/sort.rb
140
+ - lib/cloud_sesame/query/dsl/value.rb
137
141
  - lib/cloud_sesame/query/error/missing_operator_symbol.rb
138
142
  - lib/cloud_sesame/query/error/missing_query.rb
139
143
  - lib/cloud_sesame/query/node/abstract.rb
@@ -145,6 +149,7 @@ files:
145
149
  - lib/cloud_sesame/query/node/query_options_field.rb
146
150
  - lib/cloud_sesame/query/node/query_parser.rb
147
151
  - lib/cloud_sesame/query/node/request.rb
152
+ - lib/cloud_sesame/query/node/return.rb
148
153
  - lib/cloud_sesame/query/node/sort.rb
149
154
  - spec/abstract_object_spec.rb
150
155
  - spec/cloud_sesame/domain/base_spec.rb
@@ -1,17 +0,0 @@
1
- module CloudSesame
2
- module Query
3
- module DSL
4
- module LiteralHelper
5
-
6
- def d(date)
7
- AST::DateValue.new date
8
- end
9
-
10
- def r
11
- AST::RangeValue.new
12
- end
13
-
14
- end
15
- end
16
- end
17
- end
@@ -1,41 +0,0 @@
1
- module CloudSesame
2
- module Query
3
- module DSL
4
- module Range
5
-
6
- def >(value)
7
- return self
8
- end
9
-
10
- def >=(value)
11
- return self
12
- end
13
-
14
- def <(value)
15
- return self
16
- end
17
-
18
- def <=(value)
19
- return self
20
- end
21
-
22
- def gt(value)
23
- return self
24
- end
25
-
26
- def gte(value)
27
- return self
28
- end
29
-
30
- def lt(value)
31
- return self
32
- end
33
-
34
- def lte(value)
35
- return self
36
- end
37
-
38
- end
39
- end
40
- end
41
- end