CloudSesame 0.5.5 → 0.6.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 +1 -1
- data/cloud_sesame.gemspec +1 -1
- data/lib/cloud_sesame/domain/base.rb +1 -1
- data/lib/cloud_sesame/query/dsl/response_methods.rb +9 -1
- data/spec/cloud_sesame_spec.rb +166 -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: 5a284b97e1a90ded7efa4706247a6a4e77847282
|
4
|
+
data.tar.gz: cd6259198e246afe1f1ca0ef4c0e73283a904450
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 259b78d26a95d768a904939eb967f5ba8a20eed3d7569c4dd4daa2741059c46d289ed4746925c11901043ba1e357a7a4404c629296f2e8ac892e991d0bef3716
|
7
|
+
data.tar.gz: fb4b1cc9a4f63759400dfeb088533862884878f54e9f8df2249a8caf79548058cb08b9012946bf72f1693150f68426d001c259174dc7e468c9f12b00093bce7a
|
data/Gemfile.lock
CHANGED
data/cloud_sesame.gemspec
CHANGED
@@ -29,7 +29,15 @@ module CloudSesame
|
|
29
29
|
def search
|
30
30
|
compiled = request.compile
|
31
31
|
raise Error::MissingQuery.new("Query or FilterQuery can not be empty!") if !compiled[:query] || compiled[:query].empty?
|
32
|
-
|
32
|
+
if context[:cache]
|
33
|
+
@response = Rails.cache.fetch(compiled) do
|
34
|
+
results = @searchable.cloudsearch.client.search compiled
|
35
|
+
OpenStruct.new(status: results.status, hits: results.hits, facets: results.facets)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
@response = @searchable.cloudsearch.client.search compiled
|
39
|
+
end
|
40
|
+
@response
|
33
41
|
end
|
34
42
|
|
35
43
|
end
|
data/spec/cloud_sesame_spec.rb
CHANGED
@@ -1,163 +1,166 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ruby-prof'
|
3
|
-
require 'benchmark'
|
4
|
-
|
5
|
-
describe CloudSesame do
|
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
|
+
# turn_on_cache
|
38
|
+
|
39
|
+
# default_size 100
|
40
|
+
|
41
|
+
# define_sloppiness 3
|
42
|
+
|
43
|
+
# define_fuzziness do
|
44
|
+
# max_fuzziness 3
|
45
|
+
# min_char_size 6
|
46
|
+
# fuzzy_percent 0.17
|
47
|
+
# end
|
48
|
+
|
49
|
+
# field :searchable_text, query: { weight: 2 }
|
50
|
+
# field :description, query: true
|
51
|
+
# field :tags , default: -> { "men" }
|
52
|
+
|
53
|
+
# field :affiliate_advertiser_ext_id, facet: { size: 50 }
|
54
|
+
# field :currency, facet: true
|
55
|
+
# field :discount_percentage, facet: { buckets: %w([10,100] [25,100] [50,100] [70,100]), method: 'interval' }
|
56
|
+
# field :manufacturer_name, facet: { size: 50 }
|
57
|
+
# field :price, facet: { buckets: %w([0,25] [25,50] [50,100] [100,200] [200,}), method: 'interval' }
|
58
|
+
# field :category_string, facet: { sort: 'bucket', size: 10_000 }
|
59
|
+
# field :created_at, default: -> { Time.now }
|
60
|
+
|
61
|
+
# end
|
62
|
+
|
63
|
+
# end
|
64
|
+
|
65
|
+
|
66
|
+
# # @tags = [1, 2]
|
67
|
+
# # n = 10_000
|
68
|
+
# # q = nil
|
69
|
+
# # result = RubyProf.profile do
|
70
|
+
# # n.times do
|
71
|
+
# # q = Product.cloudsearch.query("black jacket").sort(price: :asc).page(1).size(1000)
|
72
|
+
# # .price { gt 100 }
|
73
|
+
# # .and {
|
74
|
+
# # or! {
|
75
|
+
# # tags *@tags
|
76
|
+
# # tags
|
77
|
+
# # tags nil
|
78
|
+
# # and! {
|
79
|
+
# # tags.not "3", "4"
|
80
|
+
# # }
|
81
|
+
# # and!.not {
|
82
|
+
# # tags.start_with "5", "6"
|
83
|
+
# # tags.not.start_with("7")
|
84
|
+
# # tags.not.near("8", distance: 7)
|
85
|
+
# # tags start_with("9"), near("10")
|
86
|
+
# # tags term("11", boost: 2)
|
87
|
+
# # tags.not phrase "12"
|
88
|
+
# # }
|
89
|
+
# # or!.not {
|
90
|
+
# # price(25..100)
|
91
|
+
# # price 100...200
|
92
|
+
# # price gte(200).lt(300)
|
93
|
+
# # price gte(300)
|
94
|
+
# # }
|
95
|
+
# # or! {
|
96
|
+
# # created_at Date.today - 7
|
97
|
+
# # created_at gte(Date.today)
|
98
|
+
# # created_at gte(Date.today).lt(Date.today + 3)
|
99
|
+
# # }
|
100
|
+
# # }
|
101
|
+
# # }
|
102
|
+
|
103
|
+
# # q.applied_filters
|
104
|
+
|
105
|
+
# # end
|
106
|
+
# # end
|
107
|
+
# # printer = RubyProf::FlatPrinter.new(result)
|
108
|
+
# # printer.print(STDOUT, {})
|
109
|
+
|
110
|
+
# # class Coupon
|
111
|
+
# # include CloudSesame
|
112
|
+
|
113
|
+
# # VALID_COUPON_RANK = 20
|
114
|
+
|
115
|
+
# # define_cloudsearch do
|
116
|
+
# # config.endpoint = ENV['AWS_ENDPOINT']
|
117
|
+
# # config.region = ENV['AWS_REGION']
|
118
|
+
|
119
|
+
# # default_size 10
|
120
|
+
|
121
|
+
# # define_sloppiness 3
|
122
|
+
|
123
|
+
# # define_fuzziness do
|
124
|
+
# # max_fuzziness 3
|
125
|
+
# # min_char_size 6
|
126
|
+
# # fuzzy_percent 0.17
|
127
|
+
# # end
|
128
|
+
|
129
|
+
# # field :end_date, as: :date1
|
130
|
+
# # field :rank, as: :num1, default: -> { gte VALID_COUPON_RANK }
|
131
|
+
# # field :searchable_text, query: true
|
132
|
+
# # field :affiliate_advertiser_search_ext_id, as: :string1, facet: { size: 50 }
|
133
|
+
# # field :countries, as: :string_array1
|
134
|
+
# # field :deal_types, as: :string_array2, facet: {}
|
135
|
+
# # field :tags, as: :string_array3, facet: {}
|
136
|
+
# # field :type, default: -> { 'Catalog::CouponSearchable' }
|
137
|
+
# # end
|
138
|
+
|
139
|
+
# # end
|
140
|
+
|
141
|
+
# # q = Coupon.cloudsearch.builder
|
142
|
+
|
143
|
+
# # binding.pry
|
144
|
+
|
145
|
+
# # class ProductController
|
146
|
+
|
147
|
+
# # def load_userq
|
148
|
+
# # @name = "scott"
|
149
|
+
# # end
|
150
|
+
|
151
|
+
# # def greeting
|
152
|
+
# # "hello world!"
|
153
|
+
# # end
|
154
|
+
|
155
|
+
# # def search
|
156
|
+
# # load_user
|
157
|
+
# # q = Product.cloudsearch.and {
|
158
|
+
# # binding.pry
|
159
|
+
# # }
|
160
|
+
# # end
|
161
|
+
|
162
|
+
# # end
|
163
|
+
|
164
|
+
# # test = ProductController.new
|
165
|
+
# # test.search
|
166
|
+
# end
|