CloudSesame 0.4.1 → 0.4.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/README.md +158 -35
- data/cloud_sesame.gemspec +1 -1
- data/lib/cloud_sesame/query/dsl/query_methods.rb +3 -3
- 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: bdd6130e69369b19a8af9084c9fafeb23da57e10
|
4
|
+
data.tar.gz: 383e48e735e7ee99f3bc3ee31b550fa7603186dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34a744413189cf8306b15bc968d671940e1d1258e50dec628a09273a820803224b4f6c2f3a3925ae1a2a58be34f1bda3977ea226b7d6396dc3d01ffe6c9e848f
|
7
|
+
data.tar.gz: 4da503890c410bf99d4ba05452156d1f6a36fce18442d19f1024260a9b8a7243bca6416875c50c8b201add9a2d362ec59f585d62fdc56062c446e4ba0b1488b3
|
data/Gemfile.lock
CHANGED
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
|
-
-
|
27
|
+
- `define_cloudsearch` with a block to setup class/modal specific setting
|
29
28
|
|
30
|
-
|
29
|
+
####define_cloudsearch(&block)
|
31
30
|
Includes all Model/Class specific cloudsearch configurations
|
32
|
-
|
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
|
-
|
43
|
+
####config.region=(string)
|
35
44
|
Set AWS CloudSearch isntance region
|
36
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
52
|
-
|
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
|
-
|
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
|
-
|
137
|
+
|
138
|
+
{ query_options[:fields] = ['name', 'tags^2'] }
|
61
139
|
```
|
62
|
-
|
140
|
+
|
141
|
+
- with **facet options** passed in
|
63
142
|
```
|
64
|
-
# To enable facet
|
65
143
|
field :currency, facet: true
|
66
144
|
|
67
|
-
|
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
|
-
|
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
|
-
|
163
|
+
- with facet **sorting**
|
164
|
+
```
|
77
165
|
field :category, facet: { sort: 'bucket', size: 10_000 }
|
78
|
-
|
79
166
|
```
|
80
167
|
|
81
|
-
|
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
|
-
|
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
|
-
|
130
|
-
|
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
|
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
|
-
|
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