searchkick 0.2.1 → 0.2.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/README.md +12 -7
- data/lib/searchkick/reindex.rb +13 -9
- data/lib/searchkick/search.rb +2 -2
- data/lib/searchkick/version.rb +1 -1
- data/test/index_test.rb +20 -0
- data/test/match_test.rb +5 -0
- data/test/test_helper.rb +3 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7af3f444676ffd5380a5fec201895f7f1ddbcbe
|
4
|
+
data.tar.gz: 07b653656f8914410a6bda9c1f0f3d1485d54465
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acde708f7c77cddf74af3b647e37f97014a16ab958b7e03b11e9774abfa02ab57c518c6f0d2647d39434f4f8ed3c3203e9a536a4ac2b2d0c961f80201cb8121c
|
7
|
+
data.tar.gz: 95ee8bd70933e4d04b0f04e96be972ed2075a065961b86da6f4164fe84ba013c2724c0801911299914b4554a405a5dc2f5751ba2843f0e80fed45b30055203c6
|
data/README.md
CHANGED
@@ -167,14 +167,11 @@ Control what data is indexed with the `search_data` method. Call `Product.reinde
|
|
167
167
|
```ruby
|
168
168
|
class Product < ActiveRecord::Base
|
169
169
|
def search_data
|
170
|
-
as_json only: [:name, :active]
|
170
|
+
as_json only: [:name, :active]
|
171
171
|
# or equivalently
|
172
172
|
{
|
173
173
|
name: name,
|
174
|
-
active: active
|
175
|
-
brand: {
|
176
|
-
city: brand.city
|
177
|
-
}
|
174
|
+
active: active
|
178
175
|
}
|
179
176
|
end
|
180
177
|
end
|
@@ -201,9 +198,9 @@ class Search < ActiveRecord::Base
|
|
201
198
|
end
|
202
199
|
```
|
203
200
|
|
204
|
-
|
201
|
+
You do **not** need to clean up the search queries. Searchkick automatically treats `apple` and `APPLES` the same.
|
205
202
|
|
206
|
-
|
203
|
+
Next, add conversions to the index. You must specify the conversions field as of version `0.2.0`.
|
207
204
|
|
208
205
|
```ruby
|
209
206
|
class Product < ActiveRecord::Base
|
@@ -329,6 +326,8 @@ heroku run rake searchkick:reindex CLASS=Product
|
|
329
326
|
|
330
327
|
## Reference
|
331
328
|
|
329
|
+
Searchkick requires Elasticsearch `0.90.0` or higher.
|
330
|
+
|
332
331
|
Reindex one record
|
333
332
|
|
334
333
|
```ruby
|
@@ -336,6 +335,12 @@ product = Product.find 10
|
|
336
335
|
product.reindex
|
337
336
|
```
|
338
337
|
|
338
|
+
Remove old indices
|
339
|
+
|
340
|
+
```ruby
|
341
|
+
Product.clean_indices
|
342
|
+
```
|
343
|
+
|
339
344
|
Use a different index name
|
340
345
|
|
341
346
|
```ruby
|
data/lib/searchkick/reindex.rb
CHANGED
@@ -17,28 +17,32 @@ module Searchkick
|
|
17
17
|
end
|
18
18
|
|
19
19
|
if a = Tire::Alias.find(alias_name)
|
20
|
-
|
21
|
-
old_indices.each do |index|
|
20
|
+
a.indices.each do |index|
|
22
21
|
a.indices.delete index
|
23
22
|
end
|
24
23
|
|
25
24
|
a.indices.add new_index
|
26
25
|
response = a.save
|
27
26
|
|
28
|
-
if response.success?
|
29
|
-
old_indices.each do |index|
|
30
|
-
i = Tire::Index.new(index)
|
31
|
-
i.delete
|
32
|
-
end
|
33
|
-
end
|
27
|
+
clean_indices if response.success?
|
34
28
|
else
|
35
|
-
tire.index.delete
|
29
|
+
tire.index.delete if tire.index.exists?
|
36
30
|
response = Tire::Alias.create(name: alias_name, indices: [new_index])
|
37
31
|
end
|
38
32
|
|
39
33
|
response.success? || (raise response.to_s)
|
40
34
|
end
|
41
35
|
|
36
|
+
# remove old indices that start w/ index_name
|
37
|
+
def clean_indices
|
38
|
+
all_indices = JSON.parse(Tire::Configuration.client.get("#{Tire::Configuration.url}/_aliases").body)
|
39
|
+
indices = all_indices.select{|k, v| v["aliases"].empty? && k =~ /\A#{Regexp.escape(index_name)}_\d{14}\z/ }.keys
|
40
|
+
indices.each do |index|
|
41
|
+
Tire::Index.new(index).delete
|
42
|
+
end
|
43
|
+
indices
|
44
|
+
end
|
45
|
+
|
42
46
|
private
|
43
47
|
|
44
48
|
def searchkick_index_options
|
data/lib/searchkick/search.rb
CHANGED
@@ -52,10 +52,10 @@ module Searchkick
|
|
52
52
|
match fields, term, use_dis_max: false, boost: 10, operator: operator, analyzer: "searchkick_search2"
|
53
53
|
end
|
54
54
|
query do
|
55
|
-
match fields, term, use_dis_max: false, fuzziness: 1, max_expansions:
|
55
|
+
match fields, term, use_dis_max: false, fuzziness: 1, max_expansions: 3, operator: operator, analyzer: "searchkick_search"
|
56
56
|
end
|
57
57
|
query do
|
58
|
-
match fields, term, use_dis_max: false, fuzziness: 1, max_expansions:
|
58
|
+
match fields, term, use_dis_max: false, fuzziness: 1, max_expansions: 3, operator: operator, analyzer: "searchkick_search2"
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
data/lib/searchkick/version.rb
CHANGED
data/test/index_test.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class TestIndex < Minitest::Unit::TestCase
|
4
|
+
|
5
|
+
def test_clean_indices
|
6
|
+
old_index = Tire::Index.new("products_development_20130801000000")
|
7
|
+
different_index = Tire::Index.new("items_development_20130801000000")
|
8
|
+
|
9
|
+
# create indexes
|
10
|
+
old_index.create
|
11
|
+
different_index.create
|
12
|
+
|
13
|
+
Product.clean_indices
|
14
|
+
|
15
|
+
assert Product.index.exists?
|
16
|
+
assert different_index.exists?
|
17
|
+
assert !old_index.exists?
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/test/match_test.rb
CHANGED
@@ -60,6 +60,11 @@ class TestMatch < Minitest::Unit::TestCase
|
|
60
60
|
assert_search "siracha", ["Sriracha"]
|
61
61
|
end
|
62
62
|
|
63
|
+
def test_misspelling_multiple
|
64
|
+
store_names ["Greek Yogurt", "Green Onions"]
|
65
|
+
assert_search "greed", ["Greek Yogurt", "Green Onions"]
|
66
|
+
end
|
67
|
+
|
63
68
|
def test_short_word
|
64
69
|
store_names ["Finn"]
|
65
70
|
assert_search "fin", ["Finn"]
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tire
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- searchkick.gemspec
|
132
132
|
- test/boost_test.rb
|
133
133
|
- test/facets_test.rb
|
134
|
+
- test/index_test.rb
|
134
135
|
- test/match_test.rb
|
135
136
|
- test/sql_test.rb
|
136
137
|
- test/suggest_test.rb
|
@@ -163,6 +164,7 @@ summary: Search made easy
|
|
163
164
|
test_files:
|
164
165
|
- test/boost_test.rb
|
165
166
|
- test/facets_test.rb
|
167
|
+
- test/index_test.rb
|
166
168
|
- test/match_test.rb
|
167
169
|
- test/sql_test.rb
|
168
170
|
- test/suggest_test.rb
|