searchkick 3.1.2 → 3.1.3
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/CHANGELOG.md +9 -0
- data/LICENSE.txt +1 -1
- data/README.md +0 -15
- data/lib/searchkick.rb +10 -22
- data/lib/searchkick/index.rb +11 -6
- data/lib/searchkick/index_options.rb +26 -6
- data/lib/searchkick/query.rb +12 -2
- data/lib/searchkick/railtie.rb +7 -0
- data/lib/searchkick/record_data.rb +2 -2
- data/lib/searchkick/version.rb +1 -1
- data/lib/{searchkick/tasks.rb → tasks/searchkick.rake} +8 -10
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fb08ed2716d410bb1d609e873e10387a97e437a6bb63530687998a5b9539e13
|
4
|
+
data.tar.gz: f0b43190746e1d841643b1fc45ef8cd86621b42970369cb2c5fb5f02396ca432
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a15444ee63e976df8b85dfb5c5462f48525cd7eb102dc4d0f156e92937223d2cae116c66019821009291bbaeaad56449bf145861c47fa2b729c13e6cf9cf13ac
|
7
|
+
data.tar.gz: cff5bee77c65345926199f94ba975db417bbbdcca5cfa7647e004b99c5f7aba3965da700a039f7bd1906d91734de98edcc178dcebfe303a4fa8b7b67bdd3e1dd
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 3.1.3
|
2
|
+
|
3
|
+
- Added support for endless ranges
|
4
|
+
- Added support for routing to `similar` method
|
5
|
+
- Added `prefix` to `where`
|
6
|
+
- Fixed error with elasticsearch-ruby 6.3
|
7
|
+
- Fixed error with some language stemmers and Elasticsearch 6.5
|
8
|
+
- Fixed issue with misspellings below and body block
|
9
|
+
|
1
10
|
## 3.1.2
|
2
11
|
|
3
12
|
- Improved performance of indices boost
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -22,18 +22,10 @@ Plus:
|
|
22
22
|
- supports many languages
|
23
23
|
- works with ActiveRecord, Mongoid, and NoBrainer
|
24
24
|
|
25
|
-
:speech_balloon: Get [handcrafted updates](https://chartkick.us7.list-manage.com/subscribe?u=952c861f99eb43084e0a49f98&id=6ea6541e8e&group[0][4]=true) for new features
|
26
|
-
|
27
25
|
:tangerine: Battle-tested at [Instacart](https://www.instacart.com/opensource)
|
28
26
|
|
29
27
|
[](https://travis-ci.org/ankane/searchkick)
|
30
28
|
|
31
|
-
---
|
32
|
-
|
33
|
-
Does your company use Searchkick? Want free advising? Fill out [this application](https://goo.gl/forms/Or1HQTRb2rgQCNtd2)
|
34
|
-
|
35
|
-
---
|
36
|
-
|
37
29
|
## Contents
|
38
30
|
|
39
31
|
- [Getting Started](#getting-started)
|
@@ -1461,8 +1453,6 @@ And use the `body` option to search:
|
|
1461
1453
|
products = Product.search body: {query: {match: {name: "milk"}}}
|
1462
1454
|
```
|
1463
1455
|
|
1464
|
-
**Note:** This replaces the entire body, so other options are ignored.
|
1465
|
-
|
1466
1456
|
View the response with:
|
1467
1457
|
|
1468
1458
|
```ruby
|
@@ -1963,11 +1953,6 @@ View the [changelog](https://github.com/ankane/searchkick/blob/master/CHANGELOG.
|
|
1963
1953
|
|
1964
1954
|
Thanks to Karel Minarik for [Elasticsearch Ruby](https://github.com/elasticsearch/elasticsearch-ruby) and [Tire](https://github.com/karmi/retire), Jaroslav Kalistsuk for [zero downtime reindexing](https://gist.github.com/jarosan/3124884), and Alex Leschenko for [Elasticsearch autocomplete](https://github.com/leschenko/elasticsearch_autocomplete).
|
1965
1955
|
|
1966
|
-
## Roadmap
|
1967
|
-
|
1968
|
-
- Reindex API
|
1969
|
-
- Incorporate human eval
|
1970
|
-
|
1971
1956
|
## Contributing
|
1972
1957
|
|
1973
1958
|
Everyone is encouraged to help improve this project. Here are a few ways you can help:
|
data/lib/searchkick.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "active_support"
|
2
2
|
require "active_support/core_ext/hash/deep_merge"
|
3
3
|
require "elasticsearch"
|
4
4
|
require "hashie"
|
@@ -17,29 +17,16 @@ require "searchkick/record_indexer"
|
|
17
17
|
require "searchkick/results"
|
18
18
|
require "searchkick/version"
|
19
19
|
|
20
|
+
require "searchkick/railtie" if defined?(Rails)
|
20
21
|
require "searchkick/logging" if defined?(ActiveSupport::Notifications)
|
21
22
|
|
22
|
-
begin
|
23
|
-
require "rake"
|
24
|
-
rescue LoadError
|
25
|
-
# do nothing
|
26
|
-
end
|
27
|
-
require "searchkick/tasks" if defined?(Rake)
|
28
|
-
|
29
|
-
# background jobs
|
30
|
-
begin
|
31
|
-
require "active_job"
|
32
|
-
rescue LoadError
|
33
|
-
# do nothing
|
34
|
-
end
|
35
|
-
if defined?(ActiveJob)
|
36
|
-
require "searchkick/bulk_reindex_job"
|
37
|
-
require "searchkick/process_batch_job"
|
38
|
-
require "searchkick/process_queue_job"
|
39
|
-
require "searchkick/reindex_v2_job"
|
40
|
-
end
|
41
|
-
|
42
23
|
module Searchkick
|
24
|
+
# background jobs
|
25
|
+
autoload :BulkReindexJob, "searchkick/bulk_reindex_job"
|
26
|
+
autoload :ProcessBatchJob, "searchkick/process_batch_job"
|
27
|
+
autoload :ProcessQueueJob, "searchkick/process_queue_job"
|
28
|
+
autoload :ReindexV2Job, "searchkick/reindex_v2_job"
|
29
|
+
|
43
30
|
class Error < StandardError; end
|
44
31
|
class MissingIndexError < Error; end
|
45
32
|
class UnsupportedVersionError < Error; end
|
@@ -104,8 +91,8 @@ module Searchkick
|
|
104
91
|
end
|
105
92
|
end
|
106
93
|
|
94
|
+
options = options.merge(block: block) if block
|
107
95
|
query = Searchkick::Query.new(klass, term, options)
|
108
|
-
block.call(query.body) if block
|
109
96
|
if options[:execute] == false
|
110
97
|
query
|
111
98
|
else
|
@@ -241,6 +228,7 @@ module Searchkick
|
|
241
228
|
end
|
242
229
|
|
243
230
|
# TODO find better ActiveModel hook
|
231
|
+
require "active_model/callbacks"
|
244
232
|
ActiveModel::Callbacks.include(Searchkick::Model)
|
245
233
|
|
246
234
|
ActiveSupport.on_load(:active_record) do
|
data/lib/searchkick/index.rb
CHANGED
@@ -91,17 +91,22 @@ module Searchkick
|
|
91
91
|
alias_method :swap, :promote
|
92
92
|
|
93
93
|
def retrieve(record)
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
94
|
+
record_data = RecordData.new(self, record).record_data
|
95
|
+
|
96
|
+
# remove underscore
|
97
|
+
get_options = Hash[record_data.map { |k, v| [k.to_s.sub(/\A_/, "").to_sym, v] }]
|
98
|
+
|
99
|
+
client.get(get_options)["_source"]
|
99
100
|
end
|
100
101
|
|
101
102
|
def all_indices(unaliased: false)
|
102
103
|
indices =
|
103
104
|
begin
|
104
|
-
client.indices.
|
105
|
+
if client.indices.respond_to?(:get_alias)
|
106
|
+
client.indices.get_alias
|
107
|
+
else
|
108
|
+
client.indices.get_aliases
|
109
|
+
end
|
105
110
|
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
106
111
|
{}
|
107
112
|
end
|
@@ -40,19 +40,19 @@ module Searchkick
|
|
40
40
|
tokenizer: "standard",
|
41
41
|
# synonym should come last, after stemming and shingle
|
42
42
|
# shingle must come before searchkick_stemmer
|
43
|
-
filter: ["
|
43
|
+
filter: ["lowercase", "asciifolding", "searchkick_index_shingle", "searchkick_stemmer"]
|
44
44
|
},
|
45
45
|
searchkick_search: {
|
46
46
|
type: "custom",
|
47
47
|
char_filter: ["ampersand"],
|
48
48
|
tokenizer: "standard",
|
49
|
-
filter: ["
|
49
|
+
filter: ["lowercase", "asciifolding", "searchkick_search_shingle", "searchkick_stemmer"]
|
50
50
|
},
|
51
51
|
searchkick_search2: {
|
52
52
|
type: "custom",
|
53
53
|
char_filter: ["ampersand"],
|
54
54
|
tokenizer: "standard",
|
55
|
-
filter: ["
|
55
|
+
filter: ["lowercase", "asciifolding", "searchkick_stemmer"]
|
56
56
|
},
|
57
57
|
# https://github.com/leschenko/elasticsearch_autocomplete/blob/master/lib/elasticsearch_autocomplete/analyzers.rb
|
58
58
|
searchkick_autocomplete_search: {
|
@@ -144,6 +144,17 @@ module Searchkick
|
|
144
144
|
}
|
145
145
|
}
|
146
146
|
|
147
|
+
if below60
|
148
|
+
# ES docs say standard token filter does nothing in ES 5
|
149
|
+
# (and therefore isn't needed at at), but tests say otherwise
|
150
|
+
# https://www.elastic.co/guide/en/elasticsearch/reference/5.0/analysis-standard-tokenfilter.html
|
151
|
+
[default_analyzer, :searchkick_search, :searchkick_search2].each do |analyzer|
|
152
|
+
settings[:analysis][:analyzer][analyzer][:filter].unshift("standard")
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
stem = options[:stem]
|
157
|
+
|
147
158
|
case language
|
148
159
|
when "chinese"
|
149
160
|
settings[:analysis][:analyzer].merge!(
|
@@ -158,7 +169,7 @@ module Searchkick
|
|
158
169
|
}
|
159
170
|
)
|
160
171
|
|
161
|
-
|
172
|
+
stem = false
|
162
173
|
when "japanese"
|
163
174
|
settings[:analysis][:analyzer].merge!(
|
164
175
|
default_analyzer => {
|
@@ -171,6 +182,8 @@ module Searchkick
|
|
171
182
|
type: "kuromoji"
|
172
183
|
}
|
173
184
|
)
|
185
|
+
|
186
|
+
stem = false
|
174
187
|
when "korean"
|
175
188
|
settings[:analysis][:analyzer].merge!(
|
176
189
|
default_analyzer => {
|
@@ -183,6 +196,8 @@ module Searchkick
|
|
183
196
|
type: "openkoreantext-analyzer"
|
184
197
|
}
|
185
198
|
)
|
199
|
+
|
200
|
+
stem = false
|
186
201
|
when "vietnamese"
|
187
202
|
settings[:analysis][:analyzer].merge!(
|
188
203
|
default_analyzer => {
|
@@ -195,6 +210,8 @@ module Searchkick
|
|
195
210
|
type: "vi_analyzer"
|
196
211
|
}
|
197
212
|
)
|
213
|
+
|
214
|
+
stem = false
|
198
215
|
when "polish", "ukrainian", "smartcn"
|
199
216
|
settings[:analysis][:analyzer].merge!(
|
200
217
|
default_analyzer => {
|
@@ -207,6 +224,8 @@ module Searchkick
|
|
207
224
|
type: language
|
208
225
|
}
|
209
226
|
)
|
227
|
+
|
228
|
+
stem = false
|
210
229
|
end
|
211
230
|
|
212
231
|
if Searchkick.env == "test"
|
@@ -231,9 +250,10 @@ module Searchkick
|
|
231
250
|
end
|
232
251
|
end
|
233
252
|
|
234
|
-
if
|
253
|
+
if stem == false
|
254
|
+
settings[:analysis][:filter].delete(:searchkick_stemmer)
|
235
255
|
settings[:analysis][:analyzer].each do |_, analyzer|
|
236
|
-
analyzer[:filter].delete("searchkick_stemmer")
|
256
|
+
analyzer[:filter].delete("searchkick_stemmer") if analyzer[:filter]
|
237
257
|
end
|
238
258
|
end
|
239
259
|
|
data/lib/searchkick/query.rb
CHANGED
@@ -15,7 +15,7 @@ module Searchkick
|
|
15
15
|
:out_of_range?, :hits, :response, :to_a, :first
|
16
16
|
|
17
17
|
def initialize(klass, term = "*", **options)
|
18
|
-
unknown_keywords = options.keys - [:aggs, :body, :body_options, :boost,
|
18
|
+
unknown_keywords = options.keys - [:aggs, :block, :body, :body_options, :boost,
|
19
19
|
:boost_by, :boost_by_distance, :boost_by_recency, :boost_where, :conversions, :conversions_term, :debug, :emoji, :exclude, :execute, :explain,
|
20
20
|
:fields, :highlight, :includes, :index_name, :indices_boost, :limit, :load,
|
21
21
|
:match, :misspellings, :model_includes, :offset, :operator, :order, :padding, :page, :per_page, :profile,
|
@@ -483,6 +483,9 @@ module Searchkick
|
|
483
483
|
# merge more body options
|
484
484
|
payload = payload.deep_merge(options[:body_options]) if options[:body_options]
|
485
485
|
|
486
|
+
# run block
|
487
|
+
options[:block].call(payload) if options[:block]
|
488
|
+
|
486
489
|
@body = payload
|
487
490
|
@page = page
|
488
491
|
@per_page = per_page
|
@@ -843,7 +846,12 @@ module Searchkick
|
|
843
846
|
else
|
844
847
|
# expand ranges
|
845
848
|
if value.is_a?(Range)
|
846
|
-
|
849
|
+
# infinite? added in Ruby 2.4
|
850
|
+
if value.end.nil? || (value.end.respond_to?(:infinite?) && value.end.infinite?)
|
851
|
+
value = {gte: value.first}
|
852
|
+
else
|
853
|
+
value = {gte: value.first, (value.exclude_end? ? :lt : :lte) => value.last}
|
854
|
+
end
|
847
855
|
end
|
848
856
|
|
849
857
|
value = {in: value} if value.is_a?(Array)
|
@@ -895,6 +903,8 @@ module Searchkick
|
|
895
903
|
}
|
896
904
|
}
|
897
905
|
}
|
906
|
+
when :prefix
|
907
|
+
filters << {prefix: {field => op_value}}
|
898
908
|
when :regexp # support for regexp queries without using a regexp ruby object
|
899
909
|
filters << {regexp: {field => {value: op_value}}}
|
900
910
|
when :not, :_not # not equal
|
@@ -39,8 +39,6 @@ module Searchkick
|
|
39
39
|
@routing_key ||= Searchkick.server_below?("6.0.0") ? :_routing : :routing
|
40
40
|
end
|
41
41
|
|
42
|
-
private
|
43
|
-
|
44
42
|
def record_data
|
45
43
|
data = {
|
46
44
|
_index: index.name,
|
@@ -51,6 +49,8 @@ module Searchkick
|
|
51
49
|
data
|
52
50
|
end
|
53
51
|
|
52
|
+
private
|
53
|
+
|
54
54
|
def search_data(method_name = nil)
|
55
55
|
partial_reindex = !method_name.nil?
|
56
56
|
|
data/lib/searchkick/version.rb
CHANGED
@@ -13,17 +13,15 @@ namespace :searchkick do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
model.reindex
|
24
|
-
end
|
25
|
-
puts "Reindex complete"
|
16
|
+
namespace :reindex do
|
17
|
+
desc "reindex all models"
|
18
|
+
task all: :environment do
|
19
|
+
Rails.application.eager_load!
|
20
|
+
Searchkick.models.each do |model|
|
21
|
+
puts "Reindexing #{model.name}..."
|
22
|
+
model.reindex
|
26
23
|
end
|
24
|
+
puts "Reindex complete"
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
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: 3.1.
|
4
|
+
version: 3.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -118,13 +118,14 @@ files:
|
|
118
118
|
- lib/searchkick/process_batch_job.rb
|
119
119
|
- lib/searchkick/process_queue_job.rb
|
120
120
|
- lib/searchkick/query.rb
|
121
|
+
- lib/searchkick/railtie.rb
|
121
122
|
- lib/searchkick/record_data.rb
|
122
123
|
- lib/searchkick/record_indexer.rb
|
123
124
|
- lib/searchkick/reindex_queue.rb
|
124
125
|
- lib/searchkick/reindex_v2_job.rb
|
125
126
|
- lib/searchkick/results.rb
|
126
|
-
- lib/searchkick/tasks.rb
|
127
127
|
- lib/searchkick/version.rb
|
128
|
+
- lib/tasks/searchkick.rake
|
128
129
|
homepage: https://github.com/ankane/searchkick
|
129
130
|
licenses:
|
130
131
|
- MIT
|
@@ -144,9 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
145
|
- !ruby/object:Gem::Version
|
145
146
|
version: '0'
|
146
147
|
requirements: []
|
147
|
-
|
148
|
-
rubygems_version: 2.7.7
|
148
|
+
rubygems_version: 3.0.3
|
149
149
|
signing_key:
|
150
150
|
specification_version: 4
|
151
|
-
summary: Intelligent search made easy
|
151
|
+
summary: Intelligent search made easy with Rails and Elasticsearch
|
152
152
|
test_files: []
|