CloudSesame 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +8 -6
- data/cloud_sesame.gemspec +3 -2
- data/lib/cloud_sesame/domain/base.rb +12 -5
- data/lib/cloud_sesame/query/ast/literal.rb +22 -10
- data/lib/cloud_sesame/query/ast/multi_expression_operator.rb +1 -1
- data/lib/cloud_sesame/query/ast/near.rb +1 -1
- data/lib/cloud_sesame/query/ast/not.rb +1 -1
- data/lib/cloud_sesame/query/ast/numeric_value.rb +13 -0
- data/lib/cloud_sesame/query/ast/operator.rb +4 -0
- data/lib/cloud_sesame/query/ast/phrase.rb +1 -1
- data/lib/cloud_sesame/query/ast/range_value.rb +35 -13
- data/lib/cloud_sesame/query/ast/root.rb +8 -0
- data/lib/cloud_sesame/query/ast/single_expression_operator.rb +5 -1
- data/lib/cloud_sesame/query/ast/value.rb +22 -11
- data/lib/cloud_sesame/query/dsl/field_methods.rb +10 -6
- data/lib/cloud_sesame/query/dsl/page_methods.rb +10 -6
- data/lib/cloud_sesame/query/node/filter_query.rb +1 -14
- data/lib/cloud_sesame.rb +6 -6
- data/profiler.rb +91 -0
- data/spec/cloud_sesame_spec.rb +105 -100
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1ab042a61e9108d439ecddd4bdf5a2b5548aa8f
|
4
|
+
data.tar.gz: 8b3015719e50ade4f074fb471cac15cc8abe11f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32f17eacc19c2ddb90270fe09f5e2c7c8eb0174633f269dba9fc38d1bad259362a86000b40a845cc26d4cea2b768ebafba015c66c6d83361009b308b6c5bb272
|
7
|
+
data.tar.gz: 2d496df6ccdc7fd728aadd58ad6fc1233d98ace2a4924026462bd7f8372116f046cbccce2137b6ac139022b829301f3534945997624f0e1b016394881cf193b6
|
data/Gemfile.lock
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
CloudSesame (0.
|
4
|
+
CloudSesame (0.3.0)
|
5
5
|
aws-sdk (~> 2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
aws-sdk (2.2.
|
11
|
-
aws-sdk-resources (= 2.2.
|
12
|
-
aws-sdk-core (2.2.
|
10
|
+
aws-sdk (2.2.12)
|
11
|
+
aws-sdk-resources (= 2.2.12)
|
12
|
+
aws-sdk-core (2.2.12)
|
13
13
|
jmespath (~> 1.0)
|
14
|
-
aws-sdk-resources (2.2.
|
15
|
-
aws-sdk-core (= 2.2.
|
14
|
+
aws-sdk-resources (2.2.12)
|
15
|
+
aws-sdk-core (= 2.2.12)
|
16
16
|
coderay (1.1.0)
|
17
17
|
diff-lcs (1.2.5)
|
18
18
|
ffi (1.9.10)
|
@@ -61,6 +61,7 @@ GEM
|
|
61
61
|
diff-lcs (>= 1.2.0, < 2.0)
|
62
62
|
rspec-support (~> 3.4.0)
|
63
63
|
rspec-support (3.4.1)
|
64
|
+
ruby-prof (0.15.9)
|
64
65
|
shellany (0.0.1)
|
65
66
|
slop (3.6.0)
|
66
67
|
thor (0.19.1)
|
@@ -74,3 +75,4 @@ DEPENDENCIES
|
|
74
75
|
guard-rspec
|
75
76
|
pry (~> 0)
|
76
77
|
rspec (~> 3)
|
78
|
+
ruby-prof
|
data/cloud_sesame.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'CloudSesame'
|
3
|
-
s.version = '0.
|
4
|
-
s.date = '2016-01-
|
3
|
+
s.version = '0.3.0'
|
4
|
+
s.date = '2016-01-20'
|
5
5
|
s.summary = "AWS CloudSearch Query DSL"
|
6
6
|
s.description = "AWS CloudSearch Query DSL"
|
7
7
|
s.authors = ['Scott Chu', 'Emily Fan', 'Greg Ward', 'David McHoull',
|
@@ -22,4 +22,5 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_development_dependency 'pry', '~> 0'
|
23
23
|
s.add_development_dependency 'guard'
|
24
24
|
s.add_development_dependency 'guard-rspec'
|
25
|
+
s.add_development_dependency 'ruby-prof'
|
25
26
|
end
|
@@ -29,10 +29,10 @@ module CloudSesame
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def field(name, options = {})
|
32
|
-
field_name = options[:as] || name
|
32
|
+
field_name = (options[:as] || name).to_sym
|
33
33
|
define_query_options(field_name, options.delete(:query)) if options[:query]
|
34
34
|
define_facet_options(field_name, options.delete(:facet)) if options[:facet]
|
35
|
-
define_filter_query_field(name, options)
|
35
|
+
define_filter_query_field(name.to_sym, options)
|
36
36
|
end
|
37
37
|
|
38
38
|
def define_sloppiness(value)
|
@@ -63,15 +63,22 @@ module CloudSesame
|
|
63
63
|
if (as = options[:as]) && (existing_options = context[:filter_query, true][:fields, true].delete(as))
|
64
64
|
options.merge!(existing_options)
|
65
65
|
end
|
66
|
-
|
66
|
+
if (block = options[:default])
|
67
|
+
filter_query_defaults << Query::AST::Literal.new(name, nil, options, &block)
|
68
|
+
end
|
69
|
+
context[:filter_query, true][:fields, true][name] = options
|
67
70
|
end
|
68
71
|
|
69
72
|
def define_query_options(name, options)
|
70
|
-
context[:query_options, true][:fields, true][name
|
73
|
+
context[:query_options, true][:fields, true][name] = format_options(options)
|
71
74
|
end
|
72
75
|
|
73
76
|
def define_facet_options(name, options)
|
74
|
-
context[:facet, true][name
|
77
|
+
context[:facet, true][name] = format_options(options)
|
78
|
+
end
|
79
|
+
|
80
|
+
def filter_query_defaults
|
81
|
+
context[:filter_query, true][:defaults] ||= []
|
75
82
|
end
|
76
83
|
|
77
84
|
end
|
@@ -3,12 +3,18 @@ module CloudSesame
|
|
3
3
|
module AST
|
4
4
|
class Literal
|
5
5
|
|
6
|
+
SINGLE_QUATE = /\'/
|
7
|
+
ESCAPE_QUATE = "\\'"
|
8
|
+
|
6
9
|
attr_accessor :field
|
7
10
|
attr_reader :options, :value
|
8
11
|
|
9
12
|
def initialize(field = nil, value = nil, options = {}, &block)
|
10
13
|
@field = field
|
11
|
-
|
14
|
+
|
15
|
+
@value = Value.parse value if value
|
16
|
+
@value = Value.parse ValueEvaluator.new.instance_exec &block if block_given?
|
17
|
+
|
12
18
|
@options = options || {}
|
13
19
|
(@options[:included] ||= []) << @value
|
14
20
|
end
|
@@ -24,20 +30,22 @@ module CloudSesame
|
|
24
30
|
end
|
25
31
|
|
26
32
|
def as_field
|
27
|
-
options[:as] || field
|
33
|
+
@as_field ||= (options[:as] || field).to_s
|
28
34
|
end
|
29
35
|
|
30
36
|
def compile(detailed = false)
|
31
|
-
|
37
|
+
updated? ? recompile(detailed) : @compiled
|
32
38
|
end
|
33
39
|
|
34
40
|
private
|
35
41
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
42
|
+
def updated?
|
43
|
+
@compiled_value != value
|
44
|
+
end
|
45
|
+
|
46
|
+
def recompile(detailed)
|
47
|
+
@compiled_value = value
|
48
|
+
@compiled = detailed ? detailed_format : standard_format
|
41
49
|
end
|
42
50
|
|
43
51
|
def standard_format
|
@@ -48,8 +56,12 @@ module CloudSesame
|
|
48
56
|
"field=#{ escape as_field } #{ value.compile }"
|
49
57
|
end
|
50
58
|
|
51
|
-
def escape(data
|
52
|
-
"'#{ data.
|
59
|
+
def escape(data)
|
60
|
+
"'#{ data.gsub(SINGLE_QUATE) { ESCAPE_QUATE } }'"
|
61
|
+
end
|
62
|
+
|
63
|
+
class ValueEvaluator
|
64
|
+
include DSL::RangeMethods
|
53
65
|
end
|
54
66
|
|
55
67
|
end
|
@@ -3,48 +3,70 @@ module CloudSesame
|
|
3
3
|
module AST
|
4
4
|
class RangeValue < Value
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
STRING_FORMAT = /\A(\[|{)(.*),(.*)(\}|\])\z/
|
7
|
+
|
8
|
+
def initialize(value = nil)
|
9
|
+
@data = if value.kind_of?(Range)
|
10
|
+
range_to_array(value)
|
11
|
+
elsif value.is_a?(String) && (match = STRING_FORMAT.match value)
|
12
|
+
@data = match.captures
|
13
|
+
else
|
14
|
+
default_range
|
15
|
+
end
|
8
16
|
end
|
9
17
|
|
10
18
|
def compile
|
11
|
-
"#{ lb }#{
|
19
|
+
"#{ lb }#{ l.to_s },#{ u.to_s }#{ ub }"
|
12
20
|
end
|
13
21
|
|
14
22
|
def gt(value = nil)
|
15
|
-
data[0], data[1] =
|
23
|
+
data[0], data[1] = '{', Value.parse(value) if value
|
16
24
|
return self
|
17
25
|
end
|
18
26
|
|
19
27
|
def gte(value = nil)
|
20
|
-
data[0], data[1] =
|
28
|
+
data[0], data[1] = '[', Value.parse(value) if value
|
21
29
|
return self
|
22
30
|
end
|
23
31
|
|
24
32
|
def lt(value = nil)
|
25
|
-
data[2], data[3] =
|
33
|
+
data[2], data[3] = Value.parse(value), '}' if value
|
26
34
|
return self
|
27
35
|
end
|
28
36
|
|
29
37
|
def lte(value = nil)
|
30
|
-
data[2], data[3] =
|
38
|
+
data[2], data[3] = Value.parse(value), ']' if value
|
31
39
|
return self
|
32
40
|
end
|
33
41
|
|
42
|
+
def l
|
43
|
+
data[1]
|
44
|
+
end
|
45
|
+
|
46
|
+
def u
|
47
|
+
data[2]
|
48
|
+
end
|
49
|
+
|
34
50
|
private
|
35
51
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
52
|
+
def range_to_array(r)
|
53
|
+
['[', r.begin, r.end, end_symbol(r)]
|
54
|
+
end
|
55
|
+
|
56
|
+
def end_symbol(value)
|
57
|
+
value.exclude_end? ? '}' : ']'
|
58
|
+
end
|
59
|
+
|
60
|
+
def default_range
|
61
|
+
['{', nil, nil, '}']
|
40
62
|
end
|
41
63
|
|
42
64
|
def lb
|
43
|
-
data[1]
|
65
|
+
data[1] ? data[0] : '{'
|
44
66
|
end
|
45
67
|
|
46
68
|
def ub
|
47
|
-
data[2]
|
69
|
+
data[2] ? data[3] : '}'
|
48
70
|
end
|
49
71
|
|
50
72
|
end
|
@@ -22,7 +22,11 @@ module CloudSesame
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def compile
|
25
|
-
"(#{
|
25
|
+
"(#{ symbol }#{ boost } #{ child.compile detailed })" if child
|
26
|
+
end
|
27
|
+
|
28
|
+
def detailed
|
29
|
+
self.class::DETAILED
|
26
30
|
end
|
27
31
|
|
28
32
|
end
|
@@ -3,14 +3,28 @@ module CloudSesame
|
|
3
3
|
module AST
|
4
4
|
class Value
|
5
5
|
|
6
|
+
RANGE_FORMAT = /\A[\[\{].*[\]\}]\z/
|
7
|
+
DIGIT_FORMAT = /\A\d+(.\d+)?\z/
|
8
|
+
SINGLE_QUATE = /\'/
|
9
|
+
ESCAPE_QUATE = "\\'"
|
10
|
+
|
6
11
|
attr_reader :data
|
7
12
|
|
13
|
+
def self.parse(value)
|
14
|
+
return value if value.kind_of? AST::Value
|
15
|
+
return AST::DateValue.new(value) if value.kind_of?(Date) || value.kind_of?(Time)
|
16
|
+
return AST::RangeValue.new(value) if value.kind_of?(Range) || (value.is_a?(String) && RANGE_FORMAT =~ value)
|
17
|
+
return AST::NumericValue.new(value) if value.is_a?(Numeric) || (value.is_a?(String) && DIGIT_FORMAT =~ value)
|
18
|
+
AST::Value.new(value)
|
19
|
+
end
|
20
|
+
|
8
21
|
def initialize(data)
|
9
22
|
@data = data
|
23
|
+
@compiled = compile
|
10
24
|
end
|
11
25
|
|
12
26
|
def compile
|
13
|
-
|
27
|
+
updated? ? recompile : @compiled
|
14
28
|
end
|
15
29
|
|
16
30
|
def to_s
|
@@ -23,24 +37,21 @@ module CloudSesame
|
|
23
37
|
|
24
38
|
private
|
25
39
|
|
26
|
-
def
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
def range?(data)
|
31
|
-
data =~ /^[\[\{].*[\]\}]$/
|
40
|
+
def updated?
|
41
|
+
@compiled_data != @data
|
32
42
|
end
|
33
43
|
|
34
|
-
def
|
35
|
-
|
44
|
+
def recompile
|
45
|
+
@compiled_data = @data
|
46
|
+
@compiled = escape @compiled_data
|
36
47
|
end
|
37
48
|
|
38
49
|
def escape(data = "")
|
39
|
-
"'#{ data.
|
50
|
+
"'#{ data.gsub(SINGLE_QUATE) { ESCAPE_QUATE } }'"
|
40
51
|
end
|
41
52
|
|
42
53
|
def strip(string)
|
43
|
-
string.
|
54
|
+
string.tr(" ", "")
|
44
55
|
end
|
45
56
|
|
46
57
|
end
|
@@ -3,18 +3,22 @@ module CloudSesame
|
|
3
3
|
module DSL
|
4
4
|
module FieldMethods
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
if (fields = dsl_context[:fields]) && fields[field]
|
10
|
-
dsl_scope.children.field = field
|
6
|
+
def literal(name, *values)
|
7
|
+
if (fields = dsl_context[:fields]) && fields[name]
|
8
|
+
dsl_scope.children.field = name
|
11
9
|
dsl_scope.children.dsl_return = dsl_return
|
12
10
|
dsl_scope.children.insert values
|
13
11
|
else
|
14
|
-
|
12
|
+
false
|
15
13
|
end
|
16
14
|
end
|
17
15
|
|
16
|
+
private
|
17
|
+
|
18
|
+
def method_missing(name, *values, &block)
|
19
|
+
(result = literal(name, *values)) ? result : super
|
20
|
+
end
|
21
|
+
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
@@ -5,18 +5,18 @@ module CloudSesame
|
|
5
5
|
|
6
6
|
# CLAUSE: PAGE and SIZE
|
7
7
|
# =========================================
|
8
|
-
def page(input =
|
9
|
-
if input
|
8
|
+
def page(input = false)
|
9
|
+
if input || input.nil?
|
10
10
|
request.page.start = nil
|
11
|
-
request.page.page = input.to_i
|
11
|
+
request.page.page = (input || 1).to_i
|
12
12
|
return self
|
13
13
|
else
|
14
14
|
request.page.page
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def start(input =
|
19
|
-
if input
|
18
|
+
def start(input = false)
|
19
|
+
if input || input.nil?
|
20
20
|
request.page.page = nil
|
21
21
|
request.page.start = input.to_i
|
22
22
|
return self
|
@@ -25,10 +25,14 @@ module CloudSesame
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
alias_method :offset, :start
|
29
|
+
|
30
|
+
def size(input = false)
|
29
31
|
if input
|
30
32
|
request.page.size = input.to_i
|
31
33
|
return self
|
34
|
+
elsif input.nil?
|
35
|
+
return self
|
32
36
|
else
|
33
37
|
request.page.size
|
34
38
|
end
|
@@ -8,20 +8,7 @@ module CloudSesame
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def root
|
11
|
-
@root ||=
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def create_root_with_default_values
|
17
|
-
root = CloudSesame::Query::AST::Root.new context
|
18
|
-
context[:fields].each do |field, options|
|
19
|
-
if options && (block = options[:default])
|
20
|
-
value = root.instance_exec &block
|
21
|
-
root << AST::Literal.new(field, value, options)
|
22
|
-
end
|
23
|
-
end if context[:fields]
|
24
|
-
root
|
11
|
+
@root ||= CloudSesame::Query::AST::Root.new context
|
25
12
|
end
|
26
13
|
|
27
14
|
end
|
data/lib/cloud_sesame.rb
CHANGED
@@ -17,19 +17,18 @@ require 'cloud_sesame/query/error/missing_query'
|
|
17
17
|
# Query DSL Methods
|
18
18
|
# ===============================================
|
19
19
|
require 'cloud_sesame/query/dsl/base'
|
20
|
-
require 'cloud_sesame/query/dsl/query_methods'
|
21
|
-
require 'cloud_sesame/query/dsl/page_methods'
|
22
|
-
require 'cloud_sesame/query/dsl/sort_methods'
|
23
|
-
require 'cloud_sesame/query/dsl/return_methods'
|
24
|
-
|
25
20
|
require 'cloud_sesame/query/dsl/block_methods'
|
26
21
|
require 'cloud_sesame/query/dsl/block_chaining_methods'
|
27
|
-
require 'cloud_sesame/query/dsl/field_methods'
|
28
22
|
require 'cloud_sesame/query/dsl/field_array_methods'
|
23
|
+
require 'cloud_sesame/query/dsl/field_methods'
|
29
24
|
require 'cloud_sesame/query/dsl/filter_query_methods'
|
30
25
|
require 'cloud_sesame/query/dsl/operator_methods'
|
26
|
+
require 'cloud_sesame/query/dsl/page_methods'
|
27
|
+
require 'cloud_sesame/query/dsl/query_methods'
|
31
28
|
require 'cloud_sesame/query/dsl/range_methods'
|
29
|
+
require 'cloud_sesame/query/dsl/return_methods'
|
32
30
|
require 'cloud_sesame/query/dsl/scope_methods'
|
31
|
+
require 'cloud_sesame/query/dsl/sort_methods'
|
33
32
|
|
34
33
|
# Query Query Filter Query AST Tree
|
35
34
|
# ===============================================
|
@@ -48,6 +47,7 @@ require 'cloud_sesame/query/ast/term'
|
|
48
47
|
require 'cloud_sesame/query/ast/literal'
|
49
48
|
require 'cloud_sesame/query/ast/value'
|
50
49
|
require 'cloud_sesame/query/ast/date_value'
|
50
|
+
require 'cloud_sesame/query/ast/numeric_Value'
|
51
51
|
require 'cloud_sesame/query/ast/range_value'
|
52
52
|
require 'cloud_sesame/query/ast/root'
|
53
53
|
|
data/profiler.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'profile'
|
2
|
+
require 'yaml'
|
3
|
+
require_relative './cloud_sesame.rb'
|
4
|
+
|
5
|
+
# AWS initializer
|
6
|
+
# =======================================================
|
7
|
+
|
8
|
+
YAML.load_file('aws.yml').each do |key, value|
|
9
|
+
ENV["AWS_#{ key }"] = value
|
10
|
+
end
|
11
|
+
|
12
|
+
# Domain Initializer /config/initializers/cloudsearch.rb
|
13
|
+
# =======================================================
|
14
|
+
|
15
|
+
|
16
|
+
CloudSesame::Domain::Client.configure do |config|
|
17
|
+
config.access_key = ENV['AWS_ACCESS_KEY_ID']
|
18
|
+
config.secret_key = ENV['AWS_SECRET_ACCESS_KEY']
|
19
|
+
end
|
20
|
+
|
21
|
+
# Usage Example
|
22
|
+
# =======================================================
|
23
|
+
class Product
|
24
|
+
include CloudSesame
|
25
|
+
|
26
|
+
define_cloudsearch do
|
27
|
+
# Product CloudSesame Config
|
28
|
+
config.endpoint = ENV['AWS_ENDPOINT']
|
29
|
+
config.region = ENV['AWS_REGION']
|
30
|
+
|
31
|
+
default_size 100
|
32
|
+
|
33
|
+
define_sloppiness 3
|
34
|
+
|
35
|
+
define_fuzziness do
|
36
|
+
max_fuzziness 3
|
37
|
+
min_char_size 6
|
38
|
+
fuzzy_percent 0.17
|
39
|
+
end
|
40
|
+
|
41
|
+
field :searchable_text, query: { weight: 2 }
|
42
|
+
field :description, query: true
|
43
|
+
field :tags
|
44
|
+
|
45
|
+
field :affiliate_advertiser_ext_id, facet: { size: 50 }
|
46
|
+
field :currency, facet: true
|
47
|
+
field :discount_percentage, facet: { buckets: %w([10,100] [25,100] [50,100] [70,100]), method: 'interval' }
|
48
|
+
field :manufacturer_name, facet: { size: 50 }
|
49
|
+
field :price, facet: { buckets: %w([0,25] [25,50] [50,100] [100,200] [200,}), method: 'interval' }
|
50
|
+
field :category_string, facet: { sort: 'bucket', size: 10_000 }
|
51
|
+
field :created_at, default: -> { gt Date.today }
|
52
|
+
|
53
|
+
scope :shoes_by_brand, ->(brand = nil) { query("shoes").and { manufacturer_name brand } if brand }
|
54
|
+
scope :and_mens do
|
55
|
+
and! { tags "men"}
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
def query
|
63
|
+
query = Product.cloudsearch
|
64
|
+
.query("black jacket")
|
65
|
+
.sort(price: :asc)
|
66
|
+
.page(1)
|
67
|
+
.size(1000)
|
68
|
+
.or {
|
69
|
+
or! {
|
70
|
+
tags("men", "women")
|
71
|
+
}
|
72
|
+
tags.not start_with("automotive"), "home"
|
73
|
+
and! {
|
74
|
+
price gt(100).lt(500)
|
75
|
+
created_at gt(Date.today - 7)
|
76
|
+
currency "CAD", "USD"
|
77
|
+
}
|
78
|
+
|
79
|
+
}.or {
|
80
|
+
and! {
|
81
|
+
tags "outdoor"
|
82
|
+
price gt(200).lt(1000)
|
83
|
+
created_at gt(Date.today - 7)
|
84
|
+
currency "CAD", "USD"
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
query.compile
|
89
|
+
end
|
90
|
+
|
91
|
+
query
|
data/spec/cloud_sesame_spec.rb
CHANGED
@@ -1,100 +1,105 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
1
|
+
# require 'spec_helper'
|
2
|
+
# require 'ruby-prof'
|
3
|
+
# require 'benchmark'
|
4
|
+
|
5
|
+
# describe CloudSesame do
|
6
|
+
|
7
|
+
# # AWS initializer
|
8
|
+
# # =======================================================
|
9
|
+
# require 'yaml'
|
10
|
+
# YAML.load_file('aws.yml').each do |key, value|
|
11
|
+
# ENV["AWS_#{ key }"] = value
|
12
|
+
# end
|
13
|
+
|
14
|
+
# # Domain Initializer /config/initializers/cloudsearch.rb
|
15
|
+
# # =======================================================
|
16
|
+
# require 'cloud_sesame'
|
17
|
+
|
18
|
+
# CloudSesame::Domain::Client.configure do |config|
|
19
|
+
# config.access_key = ENV['AWS_ACCESS_KEY_ID']
|
20
|
+
# config.secret_key = ENV['AWS_SECRET_ACCESS_KEY']
|
21
|
+
# end
|
22
|
+
|
23
|
+
# # Usage Example
|
24
|
+
# # =======================================================
|
25
|
+
# class Product
|
26
|
+
# include CloudSesame
|
27
|
+
|
28
|
+
# define_cloudsearch do
|
29
|
+
# # Product CloudSesame Config
|
30
|
+
# config.endpoint = ENV['AWS_ENDPOINT']
|
31
|
+
# config.region = ENV['AWS_REGION']
|
32
|
+
|
33
|
+
# default_size 100
|
34
|
+
|
35
|
+
# define_sloppiness 3
|
36
|
+
|
37
|
+
# define_fuzziness do
|
38
|
+
# max_fuzziness 3
|
39
|
+
# min_char_size 6
|
40
|
+
# fuzzy_percent 0.17
|
41
|
+
# end
|
42
|
+
|
43
|
+
# field :searchable_text, query: { weight: 2 }
|
44
|
+
# field :description, query: true
|
45
|
+
# field :tags
|
46
|
+
|
47
|
+
# field :affiliate_advertiser_ext_id, facet: { size: 50 }
|
48
|
+
# field :currency, facet: true
|
49
|
+
# field :discount_percentage, facet: { buckets: %w([10,100] [25,100] [50,100] [70,100]), method: 'interval' }
|
50
|
+
# field :manufacturer_name, facet: { size: 50 }
|
51
|
+
# field :price, facet: { buckets: %w([0,25] [25,50] [50,100] [100,200] [200,}), method: 'interval' }
|
52
|
+
# field :category_string, facet: { sort: 'bucket', size: 10_000 }
|
53
|
+
# field :created_at, default: -> { gt Date.today }
|
54
|
+
|
55
|
+
# scope :shoes_by_brand, ->(brand = nil) { query("shoes").and { manufacturer_name brand } if brand }
|
56
|
+
# scope :and_mens do
|
57
|
+
# and! { tags "men"}
|
58
|
+
# end
|
59
|
+
|
60
|
+
# end
|
61
|
+
|
62
|
+
# end
|
63
|
+
|
64
|
+
|
65
|
+
# # n = 500
|
66
|
+
# # result = RubyProf.profile do
|
67
|
+
# # n.times do
|
68
|
+
# q = Product.cloudsearch.query("black jacket").sort(price: :asc).page(1).size(1000).and {
|
69
|
+
# or! {
|
70
|
+
# tags "men", "women"
|
71
|
+
# and! {
|
72
|
+
# tags.not "child", "home"
|
73
|
+
# }
|
74
|
+
# and!.not {
|
75
|
+
# tags.start_with "great", "nice"
|
76
|
+
# tags.not.start_with "super"
|
77
|
+
# tags.not.near "hello world"
|
78
|
+
# tags start_with("wifi"), near("electronic")
|
79
|
+
# tags term "cool"
|
80
|
+
# tags phrase "flash_deal"
|
81
|
+
# }
|
82
|
+
# or!.not {
|
83
|
+
# price 25..100
|
84
|
+
# price 100...200
|
85
|
+
# price gte(200).lt(300)
|
86
|
+
# price gte(300)
|
87
|
+
# }
|
88
|
+
# or! {
|
89
|
+
# created_at Date.today - 7
|
90
|
+
# created_at gte(Date.today)
|
91
|
+
# created_at gte(Date.today).lt(Date.today + 3)
|
92
|
+
# }
|
93
|
+
# }
|
94
|
+
# }.compile
|
95
|
+
|
96
|
+
# # end
|
97
|
+
# # end
|
98
|
+
# # printer = RubyProf::FlatPrinter.new(result)
|
99
|
+
# # printer.print(STDOUT, {})
|
100
|
+
|
101
|
+
# # q = Product.cloudsearch.and {
|
102
|
+
# binding.pry
|
103
|
+
# # }
|
104
|
+
|
105
|
+
# 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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Chu
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2016-01-
|
18
|
+
date: 2016-01-20 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: aws-sdk
|
@@ -87,6 +87,20 @@ dependencies:
|
|
87
87
|
- - '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
name: ruby-prof
|
92
|
+
requirement: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
type: :development
|
98
|
+
prerelease: false
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
90
104
|
description: AWS CloudSearch Query DSL
|
91
105
|
email: dev@retailcommon.com
|
92
106
|
executables: []
|
@@ -115,6 +129,7 @@ files:
|
|
115
129
|
- lib/cloud_sesame/query/ast/multi_expression_operator.rb
|
116
130
|
- lib/cloud_sesame/query/ast/near.rb
|
117
131
|
- lib/cloud_sesame/query/ast/not.rb
|
132
|
+
- lib/cloud_sesame/query/ast/numeric_value.rb
|
118
133
|
- lib/cloud_sesame/query/ast/operator.rb
|
119
134
|
- lib/cloud_sesame/query/ast/or.rb
|
120
135
|
- lib/cloud_sesame/query/ast/phrase.rb
|
@@ -153,6 +168,7 @@ files:
|
|
153
168
|
- lib/cloud_sesame/query/node/request.rb
|
154
169
|
- lib/cloud_sesame/query/node/return.rb
|
155
170
|
- lib/cloud_sesame/query/node/sort.rb
|
171
|
+
- profiler.rb
|
156
172
|
- spec/abstract_object_spec.rb
|
157
173
|
- spec/cloud_sesame/domain/base_spec.rb
|
158
174
|
- spec/cloud_sesame/domain/context_spec.rb
|