CloudSesame 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- 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 +412 -411
- data/lib/cloud_sesame/query/ast/abstract/value.rb +6 -4
- data/lib/cloud_sesame/query/ast/date_value.rb +1 -1
- data/lib/cloud_sesame/query/ast/numeric_value.rb +1 -1
- data/lib/cloud_sesame/query/ast/range_value.rb +0 -1
- data/spec/profiling_spec.rb +155 -155
- metadata +1 -1
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module CloudSesame
|
2
4
|
module Query
|
3
5
|
module AST
|
@@ -66,19 +68,19 @@ module CloudSesame
|
|
66
68
|
# ===============================================
|
67
69
|
|
68
70
|
def self.strip(string)
|
69
|
-
string.to_s.tr(' '
|
71
|
+
string.to_s.tr(' ', '')
|
70
72
|
end
|
71
73
|
|
72
74
|
def self.strip!(string)
|
73
|
-
string.to_s.tr!(' '
|
75
|
+
string.to_s.tr!(' ', '')
|
74
76
|
end
|
75
77
|
|
76
78
|
def strip(string)
|
77
|
-
string.to_s.tr(' '
|
79
|
+
string.to_s.tr(' ', '')
|
78
80
|
end
|
79
81
|
|
80
82
|
def strip!(string)
|
81
|
-
string.to_s.tr!(' '
|
83
|
+
string.to_s.tr!(' ', '')
|
82
84
|
end
|
83
85
|
|
84
86
|
end
|
@@ -4,7 +4,7 @@ module CloudSesame
|
|
4
4
|
class NumericValue < Abstract::Value
|
5
5
|
|
6
6
|
def self.parse(value)
|
7
|
-
range?(value) || string_range?(value) ? RangeValue.
|
7
|
+
range?(value) || string_range?(value) ? RangeValue.new(value, self) : new(value)
|
8
8
|
end
|
9
9
|
|
10
10
|
def to_s
|
data/spec/profiling_spec.rb
CHANGED
@@ -1,155 +1,155 @@
|
|
1
|
-
|
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
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
fdescribe CloudSesame do
|
4
|
+
# FAKE RAILS AND RAILS CACHE
|
5
|
+
# =====================================
|
6
|
+
class ::Rails
|
7
|
+
def self.cache
|
8
|
+
@cache ||= FakeCache.new
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class ::FakeCache
|
13
|
+
def table
|
14
|
+
@table ||= {}
|
15
|
+
end
|
16
|
+
def fetch(key, &block)
|
17
|
+
table[key] ||= (block.call if block_given?)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# AWS initializer
|
22
|
+
# =======================================================
|
23
|
+
require 'yaml'
|
24
|
+
YAML.load_file('aws.yml').each do |key, value|
|
25
|
+
ENV["AWS_#{ key }"] = value
|
26
|
+
end
|
27
|
+
|
28
|
+
# Domain Initializer /config/initializers/cloudsearch.rb
|
29
|
+
# =======================================================
|
30
|
+
require 'cloud_sesame'
|
31
|
+
|
32
|
+
CloudSesame::Domain::Client.configure do |config|
|
33
|
+
config.access_key = ENV['AWS_ACCESS_KEY_ID']
|
34
|
+
config.secret_key = ENV['AWS_SECRET_ACCESS_KEY']
|
35
|
+
end
|
36
|
+
|
37
|
+
# Usage Example
|
38
|
+
# =======================================================
|
39
|
+
class Product
|
40
|
+
include CloudSesame
|
41
|
+
|
42
|
+
def self.greeting
|
43
|
+
"hello world!"
|
44
|
+
end
|
45
|
+
|
46
|
+
define_cloudsearch do
|
47
|
+
# Product CloudSesame Config
|
48
|
+
config.endpoint = ENV['AWS_ENDPOINT']
|
49
|
+
config.region = ENV['AWS_REGION']
|
50
|
+
|
51
|
+
caching_with :RailsCache
|
52
|
+
|
53
|
+
default_size 100
|
54
|
+
|
55
|
+
define_sloppiness 3
|
56
|
+
|
57
|
+
define_fuzziness do
|
58
|
+
max_fuzziness 3
|
59
|
+
min_char_size 6
|
60
|
+
fuzzy_percent 0.17
|
61
|
+
end
|
62
|
+
|
63
|
+
field :searchable_text, query: { weight: 2 }, type: :string
|
64
|
+
field :description, query: { weight: 0.5 }, type: :string
|
65
|
+
field :tags, type: :string
|
66
|
+
|
67
|
+
field :affiliate_advertiser_ext_id, facet: { size: 50 }
|
68
|
+
field :currency, facet: true
|
69
|
+
field :discount_percentage, facet: { buckets: %w([10,100] [25,100] [50,100] [70,100]), method: 'interval' }
|
70
|
+
field :manufacturer_name, facet: { size: 50 }
|
71
|
+
field :price, facet: { buckets: %w([0,25] [25,50] [50,100] [100,200] [200,}), method: 'interval' }
|
72
|
+
field :category_string, facet: { sort: 'bucket', size: 10_000 }
|
73
|
+
field :created_at, type: :datetime
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
class Coupon
|
80
|
+
include CloudSesame
|
81
|
+
|
82
|
+
VALID_COUPON_RANK = 20
|
83
|
+
|
84
|
+
define_cloudsearch do
|
85
|
+
config.endpoint = ENV['AWS_ENDPOINT']
|
86
|
+
config.region = ENV['AWS_REGION']
|
87
|
+
|
88
|
+
default_size 10
|
89
|
+
|
90
|
+
define_sloppiness 3
|
91
|
+
|
92
|
+
define_fuzziness do
|
93
|
+
max_fuzziness 3
|
94
|
+
min_char_size 6
|
95
|
+
fuzzy_percent 0.17
|
96
|
+
end
|
97
|
+
|
98
|
+
field :end_date, as: :date1
|
99
|
+
field :rank, as: :num1, default: -> { gte VALID_COUPON_RANK }
|
100
|
+
field :searchable_text, query: true
|
101
|
+
field :affiliate_advertiser_search_ext_id, as: :string1, facet: { size: 50 }
|
102
|
+
field :countries, as: :string_array1
|
103
|
+
field :deal_types, as: :string_array2, facet: {}
|
104
|
+
field :tags, as: :string_array3, facet: {}
|
105
|
+
field :type, default: -> { 'Catalog::CouponSearchable' }
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
@tags = [1, 2]
|
111
|
+
q = nil
|
112
|
+
profile 10_000 do
|
113
|
+
q = Product.cloudsearch
|
114
|
+
.query("black leather jacket")
|
115
|
+
.sort(price: :asc, created_at: :desc)
|
116
|
+
.page(3)
|
117
|
+
.size(1000)
|
118
|
+
.price { gt 1 }
|
119
|
+
.tags { "2" }
|
120
|
+
.and {
|
121
|
+
or! {
|
122
|
+
tags *@tags
|
123
|
+
tags nil
|
124
|
+
and! {
|
125
|
+
tags.not "3", "4"
|
126
|
+
}
|
127
|
+
and!.not {
|
128
|
+
tags.start_with "5", "6"
|
129
|
+
tags.not.start_with("7")
|
130
|
+
tags.not.near("8", distance: 7)
|
131
|
+
tags start_with("9"), near("10")
|
132
|
+
tags term("11", boost: 2)
|
133
|
+
tags.not phrase "12"
|
134
|
+
}
|
135
|
+
or!.not {
|
136
|
+
price(25..100)
|
137
|
+
price 100...200
|
138
|
+
price gte(200).lt(300)
|
139
|
+
price gte(300)
|
140
|
+
}
|
141
|
+
or! {
|
142
|
+
created_at Date.today - 7
|
143
|
+
created_at gte(Date.today)
|
144
|
+
created_at gte(Date.today).lt(Date.today + 3)
|
145
|
+
}
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
q.compile
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
binding.pry
|
154
|
+
|
155
|
+
end
|