searchkick 0.8.4 → 0.8.5
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 +7 -0
- data/README.md +24 -11
- data/lib/searchkick/model.rb +4 -1
- data/lib/searchkick/query.rb +6 -4
- data/lib/searchkick/reindex.rb +9 -2
- data/lib/searchkick/results.rb +0 -2
- data/lib/searchkick/version.rb +1 -1
- data/test/index_test.rb +15 -0
- data/test/match_test.rb +7 -0
- data/test/sql_test.rb +7 -0
- data/test/test_helper.rb +4 -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: c50ef339d04f201523ff1f41aad11277d7168dab
|
4
|
+
data.tar.gz: d7f79bf282327a781e23475f64b7530dfac6beab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61072c05e3aa82903b699e2062dc0a2944f7fcec20545709d2b83f1f0a760778adffbc7cf7002815c56c2ba6f9484de13f35134c484842ebbf56785d549a6883
|
7
|
+
data.tar.gz: 5c95dd8df5ead5050d2b24175e01b6ad197d7f430f92554f2330cb3b0976360ab4182d956e62ae734ce38b77985eb84f6c0e7e95a0d147d18f061e0964ee61e6
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -774,6 +774,8 @@ See [Production Rails](https://github.com/ankane/production_rails) for other goo
|
|
774
774
|
|
775
775
|
Prefer to use the [Elasticsearch DSL](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-queries.html) but still want awesome features like zero-downtime reindexing?
|
776
776
|
|
777
|
+
### Advanced Mapping
|
778
|
+
|
777
779
|
Create a custom mapping:
|
778
780
|
|
779
781
|
```ruby
|
@@ -788,32 +790,35 @@ class Product < ActiveRecord::Base
|
|
788
790
|
end
|
789
791
|
```
|
790
792
|
|
791
|
-
|
793
|
+
To keep the mappings and settings generated by Searchkick, use:
|
792
794
|
|
793
795
|
```ruby
|
794
|
-
|
796
|
+
class Product < ActiveRecord::Base
|
797
|
+
searchkick merge_mappings: true, mappings: {...}
|
798
|
+
end
|
795
799
|
```
|
796
800
|
|
797
|
-
|
801
|
+
### Advanced Search
|
802
|
+
|
803
|
+
And use the `body` option to search:
|
798
804
|
|
799
805
|
```ruby
|
800
|
-
products.
|
806
|
+
products = Product.search body: {match: {name: "milk"}}
|
801
807
|
```
|
802
808
|
|
803
|
-
|
809
|
+
View the response with:
|
804
810
|
|
805
811
|
```ruby
|
806
|
-
|
807
|
-
searchkick merge_mappings: true, mappings: {...}
|
808
|
-
end
|
812
|
+
products.response
|
809
813
|
```
|
810
814
|
|
811
815
|
To modify the query generated by Searchkick, use:
|
812
816
|
|
813
817
|
```ruby
|
814
|
-
|
815
|
-
|
816
|
-
|
818
|
+
products =
|
819
|
+
Product.search "2% Milk" do |body|
|
820
|
+
body[:query] = {match_all: {}}
|
821
|
+
end
|
817
822
|
```
|
818
823
|
|
819
824
|
## Reference
|
@@ -897,6 +902,14 @@ class Product < ActiveRecord::Base
|
|
897
902
|
end
|
898
903
|
```
|
899
904
|
|
905
|
+
Make fields unsearchable but include in the source
|
906
|
+
|
907
|
+
```ruby
|
908
|
+
class Product < ActiveRecord::Base
|
909
|
+
searchkick unsearchable: [:color]
|
910
|
+
end
|
911
|
+
```
|
912
|
+
|
900
913
|
Reindex asynchronously
|
901
914
|
|
902
915
|
```ruby
|
data/lib/searchkick/model.rb
CHANGED
@@ -20,8 +20,11 @@ module Searchkick
|
|
20
20
|
Searchkick::Index.new(index)
|
21
21
|
end
|
22
22
|
|
23
|
-
define_singleton_method(Searchkick.search_method_name) do |term = nil, options={}|
|
23
|
+
define_singleton_method(Searchkick.search_method_name) do |term = nil, options={}, &block|
|
24
24
|
query = Searchkick::Query.new(self, term, options)
|
25
|
+
if block
|
26
|
+
block.call(query.body)
|
27
|
+
end
|
25
28
|
if options[:execute] == false
|
26
29
|
query
|
27
30
|
else
|
data/lib/searchkick/query.rb
CHANGED
@@ -16,6 +16,7 @@ module Searchkick
|
|
16
16
|
@options = options
|
17
17
|
|
18
18
|
below12 = Gem::Version.new(Searchkick.server_version) < Gem::Version.new("1.2")
|
19
|
+
below14 = Gem::Version.new(Searchkick.server_version) < Gem::Version.new("1.4")
|
19
20
|
|
20
21
|
boost_fields = {}
|
21
22
|
fields =
|
@@ -56,6 +57,7 @@ module Searchkick
|
|
56
57
|
all = term == "*"
|
57
58
|
facet_limits = {}
|
58
59
|
|
60
|
+
options[:json] ||= options[:body]
|
59
61
|
if options[:json]
|
60
62
|
payload = options[:json]
|
61
63
|
else
|
@@ -279,7 +281,7 @@ module Searchkick
|
|
279
281
|
payload[:facets][field] = {
|
280
282
|
terms_stats: {
|
281
283
|
key_field: field,
|
282
|
-
value_script: "doc.score",
|
284
|
+
value_script: below14 ? "doc.score" : "_score",
|
283
285
|
size: size
|
284
286
|
}
|
285
287
|
}
|
@@ -355,10 +357,10 @@ module Searchkick
|
|
355
357
|
|
356
358
|
# An empty array will cause only the _id and _type for each hit to be returned
|
357
359
|
# http://www.elasticsearch.org/guide/reference/api/search/fields/
|
358
|
-
if
|
360
|
+
if options[:select]
|
361
|
+
payload[:fields] = options[:select] if options[:select] != true
|
362
|
+
elsif load
|
359
363
|
payload[:fields] = []
|
360
|
-
elsif options[:select]
|
361
|
-
payload[:fields] = options[:select]
|
362
364
|
end
|
363
365
|
|
364
366
|
if options[:type] or klass != searchkick_klass
|
data/lib/searchkick/reindex.rb
CHANGED
@@ -40,7 +40,7 @@ module Searchkick
|
|
40
40
|
# remove old indices that start w/ index_name
|
41
41
|
def clean_indices
|
42
42
|
all_indices = Searchkick.client.indices.get_aliases
|
43
|
-
indices = all_indices.select{|k, v| v["aliases"].empty? && k =~ /\A#{Regexp.escape(searchkick_index.name)}_\d{14,17}\z/ }.keys
|
43
|
+
indices = all_indices.select{|k, v| (v.empty? || v["aliases"].empty?) && k =~ /\A#{Regexp.escape(searchkick_index.name)}_\d{14,17}\z/ }.keys
|
44
44
|
indices.each do |index|
|
45
45
|
Searchkick::Index.new(index).delete
|
46
46
|
end
|
@@ -288,12 +288,19 @@ module Searchkick
|
|
288
288
|
mapping[field] = field_mapping
|
289
289
|
end
|
290
290
|
|
291
|
-
(options[:locations] || []).each do |field|
|
291
|
+
(options[:locations] || []).map(&:to_s).each do |field|
|
292
292
|
mapping[field] = {
|
293
293
|
type: "geo_point"
|
294
294
|
}
|
295
295
|
end
|
296
296
|
|
297
|
+
(options[:unsearchable] || []).map(&:to_s).each do |field|
|
298
|
+
mapping[field] = {
|
299
|
+
type: "string",
|
300
|
+
index: "no"
|
301
|
+
}
|
302
|
+
end
|
303
|
+
|
297
304
|
mappings = {
|
298
305
|
_default_: {
|
299
306
|
properties: mapping,
|
data/lib/searchkick/results.rb
CHANGED
data/lib/searchkick/version.rb
CHANGED
data/test/index_test.rb
CHANGED
@@ -41,6 +41,21 @@ class TestIndex < Minitest::Test
|
|
41
41
|
assert_equal ["Dollar Tree"], Store.search(json: {query: {match: {name: "Dollar Tree"}}}, load: false).map(&:name)
|
42
42
|
end
|
43
43
|
|
44
|
+
def test_body
|
45
|
+
store_names ["Dollar Tree"], Store
|
46
|
+
assert_equal [], Store.search(query: {match: {name: "dollar"}}).map(&:name)
|
47
|
+
assert_equal ["Dollar Tree"], Store.search(body: {query: {match: {name: "Dollar Tree"}}}, load: false).map(&:name)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_block
|
51
|
+
store_names ["Dollar Tree"]
|
52
|
+
products =
|
53
|
+
Product.search "boom" do |body|
|
54
|
+
body[:query] = {match_all: {}}
|
55
|
+
end
|
56
|
+
assert_equal ["Dollar Tree"], products.map(&:name)
|
57
|
+
end
|
58
|
+
|
44
59
|
def test_tokens
|
45
60
|
assert_equal ["dollar", "dollartre", "tree"], Product.searchkick_index.tokens("Dollar Tree")
|
46
61
|
end
|
data/test/match_test.rb
CHANGED
data/test/sql_test.rb
CHANGED
@@ -298,6 +298,13 @@ class TestSql < Minitest::Test
|
|
298
298
|
assert_equal [1, 2], result.user_ids
|
299
299
|
end
|
300
300
|
|
301
|
+
def test_select_all
|
302
|
+
store [{name: "Product A", user_ids: [1, 2]}]
|
303
|
+
hit = Product.search("product", select: true).hits.first
|
304
|
+
assert_equal hit["_source"]["name"], "Product A"
|
305
|
+
assert_equal hit["_source"]["user_ids"], [1, 2]
|
306
|
+
end
|
307
|
+
|
301
308
|
def test_nested_object
|
302
309
|
aisle = {"id" => 1, "name" => "Frozen"}
|
303
310
|
store [{name: "Product A", aisle: aisle}]
|
data/test/test_helper.rb
CHANGED
@@ -53,6 +53,7 @@ if defined?(Mongoid)
|
|
53
53
|
field :color
|
54
54
|
field :latitude, type: BigDecimal
|
55
55
|
field :longitude, type: BigDecimal
|
56
|
+
field :description
|
56
57
|
end
|
57
58
|
|
58
59
|
class Store
|
@@ -95,6 +96,7 @@ else
|
|
95
96
|
t.string :color
|
96
97
|
t.decimal :latitude, precision: 10, scale: 7
|
97
98
|
t.decimal :longitude, precision: 10, scale: 7
|
99
|
+
t.text :description
|
98
100
|
t.timestamps
|
99
101
|
end
|
100
102
|
|
@@ -146,7 +148,8 @@ class Product
|
|
146
148
|
word_start: [:name],
|
147
149
|
word_middle: [:name],
|
148
150
|
word_end: [:name],
|
149
|
-
highlight: [:name]
|
151
|
+
highlight: [:name],
|
152
|
+
unsearchable: [:description]
|
150
153
|
|
151
154
|
attr_accessor :conversions, :user_ids, :aisle
|
152
155
|
|
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.8.
|
4
|
+
version: 0.8.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|