searchkick 0.2.8 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +11 -1
- data/lib/searchkick/model.rb +6 -1
- data/lib/searchkick/reindex.rb +1 -1
- data/lib/searchkick/search.rb +13 -3
- data/lib/searchkick/version.rb +1 -1
- data/test/sql_test.rb +12 -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: 08d3471564b063d98692fa8db6e27635b826d9eb
|
4
|
+
data.tar.gz: 23ff81861bf090b967eacce86c31b99f18370738
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e3fb6959b85a1d63908e7fe7c6086eb817ee597132f701205fa0942f7982e43a6eecdb6b1924e2c7e7d4f1650071df95a2281b1b548e8099a3e2eeffbd1c475
|
7
|
+
data.tar.gz: 1c774316a7f8833239e27c4e15578c537729ce37c6c9cb54b7202f71b4ee44978d2dda2bad4d330b7e34acfbc643a002fdc92a436af79cfb41e0147d6bda9322
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -21,6 +21,8 @@ Plus:
|
|
21
21
|
- “Did you mean” suggestions
|
22
22
|
- works with ActiveRecord and Mongoid
|
23
23
|
|
24
|
+
:zap: Even better with [Searchjoy](http://ankane.github.io/searchjoy/)
|
25
|
+
|
24
26
|
:tangerine: Battle-tested at [Instacart](https://www.instacart.com)
|
25
27
|
|
26
28
|
[![Build Status](https://travis-ci.org/ankane/searchkick.png?branch=master)](https://travis-ci.org/ankane/searchkick)
|
@@ -351,6 +353,8 @@ product.similar(fields: ["name"])
|
|
351
353
|
|
352
354
|
### Geospatial Searches
|
353
355
|
|
356
|
+
**Note:** Before `0.3.0`, locations were indexed incorrectly. When upgrading, be sure to reindex immediately.
|
357
|
+
|
354
358
|
```ruby
|
355
359
|
class City < ActiveRecord::Base
|
356
360
|
searchkick locations: ["location"]
|
@@ -367,6 +371,12 @@ Reindex and search with:
|
|
367
371
|
City.search "san", where: {location: {near: [37, -114], within: "100mi"}} # or 160km
|
368
372
|
```
|
369
373
|
|
374
|
+
Bounded by a box
|
375
|
+
|
376
|
+
```ruby
|
377
|
+
City.search "san", where: {location: {top_left: [38, -123], bottom_right: [37, -122]}}
|
378
|
+
```
|
379
|
+
|
370
380
|
## Deployment
|
371
381
|
|
372
382
|
Searchkick uses `ENV["ELASTICSEARCH_URL"]` for the Elasticsearch server. This defaults to `http://localhost:9200`.
|
@@ -406,7 +416,7 @@ ENV["ELASTICSEARCH_URL"] = "http://username:password@api.searchbox.io"
|
|
406
416
|
Then deploy and reindex:
|
407
417
|
|
408
418
|
```sh
|
409
|
-
|
419
|
+
rake searchkick:reindex CLASS=Product
|
410
420
|
```
|
411
421
|
|
412
422
|
## Reference
|
data/lib/searchkick/model.rb
CHANGED
@@ -17,7 +17,7 @@ module Searchkick
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def reindex
|
20
|
-
update_index
|
20
|
+
tire.update_index
|
21
21
|
end
|
22
22
|
|
23
23
|
def search_data
|
@@ -43,6 +43,11 @@ module Searchkick
|
|
43
43
|
source[field] = "a" if !source[field]
|
44
44
|
end
|
45
45
|
|
46
|
+
# locations
|
47
|
+
(options[:locations] || []).map(&:to_s).each do |field|
|
48
|
+
source[field] = source[field].reverse if source[field]
|
49
|
+
end
|
50
|
+
|
46
51
|
source.to_json
|
47
52
|
end
|
48
53
|
end
|
data/lib/searchkick/reindex.rb
CHANGED
@@ -41,7 +41,7 @@ module Searchkick
|
|
41
41
|
# remove old indices that start w/ index_name
|
42
42
|
def clean_indices
|
43
43
|
all_indices = JSON.parse(Tire::Configuration.client.get("#{Tire::Configuration.url}/_aliases").body)
|
44
|
-
indices = all_indices.select{|k, v| v["aliases"].empty? && k =~ /\A#{Regexp.escape(
|
44
|
+
indices = all_indices.select{|k, v| v["aliases"].empty? && k =~ /\A#{Regexp.escape(tire.index.name)}_\d{14,17}\z/ }.keys
|
45
45
|
indices.each do |index|
|
46
46
|
Tire::Index.new(index).delete
|
47
47
|
end
|
data/lib/searchkick/search.rb
CHANGED
@@ -156,14 +156,13 @@ module Searchkick
|
|
156
156
|
end
|
157
157
|
|
158
158
|
# where
|
159
|
-
# TODO expand or
|
160
159
|
where_filters =
|
161
160
|
proc do |where|
|
162
161
|
filters = []
|
163
162
|
(where || {}).each do |field, value|
|
164
163
|
if field == :or
|
165
164
|
value.each do |or_clause|
|
166
|
-
filters << {or: or_clause.map{|or_statement| {
|
165
|
+
filters << {or: or_clause.map{|or_statement| {and: where_filters.call(or_statement)} }}
|
167
166
|
end
|
168
167
|
else
|
169
168
|
# expand ranges
|
@@ -177,12 +176,23 @@ module Searchkick
|
|
177
176
|
if value[:near]
|
178
177
|
filters << {
|
179
178
|
geo_distance: {
|
180
|
-
field => value.delete(:near),
|
179
|
+
field => value.delete(:near).reverse,
|
181
180
|
distance: value.delete(:within) || "50mi"
|
182
181
|
}
|
183
182
|
}
|
184
183
|
end
|
185
184
|
|
185
|
+
if value[:top_left]
|
186
|
+
filters << {
|
187
|
+
geo_bounding_box: {
|
188
|
+
field => {
|
189
|
+
top_left: value.delete(:top_left).reverse,
|
190
|
+
bottom_right: value.delete(:bottom_right).reverse
|
191
|
+
}
|
192
|
+
}
|
193
|
+
}
|
194
|
+
end
|
195
|
+
|
186
196
|
value.each do |op, op_value|
|
187
197
|
if op == :not # not equal
|
188
198
|
if op_value.is_a?(Array)
|
data/lib/searchkick/version.rb
CHANGED
data/test/sql_test.rb
CHANGED
@@ -60,7 +60,10 @@ class TestSql < Minitest::Unit::TestCase
|
|
60
60
|
assert_search "product", ["Product A", "Product B"], where: {store_id: [1, 2]}
|
61
61
|
assert_search "product", ["Product B", "Product C", "Product D"], where: {store_id: {not: 1}}
|
62
62
|
assert_search "product", ["Product C", "Product D"], where: {store_id: {not: [1, 2]}}
|
63
|
+
# or
|
63
64
|
assert_search "product", ["Product A", "Product B", "Product C"], where: {or: [[{in_stock: true}, {store_id: 3}]]}
|
65
|
+
assert_search "product", ["Product A", "Product B", "Product C"], where: {or: [[{orders_count: [2, 4]}, {store_id: [1, 2]}]]}
|
66
|
+
assert_search "product", ["Product A", "Product D"], where: {or: [[{orders_count: 1}, {created_at: {gte: now - 1}, backordered: true}]]}
|
64
67
|
# array
|
65
68
|
assert_search "product", ["Product A"], where: {user_ids: 2}
|
66
69
|
end
|
@@ -77,7 +80,7 @@ class TestSql < Minitest::Unit::TestCase
|
|
77
80
|
{name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
|
78
81
|
{name: "San Antonio", latitude: 29.4167, longitude: -98.5000}
|
79
82
|
]
|
80
|
-
assert_search "san", ["San Francisco"], where: {location: {near: [37, -122]}}
|
83
|
+
assert_search "san", ["San Francisco"], where: {location: {near: [37.5, -122.5]}}
|
81
84
|
end
|
82
85
|
|
83
86
|
def test_near_within
|
@@ -89,6 +92,14 @@ class TestSql < Minitest::Unit::TestCase
|
|
89
92
|
assert_search "san", ["San Francisco", "San Antonio"], where: {location: {near: [37, -122], within: "2000mi"}}
|
90
93
|
end
|
91
94
|
|
95
|
+
def test_top_left_bottom_right
|
96
|
+
store [
|
97
|
+
{name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
|
98
|
+
{name: "San Antonio", latitude: 29.4167, longitude: -98.5000}
|
99
|
+
]
|
100
|
+
assert_search "san", ["San Francisco"], where: {location: {top_left: [38, -123], bottom_right: [37, -122]}}
|
101
|
+
end
|
102
|
+
|
92
103
|
def test_order_hash
|
93
104
|
store_names ["Product A", "Product B", "Product C", "Product D"]
|
94
105
|
assert_order "product", ["Product D", "Product C", "Product B", "Product A"], order: {name: :desc}
|
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.
|
4
|
+
version: 0.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: 2013-
|
11
|
+
date: 2013-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tire
|