searchkick 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +42 -12
- data/lib/searchkick.rb +13 -1
- data/lib/searchkick/index.rb +0 -1
- data/lib/searchkick/index_options.rb +1 -1
- data/lib/searchkick/query.rb +15 -13
- data/lib/searchkick/version.rb +1 -1
- data/test/synonyms_test.rb +8 -0
- data/test/test_helper.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 777b21bb34049337d1ee1c20fcf51eeaf94ab604
|
4
|
+
data.tar.gz: 9219dfb5026333d38ce0486f5dbee7d2b3d54838
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9461e485b83ecf1169e9bb305c5296e9484d8bfc6b141b204b9870698cd8efe3f79a43687758c87ed390ba9bf15bcec227111a3ed3075d1aceb71bca38093b0d
|
7
|
+
data.tar.gz: 85c318dae06729ff723e27dcbcf19906f09418d7b90d7a00bfd7ad50f20a3e6f860faedbeb4d486809b47bf8ac687afb7c8e87b7917d5bddc0686f04fef756f5
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -285,6 +285,35 @@ end
|
|
285
285
|
|
286
286
|
Call `Product.reindex` after changing synonyms.
|
287
287
|
|
288
|
+
For directional synonyms, use:
|
289
|
+
|
290
|
+
```ruby
|
291
|
+
synonyms: ["lightbulb => halogenlamp"]
|
292
|
+
```
|
293
|
+
|
294
|
+
### Tags and Dynamic Synonyms
|
295
|
+
|
296
|
+
The above approach works well when your synonym list is static, but in practice, this is often not the case. When you analyze search conversions, you often want to add new synonyms or tags without a full reindex. You can use a library like [ActsAsTaggableOn](https://github.com/mbleigh/acts-as-taggable-on) and do:
|
297
|
+
|
298
|
+
```ruby
|
299
|
+
class Product < ActiveRecord::Base
|
300
|
+
acts_as_taggable
|
301
|
+
scope :search_import, -> { includes(:tags) }
|
302
|
+
|
303
|
+
def search_data
|
304
|
+
{
|
305
|
+
name_tagged: "#{name} #{tags.map(&:name).join(" ")}"
|
306
|
+
}
|
307
|
+
end
|
308
|
+
end
|
309
|
+
```
|
310
|
+
|
311
|
+
Search with:
|
312
|
+
|
313
|
+
```ruby
|
314
|
+
Product.search query, fields: [:name_tagged]
|
315
|
+
```
|
316
|
+
|
288
317
|
### WordNet
|
289
318
|
|
290
319
|
Prepopulate English synonyms with the [WordNet database](https://en.wikipedia.org/wiki/WordNet).
|
@@ -930,6 +959,14 @@ Dog.search "airbudd", suggest: true # suggestions for all animals
|
|
930
959
|
|
931
960
|
## Debugging Queries
|
932
961
|
|
962
|
+
To help with debugging queries, you can use:
|
963
|
+
|
964
|
+
```ruby
|
965
|
+
Product.search("soap", debug: true)
|
966
|
+
```
|
967
|
+
|
968
|
+
This prints useful info to `stdout`.
|
969
|
+
|
933
970
|
See how Elasticsearch scores your queries with:
|
934
971
|
|
935
972
|
```ruby
|
@@ -1012,18 +1049,11 @@ gem 'faraday_middleware-aws-signers-v4'
|
|
1012
1049
|
and add to your initializer:
|
1013
1050
|
|
1014
1051
|
```ruby
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
) do |f|
|
1021
|
-
f.request :aws_signers_v4, {
|
1022
|
-
credentials: Aws::Credentials.new(ENV["AWS_ACCESS_KEY_ID"], ENV["AWS_SECRET_ACCESS_KEY"]),
|
1023
|
-
service_name: "es",
|
1024
|
-
region: "us-east-1"
|
1025
|
-
}
|
1026
|
-
end
|
1052
|
+
Searchkick.aws_credentials = {
|
1053
|
+
access_key_id: ENV["AWS_ACCESS_KEY_ID"],
|
1054
|
+
secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
|
1055
|
+
region: "us-east-1"
|
1056
|
+
}
|
1027
1057
|
```
|
1028
1058
|
|
1029
1059
|
Then deploy and reindex:
|
data/lib/searchkick.rb
CHANGED
@@ -31,6 +31,7 @@ module Searchkick
|
|
31
31
|
class << self
|
32
32
|
attr_accessor :search_method_name, :wordnet_path, :timeout, :models
|
33
33
|
attr_writer :client, :env, :search_timeout
|
34
|
+
attr_reader :aws_credentials
|
34
35
|
end
|
35
36
|
self.search_method_name = :search
|
36
37
|
self.wordnet_path = "/var/lib/wn_s.pl"
|
@@ -46,6 +47,11 @@ module Searchkick
|
|
46
47
|
transport_options: {request: {timeout: timeout}, headers: {content_type: "application/json"}}
|
47
48
|
) do |f|
|
48
49
|
f.use Searchkick::Middleware
|
50
|
+
f.request :aws_signers_v4, {
|
51
|
+
credentials: Aws::Credentials.new(aws_credentials[:access_key_id], aws_credentials[:secret_access_key]),
|
52
|
+
service_name: "es",
|
53
|
+
region: aws_credentials[:region] || "us-east-1"
|
54
|
+
} if aws_credentials
|
49
55
|
end
|
50
56
|
end
|
51
57
|
end
|
@@ -93,6 +99,12 @@ module Searchkick
|
|
93
99
|
end
|
94
100
|
end
|
95
101
|
|
102
|
+
def self.aws_credentials=(creds)
|
103
|
+
require "faraday_middleware/aws_signers_v4"
|
104
|
+
@aws_credentials = creds
|
105
|
+
@client = nil # reset client
|
106
|
+
end
|
107
|
+
|
96
108
|
# private
|
97
109
|
def self.queue_items(items)
|
98
110
|
queued_items.concat(items)
|
@@ -112,7 +124,7 @@ module Searchkick
|
|
112
124
|
response = client.bulk(body: items)
|
113
125
|
if response["errors"]
|
114
126
|
first_with_error = response["items"].map do |item|
|
115
|
-
(item["index"] || item["delete"])
|
127
|
+
(item["index"] || item["delete"] || item["update"])
|
116
128
|
end.find { |item| item["error"] }
|
117
129
|
raise Searchkick::ImportError, "#{first_with_error["error"]} on item with id '#{first_with_error["_id"]}'"
|
118
130
|
end
|
data/lib/searchkick/index.rb
CHANGED
@@ -179,7 +179,7 @@ module Searchkick
|
|
179
179
|
if synonyms.any?
|
180
180
|
settings[:analysis][:filter][:searchkick_synonym] = {
|
181
181
|
type: "synonym",
|
182
|
-
synonyms: synonyms.select { |s| s.size > 1 }.map { |s| s.join(",") }
|
182
|
+
synonyms: synonyms.select { |s| s.size > 1 }.map { |s| s.is_a?(Array) ? s.join(",") : s }
|
183
183
|
}
|
184
184
|
# choosing a place for the synonym filter when stemming is not easy
|
185
185
|
# https://groups.google.com/forum/#!topic/elasticsearch/p7qcQlgHdB8
|
data/lib/searchkick/query.rb
CHANGED
@@ -132,21 +132,23 @@ module Searchkick
|
|
132
132
|
pp options
|
133
133
|
puts
|
134
134
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
135
|
+
if searchkick_index
|
136
|
+
puts "Model Search Data"
|
137
|
+
begin
|
138
|
+
pp klass.first(3).map { |r| {index: searchkick_index.record_data(r).merge(data: searchkick_index.send(:search_data, r))}}
|
139
|
+
rescue => e
|
140
|
+
puts "#{e.class.name}: #{e.message}"
|
141
|
+
end
|
142
|
+
puts
|
142
143
|
|
143
|
-
|
144
|
-
|
145
|
-
|
144
|
+
puts "Elasticsearch Mapping"
|
145
|
+
puts JSON.pretty_generate(searchkick_index.mapping)
|
146
|
+
puts
|
146
147
|
|
147
|
-
|
148
|
-
|
149
|
-
|
148
|
+
puts "Elasticsearch Settings"
|
149
|
+
puts JSON.pretty_generate(searchkick_index.settings)
|
150
|
+
puts
|
151
|
+
end
|
150
152
|
|
151
153
|
puts "Elasticsearch Query"
|
152
154
|
puts to_curl
|
data/lib/searchkick/version.rb
CHANGED
data/test/synonyms_test.rb
CHANGED
@@ -51,4 +51,12 @@ class SynonymsTest < Minitest::Test
|
|
51
51
|
store_names ["Creature", "Beast", "Dragon"], Animal
|
52
52
|
assert_search "animal", ["Creature", "Beast"], {}, Animal
|
53
53
|
end
|
54
|
+
|
55
|
+
def test_directional
|
56
|
+
store_names ["Lightbulb", "Green Onions", "Led"]
|
57
|
+
assert_search "led", ["Lightbulb", "Led"]
|
58
|
+
assert_search "Lightbulb", ["Lightbulb"]
|
59
|
+
assert_search "Halogen Lamp", ["Lightbulb"]
|
60
|
+
assert_search "onions", ["Green Onions"]
|
61
|
+
end
|
54
62
|
end
|
data/test/test_helper.rb
CHANGED
@@ -273,7 +273,9 @@ class Product
|
|
273
273
|
["saranwrap", "plasticwrap"],
|
274
274
|
["qtip", "cottonswab"],
|
275
275
|
["burger", "hamburger"],
|
276
|
-
["bandaid", "bandag"]
|
276
|
+
["bandaid", "bandag"],
|
277
|
+
"lightbulb => led,lightbulb",
|
278
|
+
"lightbulb => halogenlamp"
|
277
279
|
],
|
278
280
|
autocomplete: [:name],
|
279
281
|
suggest: [:name, :color],
|
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: 1.4.
|
4
|
+
version: 1.4.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: 2016-12-
|
11
|
+
date: 2016-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|