CloudSesame 0.1.4 → 0.1.5
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 +2 -0
- data/lib/cloud_sesame/query/ast/date_value.rb +21 -0
- data/lib/cloud_sesame/query/ast/literal.rb +4 -3
- data/lib/cloud_sesame/query/ast/range_value.rb +78 -0
- data/lib/cloud_sesame/query/ast/value.rb +4 -1
- data/lib/cloud_sesame/query/dsl/literal_helper.rb +4 -4
- data/spec/cloud_sesame_spec.rb +5 -7
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7aad854d12632f7a254e4d4130381ecf2c1e468
|
4
|
+
data.tar.gz: d150f9b6a91d47da8fd83df34b967c78507221bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a2374d616b59d412dcc228f51343ce56e0d9686ffc322f272a7ded656976ffeaab5492cd83547feec36619279bea6a97d094f66b8377692f3e509f89122ce2b
|
7
|
+
data.tar.gz: 816abf070d875a9d1d2df1e54bd0b1aa23618d09c1bcbf0d4e067c6abb6170667c8889b649066bd5fbe3d1aa4be712ce5251bfc73562fdd9a0f5c4ccac1f2ceb
|
data/Gemfile.lock
CHANGED
data/cloud_sesame.gemspec
CHANGED
data/lib/cloud_sesame.rb
CHANGED
@@ -43,6 +43,8 @@ require 'cloud_sesame/query/ast/prefix'
|
|
43
43
|
require 'cloud_sesame/query/ast/compound_array'
|
44
44
|
require 'cloud_sesame/query/ast/literal'
|
45
45
|
require 'cloud_sesame/query/ast/value'
|
46
|
+
require 'cloud_sesame/query/ast/date_value'
|
47
|
+
require 'cloud_sesame/query/ast/range_value'
|
46
48
|
|
47
49
|
# Query Request Nodes
|
48
50
|
# ===============================================
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module CloudSesame
|
2
|
+
module Query
|
3
|
+
module AST
|
4
|
+
class DateValue < Value
|
5
|
+
|
6
|
+
def initialize(data)
|
7
|
+
@data = data
|
8
|
+
end
|
9
|
+
|
10
|
+
def compile
|
11
|
+
strip escape @data.strftime('%FT%TZ')
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
compile
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -7,8 +7,9 @@ module CloudSesame
|
|
7
7
|
attr_reader :value, :options
|
8
8
|
|
9
9
|
def initialize(field, value, options = {})
|
10
|
-
|
11
|
-
|
10
|
+
self.field = field
|
11
|
+
self.value = value
|
12
|
+
|
12
13
|
@options = options
|
13
14
|
(options[:included] ||= []) << value
|
14
15
|
end
|
@@ -19,7 +20,7 @@ module CloudSesame
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def value=(value)
|
22
|
-
@value = Value.new(value)
|
23
|
+
@value = value.kind_of?(Value) ? value : Value.new(value)
|
23
24
|
end
|
24
25
|
|
25
26
|
def compile
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module CloudSesame
|
2
|
+
module Query
|
3
|
+
module AST
|
4
|
+
class RangeValue < Value
|
5
|
+
|
6
|
+
attr_accessor :lower_bound_included,
|
7
|
+
:upper_bound_included
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@data = [nil, nil]
|
11
|
+
end
|
12
|
+
|
13
|
+
def compile
|
14
|
+
strip "#{ lower_bound }#{ lower.compile if lower },#{ upper.compile if upper }#{ upper_bound }"
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
compile
|
19
|
+
end
|
20
|
+
|
21
|
+
def gt(value)
|
22
|
+
self.lower = value
|
23
|
+
self.lower_bound_included = false
|
24
|
+
return self
|
25
|
+
end
|
26
|
+
|
27
|
+
def gte(value)
|
28
|
+
self.lower = value
|
29
|
+
self.lower_bound_included = true
|
30
|
+
return self
|
31
|
+
end
|
32
|
+
|
33
|
+
def lt(value)
|
34
|
+
self.upper = value
|
35
|
+
self.upper_bound_included = false
|
36
|
+
return self
|
37
|
+
end
|
38
|
+
|
39
|
+
def lte(value)
|
40
|
+
self.upper = value
|
41
|
+
self.upper_bound_included = true
|
42
|
+
return self
|
43
|
+
end
|
44
|
+
|
45
|
+
def lower
|
46
|
+
data[0]
|
47
|
+
end
|
48
|
+
|
49
|
+
def lower=(value)
|
50
|
+
data[0] = to_value(value)
|
51
|
+
end
|
52
|
+
|
53
|
+
def upper
|
54
|
+
data[1]
|
55
|
+
end
|
56
|
+
|
57
|
+
def upper=(value)
|
58
|
+
data[1] = to_value(value)
|
59
|
+
end
|
60
|
+
|
61
|
+
def lower_bound
|
62
|
+
lower && lower_bound_included ? '[' : '{'
|
63
|
+
end
|
64
|
+
|
65
|
+
def upper_bound
|
66
|
+
upper && upper_bound_included ? ']' : '}'
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def to_value(value)
|
72
|
+
value.kind_of?(Value) ? value : Value.new(value)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -3,12 +3,12 @@ module CloudSesame
|
|
3
3
|
module DSL
|
4
4
|
module LiteralHelper
|
5
5
|
|
6
|
-
def d(
|
7
|
-
|
6
|
+
def d(date)
|
7
|
+
AST::DateValue.new date
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
10
|
+
def r
|
11
|
+
AST::RangeValue.new
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
data/spec/cloud_sesame_spec.rb
CHANGED
@@ -50,14 +50,12 @@ describe CloudSesame do
|
|
50
50
|
# field :searchable_text, query: { weight: 4 }
|
51
51
|
# end
|
52
52
|
# end
|
53
|
-
|
54
53
|
# # Example Query
|
55
|
-
#
|
56
|
-
#
|
57
|
-
# # .
|
58
|
-
#
|
59
|
-
#
|
60
|
-
|
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
|
+
# }
|
61
59
|
# binding.pry
|
62
60
|
|
63
61
|
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.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Chu
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- lib/cloud_sesame/domain/context.rb
|
109
109
|
- lib/cloud_sesame/query/ast/and.rb
|
110
110
|
- lib/cloud_sesame/query/ast/compound_array.rb
|
111
|
+
- lib/cloud_sesame/query/ast/date_value.rb
|
111
112
|
- lib/cloud_sesame/query/ast/leaf.rb
|
112
113
|
- lib/cloud_sesame/query/ast/literal.rb
|
113
114
|
- lib/cloud_sesame/query/ast/multi_branch.rb
|
@@ -116,6 +117,7 @@ files:
|
|
116
117
|
- lib/cloud_sesame/query/ast/not.rb
|
117
118
|
- lib/cloud_sesame/query/ast/or.rb
|
118
119
|
- lib/cloud_sesame/query/ast/prefix.rb
|
120
|
+
- lib/cloud_sesame/query/ast/range_value.rb
|
119
121
|
- lib/cloud_sesame/query/ast/root.rb
|
120
122
|
- lib/cloud_sesame/query/ast/single_branch.rb
|
121
123
|
- lib/cloud_sesame/query/ast/single_expression_operator.rb
|