CloudSesame 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21f970b1cf0438d0960afe37b8bded2fa6e8c6a8
4
- data.tar.gz: 9807f2c701ddde033b69a81ac71eeea48d525585
3
+ metadata.gz: bdd6130e69369b19a8af9084c9fafeb23da57e10
4
+ data.tar.gz: 383e48e735e7ee99f3bc3ee31b550fa7603186dd
5
5
  SHA512:
6
- metadata.gz: 86ce9ff3dd0530e1a2a46db0f9cd020b1d8156e34e39b0293cd83fcba32cb2838671d6864fb713510af4319541c2991de06c48f1c75928e9e883622eb5911363
7
- data.tar.gz: 599aa1e9d8b3cf01cc0325d3467a0d2fc7e75454af9b63ff9c7e16c43b02514fba61f3aacd1d8ee70183c2c6514b2f6ae68e28f72696c46605b22facb43824cd
6
+ metadata.gz: 34a744413189cf8306b15bc968d671940e1d1258e50dec628a09273a820803224b4f6c2f3a3925ae1a2a58be34f1bda3977ea226b7d6396dc3d01ffe6c9e848f
7
+ data.tar.gz: 4da503890c410bf99d4ba05452156d1f6a36fce18442d19f1024260a9b8a7243bca6416875c50c8b201add9a2d362ec59f585d62fdc56062c446e4ba0b1488b3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- CloudSesame (0.4.1)
4
+ CloudSesame (0.4.2)
5
5
  aws-sdk (~> 2)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -23,21 +23,61 @@ end
23
23
  ```
24
24
 
25
25
  #Model Setup
26
- ##1. Mix CloudSesame into any class or model
27
26
  - `include CloudSesame` in a model or class
28
- - call `define_cloudsearch` and pass in a block to define the cloudsearch
27
+ - `define_cloudsearch` with a block to setup class/modal specific setting
29
28
 
30
- #####define_cloudsearch(&block)
29
+ ####define_cloudsearch(&block)
31
30
  Includes all Model/Class specific cloudsearch configurations
32
- #####config.endpoint=(string)
31
+ ```
32
+ class Product
33
+ include CloudSesame
34
+
35
+ define_cloudsearch do
36
+ ...
37
+ end
38
+ end
39
+ ```
40
+
41
+ ####config.endpoint=(string)
33
42
  Set AWS CloudSearch instance search endpoint
34
- #####config.region=(string)
43
+ ####config.region=(string)
35
44
  Set AWS CloudSearch isntance region
36
- #####default_size(integer = 10)
45
+ ```
46
+ class Product
47
+ include CloudSesame
48
+
49
+ define_cloudsearch do
50
+ config.endpoint = ENV[...]
51
+ config.region = ENV[...]
52
+ end
53
+ end
54
+ ```
55
+
56
+ ####default_size(integer = 10)
37
57
  Set default search size
38
- #####define_sloppiness(integer)
58
+ ```
59
+ class Product
60
+ include CloudSesame
61
+
62
+ define_cloudsearch do
63
+ default_size 100
64
+ end
65
+ end
66
+ ```
67
+
68
+ ####define_sloppiness(integer)
39
69
  Setup sloppy query, it is turned off by default
40
- #####define_fuzziness(&block)
70
+ ```
71
+ class Product
72
+ include CloudSesame
73
+
74
+ define_cloudsearch do
75
+ define_sloppiness 3
76
+ end
77
+ end
78
+ ```
79
+
80
+ ####define_fuzziness(&block)
41
81
  Setup fuzziness, it is turned off by default.
42
82
  the block can set 3 values
43
83
  - **max_fuzziness(integer = 3)**
@@ -47,43 +87,104 @@ the block can set 3 values
47
87
  - **fuzzy_percent(float = 0.17)**
48
88
  percent used to calculate the fuzziness based on the word length, fuzziness whill choose between the calculated result and maximum fizziness, whichever is smaller.
49
89
  [(word.size * fuzzy_percent).round, max_fuzziness].min
90
+ ```
91
+ class Product
92
+ include CloudSesame
93
+
94
+ define_cloudsearch do
95
+ define_fuzziness do
96
+ max_fuzziness 3
97
+ min_char_size 6
98
+ fuzzy_percent 0.17
99
+ end
100
+ end
101
+ end
102
+ ```
103
+
104
+ ####field(symbol, options = {})
105
+ calling field and pass in a field_name will create an field expression accessor
106
+ - simple usage
107
+ ```
108
+ field :name
109
+ ```
110
+ and field expression accessor can be called to create a field expression
111
+ ```
112
+ Product.cloudsearch.name("user")
50
113
 
51
- #####field(symbol, options = {})
52
- calling field and pass in a field_name will create an literal method, which can be called to create a literal expression
114
+ { filter_query: "name:'user'" }
115
+ ```
116
+ - aliase field name
117
+ ```
118
+ field :text1, as: :name
119
+ ```
120
+ and field expression accessor method name will be `#name`
121
+ ```
122
+ Product.cloudsearch.name("user")
123
+
124
+ { filter_query: "text1:'user'" }
125
+ ```
53
126
 
54
- **field examples with query options**
127
+ - with query options is set to `true`
55
128
  ```
56
129
  field :name, query: true
57
- # COMPILED: query_options[:fields] = ["name"]
58
130
 
131
+ { query_options: { fields: ['name'] } }
132
+ ```
133
+
134
+ - with **weight** assigned to query options
135
+ ```
59
136
  field :tags, query: { weight: 2 }
60
- # COMPILED: query_options[:fields] = ["name", "tags^2"]
137
+
138
+ { query_options[:fields] = ['name', 'tags^2'] }
61
139
  ```
62
- **field example with facet**
140
+
141
+ - with **facet options** passed in
63
142
  ```
64
- # To enable facet
65
143
  field :currency, facet: true
66
144
 
67
- # To enable facet with buckets
145
+ { facets: { currency:{} } }
146
+ ```
147
+
148
+ - with facet **buckets**
149
+ ```
68
150
  field :discount, facet: {
69
151
  buckets: %w([10,100] [25,100] [50,100] [70,100]),
70
152
  method: 'interval'
71
153
  }
72
154
 
73
- # To enable facet with max size
155
+ { facets: { discount: { buckets:["[10,100]","[25,100]","[50,100]","[70,100]"], method:"interval"} } }
156
+ ```
157
+
158
+ - with facet **size** set
159
+ ```
74
160
  field :manufacturer, facet: { size: 50 }
161
+ ```
75
162
 
76
- # To enable facet with sorting
163
+ - with facet **sorting**
164
+ ```
77
165
  field :category, facet: { sort: 'bucket', size: 10_000 }
78
-
79
166
  ```
80
167
 
81
- #####scope(symbol, proc, &block)
168
+
169
+ ####scope(symbol, proc, &block)
82
170
  ActiveRecord styled scope method. Scope allows you to specify commonly-used queries which can be referenced as method calls on cloudsearch or inside of operator block
171
+ **set scope**
172
+ ```
173
+ ...
174
+ define_cloudsearch do
175
+ ....
176
+
177
+ scope :popular, -> { or! { tags "popular"; popularity gt(70) } }
178
+ end
83
179
 
84
-
85
180
 
86
- **complete example**
181
+ ```
182
+ **call a scope**
183
+ ```
184
+ Product.cloudsearch.query("shoes").popular
185
+ ```
186
+
187
+ ####Full Example
87
188
  ```
88
189
  class Product < ActiveRecord::Base
89
190
  include CloudSesame
@@ -126,29 +227,51 @@ class Product < ActiveRecord::Base
126
227
  end
127
228
  ```
128
229
 
129
- #####load_definition_from(Class/Model)
130
- every cloud
230
+ ##Inherit cloudsearch definition from another class/modal
231
+ ####load_definition_from(Class/Model)
131
232
  ```
132
233
  class ExclusiveProduct < Product
133
- # load any define cloudsearch definition from class/model
134
234
  load_definition_from Product
135
235
  end
136
236
  ```
137
-
237
+ definition can be overrided by calling `#define_cloudsearch` again
138
238
  ```
139
-
140
-
141
- # call define_cloudsearch again to override config
142
- # or map field to a different name
143
239
  define_cloudsearch {
144
- field :name, as: :product_name # => it will use name as product_name's alias, so user can query with
145
- # NewProduct.cloudsearch.name("shoes") instead of .product_name("shoes")
146
- # but the output will still be filter_query="product_name:'shoes'"
240
+ field :name, as: :product_name
147
241
  }
148
- end
149
242
  ```
150
243
 
151
- ##3. Query DSL
244
+ #Query DSL
245
+ - `.cloudsearch` returns a CloudSesame::Domain::Base instance. It is the entry point to start building up the query
246
+ - A CloudSesame::Query::Builder instance is expected to return from any query methods chained after `.cloudsearch`
247
+ ```
248
+ Product.cloudsearch #=> <CloudSesame::Domain::Base/>
249
+ query = Product.cloudsearch.query("shoes") => <CloudSesame::Query::Builder query:'shoes'/>
250
+ ```
251
+ **Query methods can be chained and build up**
252
+ ```
253
+ query = Product.cloudsearch.query("shoes")
254
+ .and {
255
+ manufacturer('puma')
256
+ or!.not {
257
+ manufacturer "nike", "adidas"
258
+ }
259
+ }
260
+ .sort(price: :desc)
261
+ .page(2)
262
+ .size(100)
263
+ }
264
+ ```
265
+ and `query.compile` will output the compiled hash
266
+ ```
267
+ {
268
+ query:'shoes',
269
+ filter_query: "(and manufacturer:'puma' (not (or manufacturer:'nike' manufacturer:'adidas')))",
270
+ sort: "price desc"
271
+ start: 100
272
+ size: 100
273
+ }
274
+ ```
152
275
 
153
276
  ###Simple Query
154
277
  ```
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.4.1'
3
+ s.version = '0.4.2'
4
4
  s.date = '2016-01-20'
5
5
  s.summary = "AWS CloudSearch Query DSL"
6
6
  s.description = "AWS CloudSearch Query DSL"
@@ -3,9 +3,9 @@ module CloudSesame
3
3
  module DSL
4
4
  module QueryMethods
5
5
 
6
- def query(input = nil)
7
- if input
8
- request.query.query = input
6
+ def query(input = false)
7
+ if input || input.nil?
8
+ request.query.query = input if input
9
9
  return self
10
10
  else
11
11
  request.query.query
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.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chu