searchkick 2.2.1 → 2.3.0
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/.travis.yml +3 -2
- data/CHANGELOG.md +8 -0
- data/Gemfile +1 -1
- data/README.md +24 -6
- data/lib/searchkick/index_options.rb +6 -4
- data/lib/searchkick/query.rb +17 -4
- data/lib/searchkick/reindex_v2_job.rb +1 -1
- data/lib/searchkick/version.rb +1 -1
- data/lib/searchkick.rb +6 -2
- data/test/errors_test.rb +2 -2
- data/test/gemfiles/{activerecord51.gemfile → activerecord50.gemfile} +1 -1
- data/test/match_test.rb +5 -0
- data/test/synonyms_test.rb +5 -0
- data/test/test_helper.rb +1 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92b9786d3ffe96d4accab83ae00accbaa5b2ffb3
|
4
|
+
data.tar.gz: 9b60f5ab8f709d9138cbe4823b14d29a06e4aa77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8e3324376e90052bbf854fe3d04200857d06ac6cde06bea08ee2fe573462de243d558ed1d0592d92b7794d5c1fd761f396812c4ea09ff5fce1e30cdac2119a8
|
7
|
+
data.tar.gz: c5bc1d098f59c17945af081727ef92cd7d297cfebe3f0acd1c5401dd95bca71a208c10208b07f7d473e9e387fc37f4643c8dc9b373dec2006c4507f30c598808
|
data/.travis.yml
CHANGED
@@ -6,7 +6,7 @@ services:
|
|
6
6
|
- redis-server
|
7
7
|
before_install:
|
8
8
|
- ./test/ci/before_install.sh
|
9
|
-
script:
|
9
|
+
script: bundle exec rake test
|
10
10
|
before_script:
|
11
11
|
- psql -c 'create database searchkick_test;' -U postgres
|
12
12
|
notifications:
|
@@ -15,11 +15,12 @@ notifications:
|
|
15
15
|
on_failure: change
|
16
16
|
gemfile:
|
17
17
|
- Gemfile
|
18
|
+
- test/gemfiles/activerecord50.gemfile
|
18
19
|
- test/gemfiles/activerecord42.gemfile
|
19
20
|
- test/gemfiles/mongoid5.gemfile
|
20
21
|
- test/gemfiles/mongoid6.gemfile
|
21
22
|
env:
|
22
|
-
- ELASTICSEARCH_VERSION=5.
|
23
|
+
- ELASTICSEARCH_VERSION=5.4.0
|
23
24
|
jdk: oraclejdk8
|
24
25
|
matrix:
|
25
26
|
include:
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 2.3.0
|
2
|
+
|
3
|
+
- Fixed analyzer on dynamically mapped fields
|
4
|
+
- Fixed error with `similar` method and `_all` field
|
5
|
+
- Throw error when fields are needed
|
6
|
+
- Added `queue_name` option
|
7
|
+
- No longer require synonyms to be lowercase
|
8
|
+
|
1
9
|
## 2.2.1
|
2
10
|
|
3
11
|
- Added `avg`, `cardinality`, `max`, `min`, and `sum` aggregations
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -27,8 +27,6 @@ Plus:
|
|
27
27
|
|
28
28
|
[](https://travis-ci.org/ankane/searchkick)
|
29
29
|
|
30
|
-
**Searchkick 2.0 was just released!** See [notable changes](#200).
|
31
|
-
|
32
30
|
## Contents
|
33
31
|
|
34
32
|
- [Getting Started](#getting-started)
|
@@ -1606,12 +1604,18 @@ Set a lower timeout for searches
|
|
1606
1604
|
Searchkick.search_timeout = 3
|
1607
1605
|
```
|
1608
1606
|
|
1609
|
-
Change the search method name
|
1607
|
+
Change the search method name
|
1610
1608
|
|
1611
1609
|
```ruby
|
1612
1610
|
Searchkick.search_method_name = :lookup
|
1613
1611
|
```
|
1614
1612
|
|
1613
|
+
Change search queue name
|
1614
|
+
|
1615
|
+
```ruby
|
1616
|
+
Searchkick.queue_name = :search_reindex
|
1617
|
+
```
|
1618
|
+
|
1615
1619
|
Eager load associations
|
1616
1620
|
|
1617
1621
|
```ruby
|
@@ -1763,11 +1767,25 @@ end
|
|
1763
1767
|
|
1764
1768
|
### Factory Girl
|
1765
1769
|
|
1766
|
-
|
1770
|
+
Use a trait and an after `create` hook for each indexed model:
|
1767
1771
|
|
1768
1772
|
```ruby
|
1769
|
-
|
1770
|
-
product
|
1773
|
+
FactoryGirl.define do
|
1774
|
+
factory :product do
|
1775
|
+
# ...
|
1776
|
+
|
1777
|
+
# Note: This should be the last trait in the list so `reindex` is called
|
1778
|
+
# after all the other callbacks complete.
|
1779
|
+
trait :reindex do
|
1780
|
+
after(:create) do |product, _evaluator|
|
1781
|
+
product.reindex(refresh: true)
|
1782
|
+
end
|
1783
|
+
end
|
1784
|
+
end
|
1785
|
+
end
|
1786
|
+
|
1787
|
+
# use it
|
1788
|
+
FactoryGirl.create(:product, :some_trait, :reindex, some_attribute: "foo")
|
1771
1789
|
```
|
1772
1790
|
|
1773
1791
|
### Parallel Tests
|
@@ -167,7 +167,7 @@ module Searchkick
|
|
167
167
|
if synonyms.any?
|
168
168
|
settings[:analysis][:filter][:searchkick_synonym] = {
|
169
169
|
type: "synonym",
|
170
|
-
synonyms: synonyms.select { |s| s.size > 1 }.map { |s| s.is_a?(Array) ? s.join(",") : s }
|
170
|
+
synonyms: synonyms.select { |s| s.size > 1 }.map { |s| s.is_a?(Array) ? s.join(",") : s }.map(&:downcase)
|
171
171
|
}
|
172
172
|
# choosing a place for the synonym filter when stemming is not easy
|
173
173
|
# https://groups.google.com/forum/#!topic/elasticsearch/p7qcQlgHdB8
|
@@ -229,6 +229,8 @@ module Searchkick
|
|
229
229
|
|
230
230
|
mapping_options[:searchable].delete("_all")
|
231
231
|
|
232
|
+
analyzed_field_options = {type: default_type, index: "analyzed", analyzer: default_analyzer}
|
233
|
+
|
232
234
|
mapping_options.values.flatten.uniq.each do |field|
|
233
235
|
fields = {}
|
234
236
|
|
@@ -240,7 +242,7 @@ module Searchkick
|
|
240
242
|
|
241
243
|
if !options[:searchable] || mapping_options[:searchable].include?(field)
|
242
244
|
if word
|
243
|
-
fields["analyzed"] =
|
245
|
+
fields["analyzed"] = analyzed_field_options
|
244
246
|
|
245
247
|
if mapping_options[:highlight].include?(field)
|
246
248
|
fields["analyzed"][:term_vector] = "with_positions_offsets"
|
@@ -294,7 +296,7 @@ module Searchkick
|
|
294
296
|
end
|
295
297
|
|
296
298
|
if word
|
297
|
-
dynamic_fields["analyzed"] =
|
299
|
+
dynamic_fields["analyzed"] = analyzed_field_options
|
298
300
|
end
|
299
301
|
end
|
300
302
|
|
@@ -305,7 +307,7 @@ module Searchkick
|
|
305
307
|
|
306
308
|
mappings = {
|
307
309
|
_default_: {
|
308
|
-
_all: all_enabled ?
|
310
|
+
_all: all_enabled ? analyzed_field_options : {enabled: false},
|
309
311
|
properties: mapping,
|
310
312
|
_routing: routing,
|
311
313
|
# https://gist.github.com/kimchy/2898285
|
data/lib/searchkick/query.rb
CHANGED
@@ -223,13 +223,15 @@ module Searchkick
|
|
223
223
|
if options[:similar]
|
224
224
|
payload = {
|
225
225
|
more_like_this: {
|
226
|
-
fields: fields,
|
227
226
|
like_text: term,
|
228
227
|
min_doc_freq: 1,
|
229
228
|
min_term_freq: 1,
|
230
229
|
analyzer: "searchkick_search2"
|
231
230
|
}
|
232
231
|
}
|
232
|
+
if fields != ["_all"]
|
233
|
+
payload[:more_like_this][:fields] = fields
|
234
|
+
end
|
233
235
|
elsif all
|
234
236
|
payload = {
|
235
237
|
match_all: {}
|
@@ -277,7 +279,13 @@ module Searchkick
|
|
277
279
|
|
278
280
|
match_type =
|
279
281
|
if field.end_with?(".phrase")
|
280
|
-
field =
|
282
|
+
field =
|
283
|
+
if field == "_all.phrase"
|
284
|
+
"_all"
|
285
|
+
else
|
286
|
+
field.sub(/\.phrase\z/, ".analyzed")
|
287
|
+
end
|
288
|
+
|
281
289
|
:match_phrase
|
282
290
|
else
|
283
291
|
:match
|
@@ -482,17 +490,22 @@ module Searchkick
|
|
482
490
|
def set_fields
|
483
491
|
boost_fields = {}
|
484
492
|
fields = options[:fields] || searchkick_options[:searchable]
|
493
|
+
default_match = options[:match] || searchkick_options[:match] || :word
|
485
494
|
fields =
|
486
495
|
if fields
|
487
496
|
fields.map do |value|
|
488
|
-
k, v = value.is_a?(Hash) ? value.to_a.first : [value,
|
497
|
+
k, v = value.is_a?(Hash) ? value.to_a.first : [value, default_match]
|
489
498
|
k2, boost = k.to_s.split("^", 2)
|
490
499
|
field = "#{k2}.#{v == :word ? 'analyzed' : v}"
|
491
500
|
boost_fields[field] = boost.to_f if boost
|
492
501
|
field
|
493
502
|
end
|
494
|
-
|
503
|
+
elsif default_match == :word
|
495
504
|
["_all"]
|
505
|
+
elsif default_match == :phrase
|
506
|
+
["_all.phrase"]
|
507
|
+
else
|
508
|
+
raise ArgumentError, "Must specify fields"
|
496
509
|
end
|
497
510
|
[boost_fields, fields]
|
498
511
|
end
|
data/lib/searchkick/version.rb
CHANGED
data/lib/searchkick.rb
CHANGED
@@ -36,7 +36,7 @@ module Searchkick
|
|
36
36
|
class ImportError < Error; end
|
37
37
|
|
38
38
|
class << self
|
39
|
-
attr_accessor :search_method_name, :wordnet_path, :timeout, :models, :client_options, :redis, :index_suffix
|
39
|
+
attr_accessor :search_method_name, :wordnet_path, :timeout, :models, :client_options, :redis, :index_suffix, :queue_name
|
40
40
|
attr_writer :client, :env, :search_timeout
|
41
41
|
attr_reader :aws_credentials
|
42
42
|
end
|
@@ -45,6 +45,7 @@ module Searchkick
|
|
45
45
|
self.timeout = 10
|
46
46
|
self.models = []
|
47
47
|
self.client_options = {}
|
48
|
+
self.queue_name = :searchkick
|
48
49
|
|
49
50
|
def self.client
|
50
51
|
@client ||= begin
|
@@ -206,4 +207,7 @@ end
|
|
206
207
|
|
207
208
|
# TODO find better ActiveModel hook
|
208
209
|
ActiveModel::Callbacks.send(:include, Searchkick::Model)
|
209
|
-
|
210
|
+
|
211
|
+
ActiveSupport.on_load(:active_record) do
|
212
|
+
extend Searchkick::Model
|
213
|
+
end
|
data/test/errors_test.rb
CHANGED
@@ -2,8 +2,8 @@ require_relative "test_helper"
|
|
2
2
|
|
3
3
|
class ErrorsTest < Minitest::Test
|
4
4
|
def test_bulk_import_raises_error
|
5
|
-
valid_dog = Product.
|
6
|
-
invalid_dog = Product.
|
5
|
+
valid_dog = Product.create(name: "2016-01-02")
|
6
|
+
invalid_dog = Product.create(name: "Ol' One-Leg")
|
7
7
|
index = Searchkick::Index.new "dogs", mappings: {
|
8
8
|
dog: {
|
9
9
|
properties: {
|
data/test/match_test.rb
CHANGED
@@ -243,6 +243,11 @@ class MatchTest < Minitest::Test
|
|
243
243
|
assert_order "wheat bread", ["Wheat Bread", "Whole Wheat Bread"], match: :phrase
|
244
244
|
end
|
245
245
|
|
246
|
+
def test_dynamic_fields
|
247
|
+
store_names ["Red Bull"], Speaker
|
248
|
+
assert_search "redbull", ["Red Bull"], {fields: [:name]}, Speaker
|
249
|
+
end
|
250
|
+
|
246
251
|
def test_unsearchable
|
247
252
|
store [
|
248
253
|
{name: "Unsearchable", description: "Almond"}
|
data/test/synonyms_test.rb
CHANGED
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: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -138,7 +138,7 @@ files:
|
|
138
138
|
- test/gemfiles/activerecord40.gemfile
|
139
139
|
- test/gemfiles/activerecord41.gemfile
|
140
140
|
- test/gemfiles/activerecord42.gemfile
|
141
|
-
- test/gemfiles/
|
141
|
+
- test/gemfiles/activerecord50.gemfile
|
142
142
|
- test/gemfiles/apartment.gemfile
|
143
143
|
- test/gemfiles/cequel.gemfile
|
144
144
|
- test/gemfiles/mongoid2.gemfile
|
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
193
|
version: '0'
|
194
194
|
requirements: []
|
195
195
|
rubyforge_project:
|
196
|
-
rubygems_version: 2.6.
|
196
|
+
rubygems_version: 2.6.11
|
197
197
|
signing_key:
|
198
198
|
specification_version: 4
|
199
199
|
summary: Searchkick learns what your users are looking for. As more people search,
|
@@ -213,7 +213,7 @@ test_files:
|
|
213
213
|
- test/gemfiles/activerecord40.gemfile
|
214
214
|
- test/gemfiles/activerecord41.gemfile
|
215
215
|
- test/gemfiles/activerecord42.gemfile
|
216
|
-
- test/gemfiles/
|
216
|
+
- test/gemfiles/activerecord50.gemfile
|
217
217
|
- test/gemfiles/apartment.gemfile
|
218
218
|
- test/gemfiles/cequel.gemfile
|
219
219
|
- test/gemfiles/mongoid2.gemfile
|