searchkick 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +7 -0
- data/README.md +24 -5
- data/lib/searchkick/logging.rb +2 -1
- data/lib/searchkick/query.rb +2 -1
- data/lib/searchkick/results.rb +13 -1
- data/lib/searchkick/version.rb +1 -1
- data/test/facets_test.rb +33 -5
- data/test/sql_test.rb +3 -0
- 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: 7cffd1af1407a4da1aedcc1a7af63202939586c5
|
4
|
+
data.tar.gz: 3fa1d499bb7f1fd4ff7a71a92fc2237931cc04fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c98bdf5690ec1bb4b837033f9e08c80cd6aacaa2d811c651108fedcee940df68168ec015c4207b210c3003315a9910517d7fd8210e7b3b2daec1d50c280cf15
|
7
|
+
data.tar.gz: a101b6f2ccd2d7c65d8290b9da7bdc5da8da1efceef7cd51371c743e7bef5cb988b9a6193ef50bf2d5f206c019712090b30f573046bed2058bc3eeef611ab9f1
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 0.7.2
|
2
|
+
|
3
|
+
- Added smart facets
|
4
|
+
- Added more fields to `load: false` result
|
5
|
+
- Fixed logging for multi-index searches
|
6
|
+
- Added `first_page?` and `last_page?` for improved Kaminari support
|
7
|
+
|
1
8
|
## 0.7.1
|
2
9
|
|
3
10
|
- Fixed huge issue w/ zero-downtime reindexing on 0.90
|
data/README.md
CHANGED
@@ -43,6 +43,8 @@ Add this line to your application’s Gemfile:
|
|
43
43
|
gem "searchkick"
|
44
44
|
```
|
45
45
|
|
46
|
+
For Elasticsearch 0.90, use version `0.6.3`.
|
47
|
+
|
46
48
|
Add searchkick to models you want to search.
|
47
49
|
|
48
50
|
```ruby
|
@@ -403,10 +405,29 @@ products = Product.search "chuck taylor", facets: [:product_type, :gender, :bran
|
|
403
405
|
p products.facets
|
404
406
|
```
|
405
407
|
|
406
|
-
|
408
|
+
By default, `where` conditions are not applied to facets (for backward compatibility).
|
409
|
+
|
410
|
+
```ruby
|
411
|
+
Product.search "wingtips", where: {color: "brandy"}, facets: [:size]
|
412
|
+
# facets *not* filtered by color :(
|
413
|
+
```
|
414
|
+
|
415
|
+
Change this with:
|
416
|
+
|
417
|
+
```ruby
|
418
|
+
Product.search "wingtips", where: {color: "brandy"}, facets: [:size], smart_facets: true
|
419
|
+
```
|
420
|
+
|
421
|
+
or set `where` conditions for each facet separately:
|
407
422
|
|
408
423
|
```ruby
|
409
|
-
Product.search "
|
424
|
+
Product.search "wingtips", facets: {size: {where: {color: "brandy"}}}
|
425
|
+
```
|
426
|
+
|
427
|
+
Limit
|
428
|
+
|
429
|
+
```ruby
|
430
|
+
Product.search "2% Milk", facets: {store_id: {limit: 10}}
|
410
431
|
```
|
411
432
|
|
412
433
|
Ranges
|
@@ -595,8 +616,6 @@ products = query.execute
|
|
595
616
|
|
596
617
|
## Reference
|
597
618
|
|
598
|
-
Searchkick requires Elasticsearch `0.90.4` or higher.
|
599
|
-
|
600
619
|
Reindex one record
|
601
620
|
|
602
621
|
```ruby
|
@@ -746,7 +765,7 @@ rake searchkick:reindex:all
|
|
746
765
|
|
747
766
|
## Note about 0.6.0 and 0.7.0
|
748
767
|
|
749
|
-
If running Searchkick `0.6.0` or `0.7.0` and Elasticsearch `0.90`, we recommend upgrading to Searchkick `0.7.1` to fix an issue that causes downtime when reindexing.
|
768
|
+
If running Searchkick `0.6.0` or `0.7.0` and Elasticsearch `0.90`, we recommend upgrading to Searchkick `0.6.1` or `0.7.1` to fix an issue that causes downtime when reindexing.
|
750
769
|
|
751
770
|
## Elasticsearch Gotchas
|
752
771
|
|
data/lib/searchkick/logging.rb
CHANGED
@@ -37,10 +37,11 @@ module Searchkick
|
|
37
37
|
payload = event.payload
|
38
38
|
name = "#{payload[:name]} (#{event.duration.round(1)}ms)"
|
39
39
|
type = payload[:query][:type]
|
40
|
+
index = payload[:query][:index].is_a?(Array) ? payload[:query][:index].join(",") : payload[:query][:index]
|
40
41
|
|
41
42
|
# no easy way to tell which host the client will use
|
42
43
|
host = Searchkick.client.transport.hosts.first
|
43
|
-
debug " #{color(name, YELLOW, true)} curl #{host[:protocol]}://#{host[:host]}:#{host[:port]}/#{CGI.escape(
|
44
|
+
debug " #{color(name, YELLOW, true)} curl #{host[:protocol]}://#{host[:host]}:#{host[:port]}/#{CGI.escape(index)}#{type ? "/#{type.map{|t| CGI.escape(t) }.join(",")}" : ""}/_search?pretty -d '#{payload[:query][:body].to_json}'"
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
data/lib/searchkick/query.rb
CHANGED
@@ -239,6 +239,7 @@ module Searchkick
|
|
239
239
|
# offset is not possible
|
240
240
|
# http://elasticsearch-users.115913.n3.nabble.com/Is-pagination-possible-in-termsStatsFacet-td3422943.html
|
241
241
|
|
242
|
+
facet_options.deep_merge!(where: options[:where].reject{|k| k == field}) if options[:smart_facets] == true
|
242
243
|
facet_filters = where_filters(facet_options[:where])
|
243
244
|
if facet_filters.any?
|
244
245
|
payload[:facets][field][:facet_filter] = {
|
@@ -448,4 +449,4 @@ module Searchkick
|
|
448
449
|
end
|
449
450
|
|
450
451
|
end
|
451
|
-
end
|
452
|
+
end
|
data/lib/searchkick/results.rb
CHANGED
@@ -25,7 +25,11 @@ module Searchkick
|
|
25
25
|
hit_ids = hit_ids.map(&:to_s)
|
26
26
|
records.sort_by{|r| hit_ids.index(r.id.to_s) }
|
27
27
|
else
|
28
|
-
hits.map
|
28
|
+
hits.map do |hit|
|
29
|
+
result = hit.except("_source").merge(hit["_source"])
|
30
|
+
result["id"] = result["_id"]
|
31
|
+
Hashie::Mash.new(result)
|
32
|
+
end
|
29
33
|
end
|
30
34
|
end
|
31
35
|
end
|
@@ -90,6 +94,14 @@ module Searchkick
|
|
90
94
|
current_page < total_pages ? (current_page + 1) : nil
|
91
95
|
end
|
92
96
|
|
97
|
+
def first_page?
|
98
|
+
previous_page.nil?
|
99
|
+
end
|
100
|
+
|
101
|
+
def last_page?
|
102
|
+
next_page.nil?
|
103
|
+
end
|
104
|
+
|
93
105
|
protected
|
94
106
|
|
95
107
|
def hits
|
data/lib/searchkick/version.rb
CHANGED
data/test/facets_test.rb
CHANGED
@@ -5,18 +5,19 @@ class TestFacets < Minitest::Unit::TestCase
|
|
5
5
|
def setup
|
6
6
|
super
|
7
7
|
store [
|
8
|
-
{name: "Product Show", store_id: 1, in_stock: true, color: "blue", price: 21},
|
9
|
-
{name: "Product Hide", store_id: 2, in_stock: false, color: "green", price: 25},
|
10
|
-
{name: "Product B", store_id: 2, in_stock: false, color: "red", price: 5}
|
8
|
+
{name: "Product Show", latitude: 37.7833, longitude: 12.4167, store_id: 1, in_stock: true, color: "blue", price: 21},
|
9
|
+
{name: "Product Hide", latitude: 29.4167, longitude: -98.5000, store_id: 2, in_stock: false, color: "green", price: 25},
|
10
|
+
{name: "Product B", latitude: 43.9333, longitude: -122.4667, store_id: 2, in_stock: false, color: "red", price: 5},
|
11
|
+
{name: "Foo", latitude: 43.9333, longitude: 12.4667, store_id: 3, in_stock: false, color: "yellow", price: 15}
|
11
12
|
]
|
12
13
|
end
|
13
14
|
|
14
15
|
def test_basic
|
15
|
-
assert_equal 2,
|
16
|
+
assert_equal ({1 => 1, 2 => 2}), store_facet(facets: [:store_id])
|
16
17
|
end
|
17
18
|
|
18
19
|
def test_where
|
19
|
-
assert_equal 1,
|
20
|
+
assert_equal ({1 => 1}), store_facet(facets: {store_id: {where: {in_stock: true}}})
|
20
21
|
end
|
21
22
|
|
22
23
|
def test_limit
|
@@ -37,4 +38,31 @@ class TestFacets < Minitest::Unit::TestCase
|
|
37
38
|
assert_equal 0, facet["ranges"][1]["count"]
|
38
39
|
assert_equal 2, facet["ranges"][2]["count"]
|
39
40
|
end
|
41
|
+
|
42
|
+
def test_where_no_smart_facets
|
43
|
+
assert_equal ({2 => 2}), store_facet(where: {color: "red"}, facets: {store_id: {where: {in_stock: false}}})
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_smart_facets
|
47
|
+
assert_equal ({1 => 1}), store_facet(where: {in_stock: true}, facets: [:store_id], smart_facets: true)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_smart_facets_where
|
51
|
+
assert_equal ({2 => 1}), store_facet(where: {color: "red"}, facets: {store_id: {where: {in_stock: false}}}, smart_facets: true)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_smart_facets_skip_facet
|
55
|
+
assert_equal ({1 => 1, 2 => 2}), store_facet(where: {store_id: 2}, facets: [:store_id], smart_facets: true)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_smart_facets_skip_facet_complex
|
59
|
+
assert_equal ({1 => 1, 2 => 1}), store_facet(where: {store_id: 2, price: {gt: 5}}, facets: [:store_id], smart_facets: true)
|
60
|
+
end
|
61
|
+
|
62
|
+
protected
|
63
|
+
|
64
|
+
def store_facet(options)
|
65
|
+
Hash[ Product.search("Product", options).facets["store_id"]["terms"].map{|v| [v["term"], v["count"]] } ]
|
66
|
+
end
|
67
|
+
|
40
68
|
end
|
data/test/sql_test.rb
CHANGED
@@ -29,6 +29,8 @@ class TestSql < Minitest::Unit::TestCase
|
|
29
29
|
assert_equal 5, products.total_entries
|
30
30
|
assert_equal 2, products.limit_value
|
31
31
|
assert_equal 4, products.offset_value
|
32
|
+
assert !products.first_page?
|
33
|
+
assert !products.last_page?
|
32
34
|
end
|
33
35
|
|
34
36
|
def test_pagination_nil_page
|
@@ -36,6 +38,7 @@ class TestSql < Minitest::Unit::TestCase
|
|
36
38
|
products = Product.search("product", order: {name: :asc}, page: nil, per_page: 2)
|
37
39
|
assert_equal ["Product A", "Product B"], products.map(&:name)
|
38
40
|
assert_equal 1, products.current_page
|
41
|
+
assert products.first_page?
|
39
42
|
end
|
40
43
|
|
41
44
|
def test_where
|
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.7.
|
4
|
+
version: 0.7.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: 2014-04-
|
11
|
+
date: 2014-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|