CloudSesame 0.5.5 → 0.6.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bcedaacb98078285e2bf1d047a041e4d284e0ba9
4
- data.tar.gz: 9694b8af7cd6f591f02979431d52113f97e4db50
3
+ metadata.gz: 5a284b97e1a90ded7efa4706247a6a4e77847282
4
+ data.tar.gz: cd6259198e246afe1f1ca0ef4c0e73283a904450
5
5
  SHA512:
6
- metadata.gz: 42f1e5e7bc7d6fe4b1eb7cfc0bfdc86c9ebbda56032ccc92a236e449e6608f5f792be6b1d710c56adffcdf0344f9b6465faabdd3e0aec65a90919fc762f8ca25
7
- data.tar.gz: 72d113a1d7004a47ced9f0d5e8767aa04a3ce4c9a7b906ffcd8c746717d9be5beeff11766e0f37e162f9ba0e2c2a05de455b14efe02ffb78ba77aee698426f10
6
+ metadata.gz: 259b78d26a95d768a904939eb967f5ba8a20eed3d7569c4dd4daa2741059c46d289ed4746925c11901043ba1e357a7a4404c629296f2e8ac892e991d0bef3716
7
+ data.tar.gz: fb4b1cc9a4f63759400dfeb088533862884878f54e9f8df2249a8caf79548058cb08b9012946bf72f1693150f68426d001c259174dc7e468c9f12b00093bce7a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- CloudSesame (0.5.5)
4
+ CloudSesame (0.6.0)
5
5
  aws-sdk (~> 2)
6
6
 
7
7
  GEM
data/cloud_sesame.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'CloudSesame'
3
- s.version = '0.5.5'
3
+ s.version = '0.6.0'
4
4
  s.date = '2016-02-09'
5
5
  s.summary = "AWS CloudSearch Query DSL"
6
6
  s.description = "AWS CloudSearch Query DSL"
@@ -32,7 +32,7 @@ module CloudSesame
32
32
  # =========================================
33
33
 
34
34
  def turn_on_cache
35
-
35
+ context[:cache] = !!(Rails rescue nil)
36
36
  end
37
37
 
38
38
  def default_size(value)
@@ -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
- @response = @searchable.cloudsearch.client.search compiled
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
@@ -1,163 +1,166 @@
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
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
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.5.5
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chu