CloudSesame 0.5.4 → 0.5.5
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/lib/cloud_sesame/domain/base.rb +4 -0
- data/lib/cloud_sesame/query/ast/numeric_value.rb +3 -1
- data/spec/cloud_sesame/query/ast/numeric_value_spec.rb +7 -1
- data/spec/cloud_sesame_spec.rb +163 -163
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcedaacb98078285e2bf1d047a041e4d284e0ba9
|
4
|
+
data.tar.gz: 9694b8af7cd6f591f02979431d52113f97e4db50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42f1e5e7bc7d6fe4b1eb7cfc0bfdc86c9ebbda56032ccc92a236e449e6608f5f792be6b1d710c56adffcdf0344f9b6465faabdd3e0aec65a90919fc762f8ca25
|
7
|
+
data.tar.gz: 72d113a1d7004a47ced9f0d5e8767aa04a3ce4c9a7b906ffcd8c746717d9be5beeff11766e0f37e162f9ba0e2c2a05de455b14efe02ffb78ba77aee698426f10
|
data/Gemfile.lock
CHANGED
data/cloud_sesame.gemspec
CHANGED
@@ -44,7 +44,6 @@ module CloudSesame
|
|
44
44
|
|
45
45
|
it 'should return true if data equals to the value' do
|
46
46
|
expect(subject == 0.990).to eq true
|
47
|
-
expect(subject == "0.990").to eq true
|
48
47
|
end
|
49
48
|
|
50
49
|
it 'should return false when data does not equal to the value' do
|
@@ -53,6 +52,13 @@ module CloudSesame
|
|
53
52
|
end
|
54
53
|
end
|
55
54
|
|
55
|
+
context 'when value comparing with a nil value' do
|
56
|
+
subject { NumericValue.new(1) }
|
57
|
+
it 'should return false' do
|
58
|
+
expect(subject == nil).to eq false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
56
62
|
end
|
57
63
|
|
58
64
|
end
|
data/spec/cloud_sesame_spec.rb
CHANGED
@@ -1,163 +1,163 @@
|
|
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
|
-
#
|
156
|
-
#
|
157
|
-
#
|
158
|
-
|
159
|
-
#
|
160
|
-
|
161
|
-
#
|
162
|
-
#
|
163
|
-
|
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
|
+
def self.greeting
|
29
|
+
"hello world!"
|
30
|
+
end
|
31
|
+
|
32
|
+
define_cloudsearch do
|
33
|
+
# Product CloudSesame Config
|
34
|
+
config.endpoint = ENV['AWS_ENDPOINT']
|
35
|
+
config.region = ENV['AWS_REGION']
|
36
|
+
|
37
|
+
default_size 100
|
38
|
+
|
39
|
+
define_sloppiness 3
|
40
|
+
|
41
|
+
define_fuzziness do
|
42
|
+
max_fuzziness 3
|
43
|
+
min_char_size 6
|
44
|
+
fuzzy_percent 0.17
|
45
|
+
end
|
46
|
+
|
47
|
+
field :searchable_text, query: { weight: 2 }
|
48
|
+
field :description, query: true
|
49
|
+
field :tags , as: :text1, default: -> { "men" }
|
50
|
+
|
51
|
+
field :affiliate_advertiser_ext_id, facet: { size: 50 }
|
52
|
+
field :currency, facet: true
|
53
|
+
field :discount_percentage, facet: { buckets: %w([10,100] [25,100] [50,100] [70,100]), method: 'interval' }
|
54
|
+
field :manufacturer_name, facet: { size: 50 }
|
55
|
+
field :price, facet: { buckets: %w([0,25] [25,50] [50,100] [100,200] [200,}), method: 'interval' }
|
56
|
+
field :category_string, facet: { sort: 'bucket', size: 10_000 }
|
57
|
+
field :created_at, default: -> { Time.now }
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
# @tags = [1, 2]
|
65
|
+
# n = 10_000
|
66
|
+
# q = nil
|
67
|
+
# result = RubyProf.profile do
|
68
|
+
# n.times do
|
69
|
+
# q = Product.cloudsearch.query("black jacket").sort(price: :asc).page(1).size(1000)
|
70
|
+
# .price { gt 100 }
|
71
|
+
# .and {
|
72
|
+
# or! {
|
73
|
+
# tags *@tags
|
74
|
+
# tags
|
75
|
+
# tags nil
|
76
|
+
# and! {
|
77
|
+
# tags.not "3", "4"
|
78
|
+
# }
|
79
|
+
# and!.not {
|
80
|
+
# tags.start_with "5", "6"
|
81
|
+
# tags.not.start_with("7")
|
82
|
+
# tags.not.near("8", distance: 7)
|
83
|
+
# tags start_with("9"), near("10")
|
84
|
+
# tags term("11", boost: 2)
|
85
|
+
# tags.not phrase "12"
|
86
|
+
# }
|
87
|
+
# or!.not {
|
88
|
+
# price(25..100)
|
89
|
+
# price 100...200
|
90
|
+
# price gte(200).lt(300)
|
91
|
+
# price gte(300)
|
92
|
+
# }
|
93
|
+
# or! {
|
94
|
+
# created_at Date.today - 7
|
95
|
+
# created_at gte(Date.today)
|
96
|
+
# created_at gte(Date.today).lt(Date.today + 3)
|
97
|
+
# }
|
98
|
+
# }
|
99
|
+
# }
|
100
|
+
# q.applied_filters
|
101
|
+
|
102
|
+
# end
|
103
|
+
# end
|
104
|
+
# printer = RubyProf::FlatPrinter.new(result)
|
105
|
+
# printer.print(STDOUT, {})
|
106
|
+
|
107
|
+
class Coupon
|
108
|
+
include CloudSesame
|
109
|
+
|
110
|
+
VALID_COUPON_RANK = 20
|
111
|
+
|
112
|
+
define_cloudsearch do
|
113
|
+
config.endpoint = ENV['AWS_ENDPOINT']
|
114
|
+
config.region = ENV['AWS_REGION']
|
115
|
+
|
116
|
+
default_size 10
|
117
|
+
|
118
|
+
define_sloppiness 3
|
119
|
+
|
120
|
+
define_fuzziness do
|
121
|
+
max_fuzziness 3
|
122
|
+
min_char_size 6
|
123
|
+
fuzzy_percent 0.17
|
124
|
+
end
|
125
|
+
|
126
|
+
field :end_date, as: :date1
|
127
|
+
field :rank, as: :num1, default: -> { gte VALID_COUPON_RANK }
|
128
|
+
field :searchable_text, query: true
|
129
|
+
field :affiliate_advertiser_search_ext_id, as: :string1, facet: { size: 50 }
|
130
|
+
field :countries, as: :string_array1
|
131
|
+
field :deal_types, as: :string_array2, facet: {}
|
132
|
+
field :tags, as: :string_array3, facet: {}
|
133
|
+
field :type, default: -> { 'Catalog::CouponSearchable' }
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
q = Coupon.cloudsearch.builder
|
139
|
+
|
140
|
+
binding.pry
|
141
|
+
|
142
|
+
# class ProductController
|
143
|
+
|
144
|
+
# def load_userq
|
145
|
+
# @name = "scott"
|
146
|
+
# end
|
147
|
+
|
148
|
+
# def greeting
|
149
|
+
# "hello world!"
|
150
|
+
# end
|
151
|
+
|
152
|
+
# def search
|
153
|
+
# load_user
|
154
|
+
# q = Product.cloudsearch.and {
|
155
|
+
# binding.pry
|
156
|
+
# }
|
157
|
+
# end
|
158
|
+
|
159
|
+
# end
|
160
|
+
|
161
|
+
# test = ProductController.new
|
162
|
+
# test.search
|
163
|
+
end
|