searchkick 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -10
- data/lib/searchkick/model.rb +2 -3
- data/lib/searchkick/reindex.rb +1 -1
- data/lib/searchkick/search.rb +0 -3
- data/lib/searchkick/version.rb +1 -1
- data/test/searchkick_test.rb +2 -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: 8b5ae6918d441a036655f1e686a97994c27cd3d0
|
4
|
+
data.tar.gz: 8bfc3d79c77b03afefb8791c0663bb26cd6e6bda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3883c5f4da5b1012e41350f3cc5356c9570d3482d8b9e7fe2bfd660de54b4028cee9841259c23e2f9eace042eb7c0d523ef43afd27c118dce156990980b49ea
|
7
|
+
data.tar.gz: dd6cb042bd1de8627abe1f3aa61150684cf8f6d9235943b1b5f149d612fa26bface7b71ff019497ed76b0577019510bc6ff22ff152f78fde7de9443b81bb08ee
|
data/README.md
CHANGED
@@ -16,8 +16,6 @@ Plus:
|
|
16
16
|
- reindex without downtime
|
17
17
|
- continually improve results from conversions - **pretty awesome**
|
18
18
|
|
19
|
-
Powered by Elasticsearch
|
20
|
-
|
21
19
|
:tangerine: Battle-tested at [Instacart](https://www.instacart.com)
|
22
20
|
|
23
21
|
## Get Started
|
@@ -54,7 +52,6 @@ And to query, use:
|
|
54
52
|
products = Product.search "2% Milk"
|
55
53
|
products.each do |product|
|
56
54
|
puts product.name
|
57
|
-
puts product._score # added by searchkick - between 0 and 1
|
58
55
|
end
|
59
56
|
```
|
60
57
|
|
@@ -147,7 +144,7 @@ Choose what data is indexed.
|
|
147
144
|
|
148
145
|
```ruby
|
149
146
|
class Product < ActiveRecord::Base
|
150
|
-
def
|
147
|
+
def search_data
|
151
148
|
as_json only: [:name, :active], include: {brand: {only: [:city]}}
|
152
149
|
# or equivalently
|
153
150
|
{
|
@@ -161,11 +158,11 @@ class Product < ActiveRecord::Base
|
|
161
158
|
end
|
162
159
|
```
|
163
160
|
|
164
|
-
Searchkick uses `find_in_batches` to import documents. To eager load associations, use the `
|
161
|
+
Searchkick uses `find_in_batches` to import documents. To eager load associations, use the `search_import` scope.
|
165
162
|
|
166
163
|
```ruby
|
167
164
|
class Product < ActiveRecord::Base
|
168
|
-
scope :
|
165
|
+
scope :search_import, includes(:searches)
|
169
166
|
end
|
170
167
|
```
|
171
168
|
|
@@ -188,7 +185,7 @@ Add conversions to the index.
|
|
188
185
|
class Product < ActiveRecord::Base
|
189
186
|
has_many :searches
|
190
187
|
|
191
|
-
def
|
188
|
+
def search_data
|
192
189
|
{
|
193
190
|
name: name,
|
194
191
|
conversions: searches.group("query").count
|
@@ -218,18 +215,32 @@ Product.search "2% Milk", facets: {store_id: {where: {in_stock: true}}}
|
|
218
215
|
|
219
216
|
## Deployment
|
220
217
|
|
221
|
-
###
|
218
|
+
### Heroku
|
222
219
|
|
223
|
-
|
220
|
+
Choose an add-on: [SearchBox](https://addons.heroku.com/searchbox), [Bonsai](https://addons.heroku.com/bonsai), or [Found](https://addons.heroku.com/foundelasticsearch).
|
224
221
|
|
225
222
|
```sh
|
223
|
+
# SearchBox
|
224
|
+
heroku addons:add searchbox:starter
|
225
|
+
|
226
|
+
# Bonsai
|
226
227
|
heroku addons:add bonsai
|
228
|
+
|
229
|
+
# Found
|
230
|
+
heroku addons:add foundelasticsearch
|
227
231
|
```
|
228
232
|
|
229
|
-
And create an initializer `config/initializers/
|
233
|
+
And create an initializer `config/initializers/elasticsearch.rb` with:
|
230
234
|
|
231
235
|
```ruby
|
236
|
+
# SearchBox
|
237
|
+
ENV["ELASTICSEARCH_URL"] = ENV["SEARCHBOX_URL"]
|
238
|
+
|
239
|
+
# Bonsai
|
232
240
|
ENV["ELASTICSEARCH_URL"] = ENV["BONSAI_URL"]
|
241
|
+
|
242
|
+
# Found
|
243
|
+
ENV["ELASTICSEARCH_URL"] = ENV["FOUNDELASTICSEARCH_URL"]
|
233
244
|
```
|
234
245
|
|
235
246
|
Then deploy and reindex:
|
data/lib/searchkick/model.rb
CHANGED
@@ -13,18 +13,17 @@ module Searchkick
|
|
13
13
|
tire do
|
14
14
|
index_name options[:index_name] || [klass.model_name.plural, ENV["RACK_ENV"] || "development"].join("_")
|
15
15
|
end
|
16
|
-
attr_accessor :_score
|
17
16
|
|
18
17
|
def reindex
|
19
18
|
update_index
|
20
19
|
end
|
21
20
|
|
22
|
-
def
|
21
|
+
def search_data
|
23
22
|
as_json
|
24
23
|
end
|
25
24
|
|
26
25
|
def to_indexed_json
|
27
|
-
source =
|
26
|
+
source = search_data
|
28
27
|
if self.class.instance_variable_get("@searchkick_options")[:conversions] and source[:conversions]
|
29
28
|
source[:conversions] = source[:conversions].map{|k, v| {query: k, count: v} }
|
30
29
|
end
|
data/lib/searchkick/reindex.rb
CHANGED
@@ -10,7 +10,7 @@ module Searchkick
|
|
10
10
|
index.create searchkick_index_options
|
11
11
|
|
12
12
|
# use scope for import
|
13
|
-
scope = respond_to?(:
|
13
|
+
scope = respond_to?(:search_import) ? search_import : self
|
14
14
|
scope.find_in_batches do |batch|
|
15
15
|
index.import batch
|
16
16
|
end
|
data/lib/searchkick/search.rb
CHANGED
data/lib/searchkick/version.rb
CHANGED
data/test/searchkick_test.rb
CHANGED