CloudSesame 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -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(' '.freeze, ''.freeze)
71
+ string.to_s.tr(' ', '')
70
72
  end
71
73
 
72
74
  def self.strip!(string)
73
- string.to_s.tr!(' '.freeze, ''.freeze)
75
+ string.to_s.tr!(' ', '')
74
76
  end
75
77
 
76
78
  def strip(string)
77
- string.to_s.tr(' '.freeze, ''.freeze)
79
+ string.to_s.tr(' ', '')
78
80
  end
79
81
 
80
82
  def strip!(string)
81
- string.to_s.tr!(' '.freeze, ''.freeze)
83
+ string.to_s.tr!(' ', '')
82
84
  end
83
85
 
84
86
  end
@@ -6,7 +6,7 @@ module CloudSesame
6
6
  FORMAT = '%FT%TZ'.freeze
7
7
 
8
8
  def self.parse(value)
9
- range?(value) || string_range?(value) ? RangeValue.parse(value, self) : new(value)
9
+ range?(value) || string_range?(value) ? RangeValue.new(value, self) : new(value)
10
10
  end
11
11
 
12
12
  def to_s
@@ -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.parse(value, self) : new(value)
7
+ range?(value) || string_range?(value) ? RangeValue.new(value, self) : new(value)
8
8
  end
9
9
 
10
10
  def to_s
@@ -4,7 +4,6 @@ module CloudSesame
4
4
  class RangeValue < Abstract::Value
5
5
 
6
6
  def initialize(value = nil, type = nil)
7
-
8
7
  self.value = RangeValue.range?(value) ? range_handler(value) :
9
8
  RangeValue.string_range?(value) ? string_handler(value) :
10
9
  empty_value
@@ -1,155 +1,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
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
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.7.3
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chu