CloudSesame 0.7.1 → 0.7.2
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/coverage/.last_run.json +1 -1
- data/coverage/.resultset.json +376 -376
- data/lib/services/class_specific.rb +4 -4
- data/spec/profiling_spec.rb +155 -155
- metadata +1 -1
|
@@ -15,10 +15,11 @@ module ClassSpecific
|
|
|
15
15
|
private
|
|
16
16
|
|
|
17
17
|
def __constructor__(klass, callback_args)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
yield(name)
|
|
18
|
+
return self if !(name = __get_constant_name__(klass))
|
|
19
|
+
return const_get(name) if constants(false).include?(name.to_sym)
|
|
21
20
|
|
|
21
|
+
yield(name)
|
|
22
|
+
constant = yield(name)
|
|
22
23
|
__invoke_callback__(constant, klass, *callback_args) if @__construct_callback__
|
|
23
24
|
constant
|
|
24
25
|
end
|
|
@@ -26,7 +27,6 @@ module ClassSpecific
|
|
|
26
27
|
def __invoke_callback__(constant, klass, *args)
|
|
27
28
|
eval_method = constant.is_a?(Class) ? :class_exec : :module_exec
|
|
28
29
|
constant.send(eval_method, klass, *args, &@__construct_callback__)
|
|
29
|
-
@__construct_callback__ = nil
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def __define_subclass__(name, parent)
|
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: true, 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 1 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
|