searchkick 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +39 -23
- data/lib/searchkick/search.rb +17 -5
- data/lib/searchkick/version.rb +1 -1
- data/test/facets_test.rb +14 -3
- data/test/sql_test.rb +11 -4
- data/test/test_helper.rb +1 -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: c8a8a68edbdd1ac1b03fc9fa7396391082a13a64
|
4
|
+
data.tar.gz: 9933087ad09633fbb2b9b0607fc2ec591a62e35b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edbfccd85651bbfb32c13a8c7de4ea15663cc0ff04fcc03969d7268d2c365b59e7272045541b116e9bb0234d8e5976190265d699d6549cc0a6710489927638f6
|
7
|
+
data.tar.gz: eea0fe79ae6396f7c07769a3437640162ded10494600bc69179403e2f11609a9c24609c4eaa08dd287840328417d54323850657fd7791f51212aa287549e6993
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -87,6 +87,7 @@ where: {
|
|
87
87
|
aisle_id: [25, 30], # in
|
88
88
|
store_id: {not: 2}, # not
|
89
89
|
aisle_id: {not: [25, 30]}, # not in
|
90
|
+
user_ids: {all: [1, 3]}, # all elements in array
|
90
91
|
or: [
|
91
92
|
[{in_stock: true}, {backordered: true}]
|
92
93
|
]
|
@@ -111,6 +112,14 @@ Boost by a field
|
|
111
112
|
boost: "orders_count" # give popular documents a little boost
|
112
113
|
```
|
113
114
|
|
115
|
+
### Get Everything
|
116
|
+
|
117
|
+
Use a `*` for the query.
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
Product.search "*"
|
121
|
+
```
|
122
|
+
|
114
123
|
### Pagination
|
115
124
|
|
116
125
|
Plays nicely with kaminari and will_paginate.
|
@@ -348,6 +357,13 @@ Advanced
|
|
348
357
|
Product.search "2% Milk", facets: {store_id: {where: {in_stock: true}, limit: 10}}
|
349
358
|
```
|
350
359
|
|
360
|
+
Ranges
|
361
|
+
|
362
|
+
```ruby
|
363
|
+
price_ranges = [{to: 20}, {from: 20, to: 50}, {from: 50}]
|
364
|
+
Product.search "*", facets: {price: {ranges: price_ranges}}
|
365
|
+
```
|
366
|
+
|
351
367
|
### Highlight
|
352
368
|
|
353
369
|
Highlight the search query in the results.
|
@@ -407,6 +423,29 @@ Bounded by a box
|
|
407
423
|
City.search "san", where: {location: {top_left: [38, -123], bottom_right: [37, -122]}}
|
408
424
|
```
|
409
425
|
|
426
|
+
## Inheritance
|
427
|
+
|
428
|
+
Searchkick supports single table inheritance.
|
429
|
+
|
430
|
+
```ruby
|
431
|
+
class Dog < Animal
|
432
|
+
end
|
433
|
+
```
|
434
|
+
|
435
|
+
The parent and child model can both reindex.
|
436
|
+
|
437
|
+
```ruby
|
438
|
+
Animal.reindex
|
439
|
+
Dog.reindex # equivalent
|
440
|
+
```
|
441
|
+
|
442
|
+
And to search, use:
|
443
|
+
|
444
|
+
```ruby
|
445
|
+
Animal.search "*" # all animals
|
446
|
+
Dog.search "*" # just dogs
|
447
|
+
```
|
448
|
+
|
410
449
|
## Deployment
|
411
450
|
|
412
451
|
Searchkick uses `ENV["ELASTICSEARCH_URL"]` for the Elasticsearch server. This defaults to `http://localhost:9200`.
|
@@ -449,29 +488,6 @@ Then deploy and reindex:
|
|
449
488
|
rake searchkick:reindex CLASS=Product
|
450
489
|
```
|
451
490
|
|
452
|
-
## Inheritance
|
453
|
-
|
454
|
-
Searchkick supports single table inheritance.
|
455
|
-
|
456
|
-
```ruby
|
457
|
-
class Dog < Animal
|
458
|
-
end
|
459
|
-
```
|
460
|
-
|
461
|
-
The parent and child model can both reindex.
|
462
|
-
|
463
|
-
```ruby
|
464
|
-
Animal.reindex
|
465
|
-
Dog.reindex # equivalent
|
466
|
-
```
|
467
|
-
|
468
|
-
And to search, use:
|
469
|
-
|
470
|
-
```ruby
|
471
|
-
Animal.search "*" # all animals
|
472
|
-
Dog.search "*" # just dogs
|
473
|
-
```
|
474
|
-
|
475
491
|
## Reference
|
476
492
|
|
477
493
|
Searchkick requires Elasticsearch `0.90.0` or higher.
|
data/lib/searchkick/search.rb
CHANGED
@@ -201,6 +201,8 @@ module Searchkick
|
|
201
201
|
else
|
202
202
|
filters << {not: {term: {field => op_value}}}
|
203
203
|
end
|
204
|
+
elsif op == :all
|
205
|
+
filters << {terms: {field => op_value, execution: "and"}}
|
204
206
|
else
|
205
207
|
range_query =
|
206
208
|
case op
|
@@ -250,12 +252,22 @@ module Searchkick
|
|
250
252
|
facets.each do |field, facet_options|
|
251
253
|
# ask for extra facets due to
|
252
254
|
# https://github.com/elasticsearch/elasticsearch/issues/1305
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
255
|
+
|
256
|
+
if facet_options[:ranges]
|
257
|
+
payload[:facets][field] = {
|
258
|
+
range: {
|
259
|
+
field.to_sym => facet_options[:ranges]
|
260
|
+
}
|
257
261
|
}
|
258
|
-
|
262
|
+
else
|
263
|
+
payload[:facets][field] = {
|
264
|
+
terms: {
|
265
|
+
field: field,
|
266
|
+
size: facet_options[:limit] ? facet_options[:limit] + 150 : 100000
|
267
|
+
}
|
268
|
+
}
|
269
|
+
end
|
270
|
+
|
259
271
|
facet_limits[field] = facet_options[:limit] if facet_options[:limit]
|
260
272
|
|
261
273
|
# offset is not possible
|
data/lib/searchkick/version.rb
CHANGED
data/test/facets_test.rb
CHANGED
@@ -5,9 +5,9 @@ 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"},
|
9
|
-
{name: "Product Hide", store_id: 2, in_stock: false, color: "green"},
|
10
|
-
{name: "Product B", store_id: 2, in_stock: false, color: "red"}
|
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}
|
11
11
|
]
|
12
12
|
end
|
13
13
|
|
@@ -26,4 +26,15 @@ class TestFacets < Minitest::Unit::TestCase
|
|
26
26
|
assert_equal 1, facet["other"]
|
27
27
|
end
|
28
28
|
|
29
|
+
def test_ranges
|
30
|
+
price_ranges = [{to: 10}, {from: 10, to: 20}, {from: 20}]
|
31
|
+
facet = Product.search("Product", facets: {price: {ranges: price_ranges}}).facets["price"]
|
32
|
+
|
33
|
+
assert_equal 3, facet["ranges"].size
|
34
|
+
assert_equal 10.0, facet["ranges"][0]["to"]
|
35
|
+
assert_equal 20.0, facet["ranges"][2]["from"]
|
36
|
+
assert_equal 1, facet["ranges"][0]["count"]
|
37
|
+
assert_equal 0, facet["ranges"][1]["count"]
|
38
|
+
assert_equal 2, facet["ranges"][2]["count"]
|
39
|
+
end
|
29
40
|
end
|
data/test/sql_test.rb
CHANGED
@@ -39,7 +39,7 @@ class TestSql < Minitest::Unit::TestCase
|
|
39
39
|
now = Time.now
|
40
40
|
store [
|
41
41
|
{name: "Product A", store_id: 1, in_stock: true, backordered: true, created_at: now, orders_count: 4, user_ids: [1, 2, 3]},
|
42
|
-
{name: "Product B", store_id: 2, in_stock: true, backordered: false, created_at: now - 1, orders_count: 3},
|
42
|
+
{name: "Product B", store_id: 2, in_stock: true, backordered: false, created_at: now - 1, orders_count: 3, user_ids: [1]},
|
43
43
|
{name: "Product C", store_id: 3, in_stock: false, backordered: true, created_at: now - 2, orders_count: 2},
|
44
44
|
{name: "Product D", store_id: 4, in_stock: false, backordered: false, created_at: now - 3, orders_count: 1},
|
45
45
|
]
|
@@ -64,15 +64,16 @@ class TestSql < Minitest::Unit::TestCase
|
|
64
64
|
assert_search "product", ["Product A", "Product B", "Product C"], where: {or: [[{in_stock: true}, {store_id: 3}]]}
|
65
65
|
assert_search "product", ["Product A", "Product B", "Product C"], where: {or: [[{orders_count: [2, 4]}, {store_id: [1, 2]}]]}
|
66
66
|
assert_search "product", ["Product A", "Product D"], where: {or: [[{orders_count: 1}, {created_at: {gte: now - 1}, backordered: true}]]}
|
67
|
-
#
|
68
|
-
assert_search "product", ["Product A"], where: {user_ids:
|
67
|
+
# all
|
68
|
+
assert_search "product", ["Product A"], where: {user_ids: {all: [1, 3]}}
|
69
|
+
assert_search "product", [], where: {user_ids: {all: [1, 2, 3, 4]}}
|
69
70
|
end
|
70
71
|
|
71
72
|
def test_where_string
|
72
73
|
store [
|
73
74
|
{name: "Product A", color: "RED"}
|
74
75
|
]
|
75
|
-
assert_search "product", ["Product A"], where: {color:
|
76
|
+
assert_search "product", ["Product A"], where: {color: "RED"}
|
76
77
|
end
|
77
78
|
|
78
79
|
def test_where_nil
|
@@ -83,6 +84,12 @@ class TestSql < Minitest::Unit::TestCase
|
|
83
84
|
assert_search "product", ["Product A"], where: {color: nil}
|
84
85
|
end
|
85
86
|
|
87
|
+
def test_where_id
|
88
|
+
store_names ["Product A"]
|
89
|
+
product = Product.last
|
90
|
+
assert_search "product", ["Product A"], where: {id: product.id}
|
91
|
+
end
|
92
|
+
|
86
93
|
def test_near
|
87
94
|
store [
|
88
95
|
{name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
|
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: 0.3.
|
4
|
+
version: 0.3.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: 2013-
|
11
|
+
date: 2013-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tire
|