searchkick 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -5
- data/CHANGELOG.md +7 -0
- data/README.md +32 -9
- data/lib/searchkick/index.rb +17 -7
- data/lib/searchkick/index_options.rb +2 -2
- data/lib/searchkick/model.rb +14 -24
- data/lib/searchkick/query.rb +44 -4
- data/lib/searchkick/results.rb +6 -2
- data/lib/searchkick/version.rb +1 -1
- data/test/ci/before_install.sh +7 -8
- data/test/gemfiles/nobrainer.gemfile +1 -1
- data/test/match_test.rb +8 -1
- data/test/partial_reindex_test.rb +58 -0
- data/test/sql_test.rb +14 -6
- data/test/test_helper.rb +6 -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: 9994b20546ec9b93a6fe9b34a0e329868aa3371b
|
4
|
+
data.tar.gz: 77ab1a591fe5e599b3d640d271aafe3f0642b47d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cf24561e0d7d871311b6ec5d50f115d654ce64c77422c1e51a07d13831b3ae81327ff1505d59d1b707d6b4926fad61e094178e703ee7a454cffafaf80b77464
|
7
|
+
data.tar.gz: 95a15798d483c444398a88c6940e88275eceb850231e869a272ab0bbc659089ca651780eba84ab5ac95f9a24aa1a8aed3e05da88474e6b093aedd265e69c7c7a
|
data/.travis.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
+
sudo: false
|
1
2
|
language: ruby
|
2
3
|
rvm: 2.2.5
|
3
4
|
services:
|
4
|
-
- elasticsearch
|
5
5
|
- mongodb
|
6
6
|
before_install:
|
7
7
|
- ./test/ci/before_install.sh
|
@@ -24,17 +24,22 @@ gemfile:
|
|
24
24
|
- test/gemfiles/mongoid4.gemfile
|
25
25
|
- test/gemfiles/mongoid5.gemfile
|
26
26
|
env:
|
27
|
-
- ELASTICSEARCH_VERSION=
|
27
|
+
- ELASTICSEARCH_VERSION=5.1.1
|
28
|
+
jdk: oraclejdk8
|
28
29
|
matrix:
|
29
30
|
include:
|
30
31
|
- gemfile: Gemfile
|
31
32
|
env: ELASTICSEARCH_VERSION=1.0.0
|
33
|
+
jdk: oraclejdk7
|
32
34
|
- gemfile: Gemfile
|
33
35
|
env: ELASTICSEARCH_VERSION=1.7.0
|
36
|
+
jdk: oraclejdk7
|
34
37
|
- gemfile: Gemfile
|
35
38
|
env: ELASTICSEARCH_VERSION=2.0.0
|
39
|
+
jdk: oraclejdk7
|
36
40
|
- gemfile: Gemfile
|
37
|
-
env: ELASTICSEARCH_VERSION=
|
38
|
-
|
41
|
+
env: ELASTICSEARCH_VERSION=2.4.1
|
42
|
+
jdk: oraclejdk7
|
39
43
|
- gemfile: Gemfile
|
40
|
-
env: ELASTICSEARCH_VERSION=5.0.
|
44
|
+
env: ELASTICSEARCH_VERSION=5.0.1
|
45
|
+
jdk: oraclejdk8
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
|
+
## 1.4.1
|
2
|
+
|
3
|
+
- Added `partial_reindex` method
|
4
|
+
- Added `debug` option to `search` method
|
5
|
+
- Added `profile` option
|
6
|
+
|
1
7
|
## 1.4.0
|
2
8
|
|
9
|
+
- Official support for Elasticsearch 5
|
3
10
|
- Boost exact matches for partial matching
|
4
11
|
- Added `searchkick_debug` method
|
5
12
|
- Added `geo_polygon` filter
|
data/README.md
CHANGED
@@ -44,8 +44,6 @@ Add this line to your application’s Gemfile:
|
|
44
44
|
gem 'searchkick'
|
45
45
|
```
|
46
46
|
|
47
|
-
For Elasticsearch 5.0, use the version `1.4` and above. For Elasticsearch 2.0, use the version `1.0` and above.
|
48
|
-
|
49
47
|
Add searchkick to models you want to search.
|
50
48
|
|
51
49
|
```ruby
|
@@ -543,7 +541,7 @@ First, specify which fields use this feature. This is necessary since autocomple
|
|
543
541
|
|
544
542
|
```ruby
|
545
543
|
class Book < ActiveRecord::Base
|
546
|
-
searchkick
|
544
|
+
searchkick word_start: [:title, :author]
|
547
545
|
end
|
548
546
|
```
|
549
547
|
|
@@ -565,6 +563,7 @@ class BooksController < ApplicationController
|
|
565
563
|
def autocomplete
|
566
564
|
render json: Book.search(params[:query], {
|
567
565
|
fields: ["title^5", "author"],
|
566
|
+
match: :word_start,
|
568
567
|
limit: 10,
|
569
568
|
load: false,
|
570
569
|
misspellings: {below: 5}
|
@@ -579,11 +578,18 @@ Then add the search box and JavaScript code to a view.
|
|
579
578
|
<input type="text" id="query" name="query" />
|
580
579
|
|
581
580
|
<script src="jquery.js"></script>
|
582
|
-
<script src="typeahead.js"></script>
|
581
|
+
<script src="typeahead.bundle.js"></script>
|
583
582
|
<script>
|
584
|
-
|
585
|
-
|
586
|
-
|
583
|
+
var books = new Bloodhound({
|
584
|
+
datumTokenizer: Bloodhound.tokenizers.whitespace,
|
585
|
+
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
586
|
+
remote: {
|
587
|
+
url: '/books/autocomplete?query=%QUERY',
|
588
|
+
wildcard: '%QUERY'
|
589
|
+
}
|
590
|
+
});
|
591
|
+
$('#query').typeahead(null, {
|
592
|
+
source: books
|
587
593
|
});
|
588
594
|
</script>
|
589
595
|
```
|
@@ -852,7 +858,7 @@ Bounded by a box
|
|
852
858
|
City.search "san", where: {location: {top_left: {lat: 38, lon: -123}, bottom_right: {lat: 37, lon: -122}}}
|
853
859
|
```
|
854
860
|
|
855
|
-
Bounded by a polygon
|
861
|
+
Bounded by a polygon
|
856
862
|
|
857
863
|
```ruby
|
858
864
|
City.search "san", where: {location: {geo_polygon: {points: [{lat: 38, lon: -123}, {lat: 39, lon: -123}, {lat: 37, lon: 122}]}}}
|
@@ -1055,7 +1061,7 @@ require "typhoeus/adapters/faraday"
|
|
1055
1061
|
Ethon.logger.level = Logger::WARN
|
1056
1062
|
```
|
1057
1063
|
|
1058
|
-
|
1064
|
+
If you run into issues on Windows, check out [this post](https://www.rastating.com/fixing-issues-in-typhoeus-and-httparty-on-windows/).
|
1059
1065
|
|
1060
1066
|
### Automatic Failover
|
1061
1067
|
|
@@ -1207,6 +1213,21 @@ Product.where("id > 100000").find_in_batches do |batch|
|
|
1207
1213
|
end
|
1208
1214
|
```
|
1209
1215
|
|
1216
|
+
Reindex a subset of attributes
|
1217
|
+
|
1218
|
+
```ruby
|
1219
|
+
class Product < ActiveRecord::Base
|
1220
|
+
def search_prices
|
1221
|
+
{
|
1222
|
+
price: price,
|
1223
|
+
sale_price: sale_price
|
1224
|
+
}
|
1225
|
+
end
|
1226
|
+
end
|
1227
|
+
|
1228
|
+
Product.partial_reindex(:search_prices)
|
1229
|
+
```
|
1230
|
+
|
1210
1231
|
Remove old indices
|
1211
1232
|
|
1212
1233
|
```ruby
|
@@ -1517,6 +1538,8 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
|
|
1517
1538
|
- Write, clarify, or fix documentation
|
1518
1539
|
- Suggest or add new features
|
1519
1540
|
|
1541
|
+
If you’re looking for ideas, [try here](https://github.com/ankane/searchkick/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22).
|
1542
|
+
|
1520
1543
|
To get started with development and testing:
|
1521
1544
|
|
1522
1545
|
```sh
|
data/lib/searchkick/index.rb
CHANGED
@@ -67,6 +67,10 @@ module Searchkick
|
|
67
67
|
end
|
68
68
|
alias_method :import, :bulk_index
|
69
69
|
|
70
|
+
def bulk_update(records, method_name)
|
71
|
+
Searchkick.queue_items(records.map { |r| {update: record_data(r).merge(data: {doc: search_data(r, method_name)})} })
|
72
|
+
end
|
73
|
+
|
70
74
|
def record_data(r)
|
71
75
|
data = {
|
72
76
|
_index: name,
|
@@ -221,6 +225,7 @@ module Searchkick
|
|
221
225
|
|
222
226
|
def import_scope(scope, options = {})
|
223
227
|
batch_size = @options[:batch_size] || 1000
|
228
|
+
method_name = options[:method_name]
|
224
229
|
|
225
230
|
# use scope for import
|
226
231
|
scope = scope.search_import if scope.respond_to?(:search_import)
|
@@ -234,7 +239,7 @@ module Searchkick
|
|
234
239
|
end
|
235
240
|
|
236
241
|
scope.find_in_batches batch_size: batch_size do |batch|
|
237
|
-
|
242
|
+
import_or_update batch.select(&:should_index?), method_name
|
238
243
|
end
|
239
244
|
else
|
240
245
|
# https://github.com/karmi/tire/blob/master/lib/tire/model/import.rb
|
@@ -244,14 +249,18 @@ module Searchkick
|
|
244
249
|
scope.all.each do |item|
|
245
250
|
items << item if item.should_index?
|
246
251
|
if items.length == batch_size
|
247
|
-
|
252
|
+
import_or_update items, method_name
|
248
253
|
items = []
|
249
254
|
end
|
250
255
|
end
|
251
|
-
|
256
|
+
import_or_update items, method_name
|
252
257
|
end
|
253
258
|
end
|
254
259
|
|
260
|
+
def import_or_update(records, method_name)
|
261
|
+
method_name ? bulk_update(records, method_name) : import(records)
|
262
|
+
end
|
263
|
+
|
255
264
|
# other
|
256
265
|
|
257
266
|
def tokens(text, options = {})
|
@@ -285,13 +294,14 @@ module Searchkick
|
|
285
294
|
id.is_a?(Numeric) ? id : id.to_s
|
286
295
|
end
|
287
296
|
|
288
|
-
def search_data(record)
|
289
|
-
|
297
|
+
def search_data(record, method_name = nil)
|
298
|
+
partial_reindex = !method_name.nil?
|
299
|
+
source = record.send(method_name || :search_data)
|
290
300
|
options = record.class.searchkick_options
|
291
301
|
|
292
302
|
# stringify fields
|
293
303
|
# remove _id since search_id is used instead
|
294
|
-
source = source.each_with_object({}) { |(k, v), memo| memo[k.to_s] = v; memo }.except("_id")
|
304
|
+
source = source.each_with_object({}) { |(k, v), memo| memo[k.to_s] = v; memo }.except("_id", "_type")
|
295
305
|
|
296
306
|
# conversions
|
297
307
|
Array(options[:conversions]).map(&:to_s).each do |conversions_field|
|
@@ -302,7 +312,7 @@ module Searchkick
|
|
302
312
|
|
303
313
|
# hack to prevent generator field doesn't exist error
|
304
314
|
(options[:suggest] || []).map(&:to_s).each do |field|
|
305
|
-
source[field] = nil
|
315
|
+
source[field] = nil if !source[field] && !partial_reindex
|
306
316
|
end
|
307
317
|
|
308
318
|
# locations
|
@@ -25,7 +25,7 @@ module Searchkick
|
|
25
25
|
}
|
26
26
|
end
|
27
27
|
|
28
|
-
keyword_mapping[:ignore_above] = 256 unless below22
|
28
|
+
keyword_mapping[:ignore_above] = (options[:ignore_above] || 256) unless below22
|
29
29
|
|
30
30
|
settings = {
|
31
31
|
analysis: {
|
@@ -308,7 +308,7 @@ module Searchkick
|
|
308
308
|
dynamic_fields["{name}"] = {type: default_type, index: "no"}
|
309
309
|
end
|
310
310
|
|
311
|
-
dynamic_fields["{name}"][:ignore_above] = 256 unless below22
|
311
|
+
dynamic_fields["{name}"][:ignore_above] = (options[:ignore_above] || 256) unless below22
|
312
312
|
|
313
313
|
unless options[:searchable]
|
314
314
|
if options[:match] && options[:match] != :word
|
data/lib/searchkick/model.rb
CHANGED
@@ -54,6 +54,13 @@ module Searchkick
|
|
54
54
|
end
|
55
55
|
alias_method :reindex, :searchkick_reindex unless method_defined?(:reindex)
|
56
56
|
|
57
|
+
def searchkick_partial_reindex(method_name)
|
58
|
+
searchkick_index.import_scope(searchkick_klass, method_name: method_name)
|
59
|
+
searchkick_index.refresh
|
60
|
+
true
|
61
|
+
end
|
62
|
+
alias_method :partial_reindex, :searchkick_partial_reindex unless method_defined?(:partial_reindex)
|
63
|
+
|
57
64
|
def clean_indices
|
58
65
|
searchkick_index.clean_indices
|
59
66
|
end
|
@@ -71,30 +78,7 @@ module Searchkick
|
|
71
78
|
end
|
72
79
|
|
73
80
|
def searchkick_debug
|
74
|
-
|
75
|
-
|
76
|
-
puts "Model Searchkick Options"
|
77
|
-
pp searchkick_options
|
78
|
-
puts
|
79
|
-
|
80
|
-
puts "Model Sample Search Data"
|
81
|
-
begin
|
82
|
-
pp first(3).map { |r| {index: searchkick_index.record_data(r).merge(data: searchkick_index.send(:search_data, r))}}
|
83
|
-
rescue => e
|
84
|
-
puts "#{e.class.name}: #{e.message}"
|
85
|
-
end
|
86
|
-
puts
|
87
|
-
|
88
|
-
puts "Elasticsearch Mapping"
|
89
|
-
puts JSON.pretty_generate(searchkick_index.mapping)
|
90
|
-
puts
|
91
|
-
|
92
|
-
puts "Elasticsearch Settings"
|
93
|
-
puts JSON.pretty_generate(searchkick_index.settings)
|
94
|
-
puts
|
95
|
-
|
96
|
-
puts "Elasticsearch Sample Results"
|
97
|
-
puts JSON.pretty_generate(search("*", load: false, limit: 3).response)
|
81
|
+
warn "Use debug option with search method instead"
|
98
82
|
|
99
83
|
nil # do not return anything, as this is strictly used for manual debugging
|
100
84
|
end
|
@@ -117,6 +101,12 @@ module Searchkick
|
|
117
101
|
self.class.searchkick_index.reindex_record_async(self)
|
118
102
|
end unless method_defined?(:reindex_async)
|
119
103
|
|
104
|
+
def partial_reindex(method_name)
|
105
|
+
self.class.searchkick_index.bulk_update([self], method_name)
|
106
|
+
self.class.searchkick_index.refresh
|
107
|
+
true
|
108
|
+
end unless method_defined?(:partial_reindex)
|
109
|
+
|
120
110
|
def similar(options = {})
|
121
111
|
self.class.searchkick_index.similar_record(self, options)
|
122
112
|
end unless method_defined?(:similar)
|
data/lib/searchkick/query.rb
CHANGED
@@ -112,11 +112,50 @@ module Searchkick
|
|
112
112
|
padding: @padding,
|
113
113
|
load: @load,
|
114
114
|
includes: options[:include] || options[:includes],
|
115
|
-
json:
|
115
|
+
json: !@json.nil?,
|
116
116
|
match_suffix: @match_suffix,
|
117
117
|
highlighted_fields: @highlighted_fields || []
|
118
118
|
}
|
119
119
|
|
120
|
+
if options[:debug]
|
121
|
+
require "pp"
|
122
|
+
|
123
|
+
puts "Searchkick Version: #{Searchkick::VERSION}"
|
124
|
+
puts "Elasticsearch Version: #{Searchkick.server_version}"
|
125
|
+
puts
|
126
|
+
|
127
|
+
puts "Model Searchkick Options"
|
128
|
+
pp searchkick_options
|
129
|
+
puts
|
130
|
+
|
131
|
+
puts "Search Options"
|
132
|
+
pp options
|
133
|
+
puts
|
134
|
+
|
135
|
+
puts "Model Search Data"
|
136
|
+
begin
|
137
|
+
pp klass.first(3).map { |r| {index: searchkick_index.record_data(r).merge(data: searchkick_index.send(:search_data, r))}}
|
138
|
+
rescue => e
|
139
|
+
puts "#{e.class.name}: #{e.message}"
|
140
|
+
end
|
141
|
+
puts
|
142
|
+
|
143
|
+
puts "Elasticsearch Mapping"
|
144
|
+
puts JSON.pretty_generate(searchkick_index.mapping)
|
145
|
+
puts
|
146
|
+
|
147
|
+
puts "Elasticsearch Settings"
|
148
|
+
puts JSON.pretty_generate(searchkick_index.settings)
|
149
|
+
puts
|
150
|
+
|
151
|
+
puts "Elasticsearch Query"
|
152
|
+
puts to_curl
|
153
|
+
puts
|
154
|
+
|
155
|
+
puts "Elasticsearch Results"
|
156
|
+
puts JSON.pretty_generate(response)
|
157
|
+
end
|
158
|
+
|
120
159
|
# set execute for multi search
|
121
160
|
@execute = Searchkick::Results.new(searchkick_klass, response, opts)
|
122
161
|
end
|
@@ -173,9 +212,9 @@ module Searchkick
|
|
173
212
|
|
174
213
|
all = term == "*"
|
175
214
|
|
176
|
-
options[:json]
|
177
|
-
if
|
178
|
-
payload =
|
215
|
+
@json = options[:json] || options[:body]
|
216
|
+
if @json
|
217
|
+
payload = @json
|
179
218
|
else
|
180
219
|
if options[:query]
|
181
220
|
payload = options[:query]
|
@@ -365,6 +404,7 @@ module Searchkick
|
|
365
404
|
from: offset
|
366
405
|
}
|
367
406
|
payload[:explain] = options[:explain] if options[:explain]
|
407
|
+
payload[:profile] = options[:profile] if options[:profile]
|
368
408
|
|
369
409
|
# order
|
370
410
|
set_order(payload) if options[:order]
|
data/lib/searchkick/results.rb
CHANGED
@@ -181,7 +181,11 @@ module Searchkick
|
|
181
181
|
if options[:includes]
|
182
182
|
records =
|
183
183
|
if defined?(NoBrainer::Document) && records < NoBrainer::Document
|
184
|
-
|
184
|
+
if Gem.loaded_specs["nobrainer"].version >= Gem::Version.new("0.21")
|
185
|
+
records.eager_load(options[:includes])
|
186
|
+
else
|
187
|
+
records.preload(options[:includes])
|
188
|
+
end
|
185
189
|
else
|
186
190
|
records.includes(options[:includes])
|
187
191
|
end
|
@@ -196,7 +200,7 @@ module Searchkick
|
|
196
200
|
elsif records.respond_to?(:queryable)
|
197
201
|
# Mongoid 3+
|
198
202
|
records.queryable.for_ids(ids)
|
199
|
-
elsif records.respond_to?(:unscoped) && records.all.respond_to?(
|
203
|
+
elsif records.respond_to?(:unscoped) && [:preload, :eager_load].any? { |m| records.all.respond_to?(m) }
|
200
204
|
# Nobrainer
|
201
205
|
records.unscoped.where(:id.in => ids)
|
202
206
|
else
|
data/lib/searchkick/version.rb
CHANGED
data/test/ci/before_install.sh
CHANGED
@@ -4,15 +4,14 @@ set -e
|
|
4
4
|
|
5
5
|
gem install bundler
|
6
6
|
|
7
|
-
# https://docs.travis-ci.com/user/database-setup/#ElasticSearch
|
8
|
-
sudo apt-get purge elasticsearch
|
9
7
|
if [[ $ELASTICSEARCH_VERSION == 1* ]]; then
|
10
|
-
curl -O https://download.
|
8
|
+
curl -L -O https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-$ELASTICSEARCH_VERSION.tar.gz
|
11
9
|
elif [[ $ELASTICSEARCH_VERSION == 2* ]]; then
|
12
|
-
curl -O https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/
|
10
|
+
curl -L -O https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/$ELASTICSEARCH_VERSION/elasticsearch-$ELASTICSEARCH_VERSION.tar.gz
|
13
11
|
else
|
14
|
-
curl -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-$ELASTICSEARCH_VERSION.
|
12
|
+
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-$ELASTICSEARCH_VERSION.tar.gz
|
15
13
|
fi
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
tar -xvf elasticsearch-$ELASTICSEARCH_VERSION.tar.gz
|
15
|
+
cd elasticsearch-$ELASTICSEARCH_VERSION/bin
|
16
|
+
./elasticsearch -d
|
17
|
+
wget -O- --waitretry=1 --tries=30 --retry-connrefused -v http://127.0.0.1:9200/
|
data/test/match_test.rb
CHANGED
@@ -34,7 +34,9 @@ class MatchTest < Minitest::Test
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_percent
|
37
|
-
|
37
|
+
# Note: "2% Milk" doesn't get matched in ES below 5.1.1
|
38
|
+
# This could be a bug since it has an edit distance of 1
|
39
|
+
store_names ["1% Milk", "Whole Milk"]
|
38
40
|
assert_search "1%", ["1% Milk"]
|
39
41
|
end
|
40
42
|
|
@@ -184,6 +186,11 @@ class MatchTest < Minitest::Test
|
|
184
186
|
assert_search "ben and jerrys", ["Ben and Jerry's"]
|
185
187
|
end
|
186
188
|
|
189
|
+
def test_apostrophe_search
|
190
|
+
store_names ["Ben and Jerrys"]
|
191
|
+
assert_search "ben and jerry's", ["Ben and Jerrys"]
|
192
|
+
end
|
193
|
+
|
187
194
|
def test_ampersand_index
|
188
195
|
store_names ["Ben & Jerry's"]
|
189
196
|
assert_search "ben and jerrys", ["Ben & Jerry's"]
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class PartialReindexTest < Minitest::Test
|
4
|
+
def test_class_method
|
5
|
+
store [{name: "Hi", color: "Blue"}]
|
6
|
+
|
7
|
+
# normal search
|
8
|
+
assert_search "hi", ["Hi"], fields: [:name], load: false
|
9
|
+
assert_search "blue", ["Hi"], fields: [:color], load: false
|
10
|
+
|
11
|
+
# update
|
12
|
+
product = Product.first
|
13
|
+
product.name = "Bye"
|
14
|
+
product.color = "Red"
|
15
|
+
Searchkick.callbacks(false) do
|
16
|
+
product.save!
|
17
|
+
end
|
18
|
+
Product.searchkick_index.refresh
|
19
|
+
|
20
|
+
# index not updated
|
21
|
+
assert_search "hi", ["Hi"], fields: [:name], load: false
|
22
|
+
assert_search "blue", ["Hi"], fields: [:color], load: false
|
23
|
+
|
24
|
+
# partial reindex
|
25
|
+
Product.partial_reindex(:search_name)
|
26
|
+
|
27
|
+
# name updated, but not color
|
28
|
+
assert_search "bye", ["Bye"], fields: [:name], load: false
|
29
|
+
assert_search "blue", ["Bye"], fields: [:color], load: false
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_instance_method
|
33
|
+
store [{name: "Hi", color: "Blue"}]
|
34
|
+
|
35
|
+
# normal search
|
36
|
+
assert_search "hi", ["Hi"], fields: [:name], load: false
|
37
|
+
assert_search "blue", ["Hi"], fields: [:color], load: false
|
38
|
+
|
39
|
+
# update
|
40
|
+
product = Product.first
|
41
|
+
product.name = "Bye"
|
42
|
+
product.color = "Red"
|
43
|
+
Searchkick.callbacks(false) do
|
44
|
+
product.save!
|
45
|
+
end
|
46
|
+
Product.searchkick_index.refresh
|
47
|
+
|
48
|
+
# index not updated
|
49
|
+
assert_search "hi", ["Hi"], fields: [:name], load: false
|
50
|
+
assert_search "blue", ["Hi"], fields: [:color], load: false
|
51
|
+
|
52
|
+
product.partial_reindex(:search_name)
|
53
|
+
|
54
|
+
# name updated, but not color
|
55
|
+
assert_search "bye", ["Bye"], fields: [:name], load: false
|
56
|
+
assert_search "blue", ["Bye"], fields: [:color], load: false
|
57
|
+
end
|
58
|
+
end
|
data/test/sql_test.rb
CHANGED
@@ -55,7 +55,7 @@ class SqlTest < Minitest::Test
|
|
55
55
|
# body_options
|
56
56
|
|
57
57
|
def test_body_options_should_merge_into_body
|
58
|
-
query = Product.search(
|
58
|
+
query = Product.search("*", body_options: {min_score: 1.0}, execute: false)
|
59
59
|
assert_equal 1.0, query.body[:min_score]
|
60
60
|
end
|
61
61
|
|
@@ -81,6 +81,12 @@ class SqlTest < Minitest::Test
|
|
81
81
|
assert_kind_of Hash, Product.search("product", load: false, include: [:store]).first
|
82
82
|
end
|
83
83
|
|
84
|
+
def test_load_false_nested_object
|
85
|
+
aisle = {"id" => 1, "name" => "Frozen"}
|
86
|
+
store [{name: "Product A", aisle: aisle}]
|
87
|
+
assert_equal aisle, Product.search("product", load: false).first.aisle.to_hash
|
88
|
+
end
|
89
|
+
|
84
90
|
# select
|
85
91
|
|
86
92
|
def test_select
|
@@ -218,14 +224,16 @@ class SqlTest < Minitest::Test
|
|
218
224
|
assert_nil result.user_ids
|
219
225
|
end
|
220
226
|
|
221
|
-
#
|
227
|
+
# nested
|
222
228
|
|
223
|
-
def
|
224
|
-
|
225
|
-
store [{name: "Product A", aisle:
|
226
|
-
|
229
|
+
def test_nested_search
|
230
|
+
skip
|
231
|
+
store [{name: "Product A", aisle: {"id" => 1, "name" => "Frozen"}}]
|
232
|
+
assert_search "frozen", ["Product A"], fields: ["aisle.name"], debug: true
|
227
233
|
end
|
228
234
|
|
235
|
+
# other tests
|
236
|
+
|
229
237
|
def test_include
|
230
238
|
skip unless defined?(ActiveRecord)
|
231
239
|
store_names ["Product A"]
|
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: 1.4.
|
4
|
+
version: 1.4.1
|
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-
|
11
|
+
date: 2016-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- test/multi_tenancy_test.rb
|
151
151
|
- test/order_test.rb
|
152
152
|
- test/pagination_test.rb
|
153
|
+
- test/partial_reindex_test.rb
|
153
154
|
- test/query_test.rb
|
154
155
|
- test/records_test.rb
|
155
156
|
- test/reindex_job_test.rb
|
@@ -218,6 +219,7 @@ test_files:
|
|
218
219
|
- test/multi_tenancy_test.rb
|
219
220
|
- test/order_test.rb
|
220
221
|
- test/pagination_test.rb
|
222
|
+
- test/partial_reindex_test.rb
|
221
223
|
- test/query_test.rb
|
222
224
|
- test/records_test.rb
|
223
225
|
- test/reindex_job_test.rb
|