searchkick 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +10 -2
- data/lib/searchkick.rb +5 -3
- data/lib/searchkick/index.rb +17 -7
- data/lib/searchkick/query.rb +4 -3
- data/lib/searchkick/version.rb +1 -1
- data/test/aggs_test.rb +5 -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: a492bb88396370b25f7bd69d7c5cebad46fde482
|
4
|
+
data.tar.gz: d958c3ee3261ddf1cf7aed5f1ef1b6e50348194c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c510e1a08aa01f34f23220a6af5676520be76ab1920843acb3d8ca205fb621de39ee9de3607f6363c49bda2bd416f9bfa1cad9666c42c7e3c4be81bbe678c59a
|
7
|
+
data.tar.gz: 5f51db56e29051fc7fe37242e9b94a09e1a4d05883709b8fe102a750db8197f642753c89a5a186233fe310c5de75a00ee6da1e8cd967061e891ba335097d314f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 1.0.2
|
2
|
+
|
3
|
+
- Throw `Searchkick::ImportError` for errors when importing records
|
4
|
+
- Errors now inherit from `Searchkick::Error`
|
5
|
+
- Added `order` option to aggregations
|
6
|
+
- Added `mapping` method
|
7
|
+
|
1
8
|
## 1.0.1
|
2
9
|
|
3
10
|
- Added aggregations method to get raw response
|
data/README.md
CHANGED
@@ -260,7 +260,7 @@ Searchkick defaults to English for stemming. To change this, use:
|
|
260
260
|
|
261
261
|
```ruby
|
262
262
|
class Product < ActiveRecord::Base
|
263
|
-
searchkick
|
263
|
+
searchkick language: "german"
|
264
264
|
end
|
265
265
|
```
|
266
266
|
|
@@ -317,7 +317,7 @@ Product.search "zuchini", misspellings: false # no zucchini
|
|
317
317
|
|
318
318
|
### Emoji
|
319
319
|
|
320
|
-
|
320
|
+
Search :ice_cream::cake: and get `ice cream cake`!
|
321
321
|
|
322
322
|
Add this line to your application’s Gemfile:
|
323
323
|
|
@@ -594,6 +594,14 @@ Limit
|
|
594
594
|
Product.search "apples", aggs: {store_id: {limit: 10}}
|
595
595
|
```
|
596
596
|
|
597
|
+
Order
|
598
|
+
|
599
|
+
```ruby
|
600
|
+
Product.search "wingtips", aggs: {color: {order: {"_term" => "asc"}}} # alphabetically
|
601
|
+
```
|
602
|
+
|
603
|
+
[All of these options are supported](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-order)
|
604
|
+
|
597
605
|
Ranges
|
598
606
|
|
599
607
|
```ruby
|
data/lib/searchkick.rb
CHANGED
@@ -19,10 +19,12 @@ end
|
|
19
19
|
require "searchkick/reindex_v2_job" if defined?(ActiveJob)
|
20
20
|
|
21
21
|
module Searchkick
|
22
|
-
class
|
23
|
-
class
|
22
|
+
class Error < StandardError; end
|
23
|
+
class MissingIndexError < Error; end
|
24
|
+
class UnsupportedVersionError < Error; end
|
24
25
|
class InvalidQueryError < Elasticsearch::Transport::Transport::Errors::BadRequest; end
|
25
|
-
class DangerousOperation <
|
26
|
+
class DangerousOperation < Error; end
|
27
|
+
class ImportError < Error; end
|
26
28
|
|
27
29
|
class << self
|
28
30
|
attr_accessor :search_method_name
|
data/lib/searchkick/index.rb
CHANGED
@@ -27,6 +27,10 @@ module Searchkick
|
|
27
27
|
client.indices.exists_alias name: name
|
28
28
|
end
|
29
29
|
|
30
|
+
def mapping
|
31
|
+
client.indices.get_mapping index: name
|
32
|
+
end
|
33
|
+
|
30
34
|
def swap(new_name)
|
31
35
|
old_indices =
|
32
36
|
begin
|
@@ -62,11 +66,15 @@ module Searchkick
|
|
62
66
|
|
63
67
|
def import(records)
|
64
68
|
records.group_by { |r| document_type(r) }.each do |type, batch|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
69
|
+
response =
|
70
|
+
client.bulk(
|
71
|
+
index: name,
|
72
|
+
type: type,
|
73
|
+
body: batch.map { |r| {index: {_id: search_id(r), data: search_data(r)}} }
|
74
|
+
)
|
75
|
+
if response["errors"]
|
76
|
+
raise Searchkick::ImportError, response["items"].first["index"]["error"]
|
77
|
+
end
|
70
78
|
end
|
71
79
|
end
|
72
80
|
|
@@ -201,6 +209,8 @@ module Searchkick
|
|
201
209
|
|
202
210
|
def index_options
|
203
211
|
options = @options
|
212
|
+
language = options[:language]
|
213
|
+
language = language.call if language.respond_to?(:call)
|
204
214
|
|
205
215
|
if options[:mappings] && !options[:merge_mappings]
|
206
216
|
settings = options[:settings] || {}
|
@@ -317,8 +327,8 @@ module Searchkick
|
|
317
327
|
searchkick_stemmer: {
|
318
328
|
# use stemmer if language is lowercase, snowball otherwise
|
319
329
|
# TODO deprecate language option in favor of stemmer
|
320
|
-
type:
|
321
|
-
language:
|
330
|
+
type: language == language.to_s.downcase ? "stemmer" : "snowball",
|
331
|
+
language: language || "English"
|
322
332
|
}
|
323
333
|
},
|
324
334
|
char_filter: {
|
data/lib/searchkick/query.rb
CHANGED
@@ -351,27 +351,28 @@ module Searchkick
|
|
351
351
|
|
352
352
|
aggs.each do |field, agg_options|
|
353
353
|
size = agg_options[:limit] ? agg_options[:limit] : 100_000
|
354
|
+
shared_agg_options = agg_options.slice(:order)
|
354
355
|
|
355
356
|
if agg_options[:ranges]
|
356
357
|
payload[:aggs][field] = {
|
357
358
|
range: {
|
358
359
|
field: agg_options[:field] || field,
|
359
360
|
ranges: agg_options[:ranges]
|
360
|
-
}
|
361
|
+
}.merge(shared_agg_options)
|
361
362
|
}
|
362
363
|
elsif agg_options[:date_ranges]
|
363
364
|
payload[:aggs][field] = {
|
364
365
|
date_range: {
|
365
366
|
field: agg_options[:field] || field,
|
366
367
|
ranges: agg_options[:date_ranges]
|
367
|
-
}
|
368
|
+
}.merge(shared_agg_options)
|
368
369
|
}
|
369
370
|
else
|
370
371
|
payload[:aggs][field] = {
|
371
372
|
terms: {
|
372
373
|
field: agg_options[:field] || field,
|
373
374
|
size: size
|
374
|
-
}
|
375
|
+
}.merge(shared_agg_options)
|
375
376
|
}
|
376
377
|
end
|
377
378
|
|
data/lib/searchkick/version.rb
CHANGED
data/test/aggs_test.rb
CHANGED
@@ -19,6 +19,11 @@ class AggsTest < Minitest::Test
|
|
19
19
|
assert_equal ({1 => 1}), store_agg(aggs: {store_id: {where: {in_stock: true}}})
|
20
20
|
end
|
21
21
|
|
22
|
+
def test_order
|
23
|
+
agg = Product.search("Product", aggs: {color: {order: {"_term" => "desc"}}}).aggs["color"]
|
24
|
+
assert_equal %w[red green blue], agg["buckets"].map { |b| b["key"] }
|
25
|
+
end
|
26
|
+
|
22
27
|
def test_field
|
23
28
|
assert_equal ({1 => 1, 2 => 2}), store_agg(aggs: {store_id: {}})
|
24
29
|
assert_equal ({1 => 1, 2 => 2}), store_agg(aggs: {store_id: {field: "store_id"}})
|
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.0.
|
4
|
+
version: 1.0.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: 2015-11-
|
11
|
+
date: 2015-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|