searchkick 0.2.0 → 0.2.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 +14 -8
- data/lib/searchkick.rb +1 -0
- data/lib/searchkick/logger.rb +19 -0
- data/lib/searchkick/reindex.rb +2 -2
- data/lib/searchkick/search.rb +4 -0
- data/lib/searchkick/version.rb +1 -1
- data/searchkick.gemspec +1 -0
- data/test/match_test.rb +5 -0
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b15fd3f6aa1493ee75fee109a3420fb8e79bed7
|
4
|
+
data.tar.gz: c8cf011a7e5fb72bb25fe131eaa655be2713def7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7c45c3c3627c02a45c7cc4380d59404d334fb2a0e1e4a327b472cb14dcac12df59843f5bf146185c76998409fcadb850393b0c92e89e0f6a20972445fbe1735
|
7
|
+
data.tar.gz: 616ca8f2a7776ca7f830cb2679bdbd7769460061107ed833f607896cfa2d637927011a40c958e026f0717de9471dd64f2bad157fbb55b79d93019132a7f8a605
|
data/README.md
CHANGED
@@ -287,6 +287,8 @@ Product.search "2% Milk", facets: {store_id: {where: {in_stock: true}}}
|
|
287
287
|
|
288
288
|
## Deployment
|
289
289
|
|
290
|
+
Searchkick uses `ENV["ELASTICSEARCH_URL"]` for the Elasticsearch server. This defaults to `http://localhost:9200`.
|
291
|
+
|
290
292
|
### Heroku
|
291
293
|
|
292
294
|
Choose an add-on: [SearchBox](https://addons.heroku.com/searchbox), [Bonsai](https://addons.heroku.com/bonsai), or [Found](https://addons.heroku.com/foundelasticsearch).
|
@@ -294,25 +296,29 @@ Choose an add-on: [SearchBox](https://addons.heroku.com/searchbox), [Bonsai](htt
|
|
294
296
|
```sh
|
295
297
|
# SearchBox
|
296
298
|
heroku addons:add searchbox:starter
|
299
|
+
heroku config:add ELASTICSEARCH_URL=`heroku config:get SEARCHBOX_URL`
|
297
300
|
|
298
301
|
# Bonsai
|
299
302
|
heroku addons:add bonsai
|
303
|
+
heroku config:add ELASTICSEARCH_URL=`heroku config:get BONSAI_URL`
|
300
304
|
|
301
305
|
# Found
|
302
306
|
heroku addons:add foundelasticsearch
|
307
|
+
heroku config:add ELASTICSEARCH_URL=`heroku config:get FOUNDELASTICSEARCH_URL`
|
303
308
|
```
|
304
309
|
|
305
|
-
|
310
|
+
Then deploy and reindex:
|
306
311
|
|
307
|
-
```
|
308
|
-
|
309
|
-
|
312
|
+
```sh
|
313
|
+
heroku run rake searchkick:reindex CLASS=Product
|
314
|
+
```
|
310
315
|
|
311
|
-
|
312
|
-
ENV["ELASTICSEARCH_URL"] = ENV["BONSAI_URL"]
|
316
|
+
### Other
|
313
317
|
|
314
|
-
|
315
|
-
|
318
|
+
Create an initializer `config/initializers/elasticsearch.rb` with:
|
319
|
+
|
320
|
+
```ruby
|
321
|
+
ENV["ELASTICSEARCH_URL"] = "http://username:password@api.searchbox.io"
|
316
322
|
```
|
317
323
|
|
318
324
|
Then deploy and reindex:
|
data/lib/searchkick.rb
CHANGED
@@ -5,6 +5,7 @@ require "searchkick/results"
|
|
5
5
|
require "searchkick/search"
|
6
6
|
require "searchkick/model"
|
7
7
|
require "searchkick/tasks"
|
8
|
+
require "searchkick/logger" if defined?(Rails)
|
8
9
|
|
9
10
|
# TODO find better ActiveModel hook
|
10
11
|
ActiveModel::AttributeMethods::ClassMethods.send(:include, Searchkick::Model)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "tire/rails/logger"
|
2
|
+
require "tire/rails/logger/log_subscriber"
|
3
|
+
|
4
|
+
class Tire::Rails::LogSubscriber
|
5
|
+
|
6
|
+
# better output format
|
7
|
+
def search(event)
|
8
|
+
self.class.runtime += event.duration
|
9
|
+
return unless logger.debug?
|
10
|
+
|
11
|
+
payload = event.payload
|
12
|
+
|
13
|
+
name = "%s (%.1fms)" % [payload[:name], event.duration]
|
14
|
+
query = payload[:search].to_s
|
15
|
+
|
16
|
+
debug " #{color(name, YELLOW, true)} #{query}"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/lib/searchkick/reindex.rb
CHANGED
@@ -57,12 +57,12 @@ module Searchkick
|
|
57
57
|
tokenizer: "standard",
|
58
58
|
# synonym should come last, after stemming and shingle
|
59
59
|
# shingle must come before snowball
|
60
|
-
filter: ["standard", "lowercase", "asciifolding", "stop", "
|
60
|
+
filter: ["standard", "lowercase", "asciifolding", "stop", "searchkick_index_shingle", "snowball"]
|
61
61
|
},
|
62
62
|
searchkick_search: {
|
63
63
|
type: "custom",
|
64
64
|
tokenizer: "standard",
|
65
|
-
filter: ["standard", "lowercase", "asciifolding", "stop", "
|
65
|
+
filter: ["standard", "lowercase", "asciifolding", "stop", "searchkick_search_shingle", "snowball"]
|
66
66
|
},
|
67
67
|
searchkick_search2: {
|
68
68
|
type: "custom",
|
data/lib/searchkick/search.rb
CHANGED
@@ -182,6 +182,10 @@ module Searchkick
|
|
182
182
|
|
183
183
|
payload = s.to_hash
|
184
184
|
|
185
|
+
# An empty array will cause only the _id and _type for each hit to be returned
|
186
|
+
# http://www.elasticsearch.org/guide/reference/api/search/fields/
|
187
|
+
payload[:fields] = [] if load
|
188
|
+
|
185
189
|
# suggestions
|
186
190
|
if options[:suggest]
|
187
191
|
suggest_fields = (@searchkick_options[:suggest] || []).map(&:to_s)
|
data/lib/searchkick/version.rb
CHANGED
data/searchkick.gemspec
CHANGED
data/test/match_test.rb
CHANGED
@@ -29,6 +29,11 @@ class TestMatch < Minitest::Unit::TestCase
|
|
29
29
|
assert_search "dish soap", ["Dish Washer Amazing Organic Soap"]
|
30
30
|
end
|
31
31
|
|
32
|
+
def test_middle_token_wine
|
33
|
+
store_names ["Beringer Wine Founders Estate Chardonnay"]
|
34
|
+
assert_search "beringer chardonnay", ["Beringer Wine Founders Estate Chardonnay"]
|
35
|
+
end
|
36
|
+
|
32
37
|
def test_percent
|
33
38
|
store_names ["1% Milk", "2% Milk", "Whole Milk"]
|
34
39
|
assert_search "1%", ["1% Milk"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: searchkick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: tire-contrib
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,6 +121,7 @@ files:
|
|
107
121
|
- README.md
|
108
122
|
- Rakefile
|
109
123
|
- lib/searchkick.rb
|
124
|
+
- lib/searchkick/logger.rb
|
110
125
|
- lib/searchkick/model.rb
|
111
126
|
- lib/searchkick/reindex.rb
|
112
127
|
- lib/searchkick/results.rb
|