searchkick 0.7.2 → 0.7.3
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 +6 -0
- data/README.md +4 -2
- data/lib/searchkick/query.rb +5 -1
- data/lib/searchkick/results.rb +16 -8
- data/lib/searchkick/version.rb +1 -1
- data/test/inheritance_test.rb +8 -0
- data/test/sql_test.rb +5 -0
- data/test/suggest_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: 174eaff2241d0285d027261332c228bae2cf9215
|
4
|
+
data.tar.gz: db755391a04705242e8d21a54c8374518a1b7344
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 587dc4255bb875770e109c1c120fac8775a83f818d009d42bdea27d664af88c93ac3b4bc4e37d7bce033e60f54213fbb41eb5f873bfaffcdb9b6ab0d4605a1ec
|
7
|
+
data.tar.gz: a2da459414ad0a95efbe58c313593367f1e1d7dd3d61d6539c404c813ac204e0b37cae0144ea8366ee0af73fff9a9aeff9d24057b00d001fe00eee5e92caff4a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -331,6 +331,8 @@ Autocomplete predicts what a user will type, making the search experience faster
|
|
331
331
|
|
332
332
|

|
333
333
|
|
334
|
+
**Note:** If you only have a few thousand records, don’t use Searchkick for autocomplete. It’s *much* faster to load all records into JavaScript and autocomplete there (eliminates network requests).
|
335
|
+
|
334
336
|
First, specify which fields use this feature. This is necessary since autocomplete can increase the index size significantly, but don’t worry - this gives you blazing faster queries.
|
335
337
|
|
336
338
|
```ruby
|
@@ -345,7 +347,7 @@ Reindex and search with:
|
|
345
347
|
City.search "san fr", fields: [{name: :text_start}]
|
346
348
|
```
|
347
349
|
|
348
|
-
Typically, you want to use a
|
350
|
+
Typically, you want to use a JavaScript library like [typeahead.js](http://twitter.github.io/typeahead.js/) or [jQuery UI](http://jqueryui.com/autocomplete/).
|
349
351
|
|
350
352
|
#### Here’s how to make it work with Rails
|
351
353
|
|
@@ -362,7 +364,7 @@ class CitiesController < ApplicationController
|
|
362
364
|
end
|
363
365
|
```
|
364
366
|
|
365
|
-
Then add the search box and
|
367
|
+
Then add the search box and JavaScript code to a view.
|
366
368
|
|
367
369
|
```html
|
368
370
|
<input type="text" id="query" name="query" />
|
data/lib/searchkick/query.rb
CHANGED
@@ -254,8 +254,12 @@ module Searchkick
|
|
254
254
|
# suggestions
|
255
255
|
if options[:suggest]
|
256
256
|
suggest_fields = (searchkick_options[:suggest] || []).map(&:to_s)
|
257
|
+
|
257
258
|
# intersection
|
258
|
-
|
259
|
+
if options[:fields]
|
260
|
+
suggest_fields = suggest_fields & options[:fields].map{|v| (v.is_a?(Hash) ? v.keys.first : v).to_s }
|
261
|
+
end
|
262
|
+
|
259
263
|
if suggest_fields.any?
|
260
264
|
payload[:suggest] = {text: term}
|
261
265
|
suggest_fields.each do |field|
|
data/lib/searchkick/results.rb
CHANGED
@@ -5,7 +5,7 @@ module Searchkick
|
|
5
5
|
|
6
6
|
attr_reader :klass, :response, :options
|
7
7
|
|
8
|
-
def_delegators :results, :each, :empty?, :size, :slice, :[], :to_ary
|
8
|
+
def_delegators :results, :each, :any?, :empty?, :size, :length, :slice, :[], :to_ary
|
9
9
|
|
10
10
|
def initialize(klass, response, options = {})
|
11
11
|
@klass = klass
|
@@ -16,14 +16,21 @@ module Searchkick
|
|
16
16
|
def results
|
17
17
|
@results ||= begin
|
18
18
|
if options[:load]
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
# results can have different types
|
20
|
+
results = {}
|
21
|
+
|
22
|
+
hits.group_by{|hit, i| hit["_type"] }.each do |type, grouped_hits|
|
23
|
+
records = type.camelize.constantize
|
24
|
+
if options[:includes]
|
25
|
+
records = records.includes(options[:includes])
|
26
|
+
end
|
27
|
+
results[type] = records.find(grouped_hits.map{|hit| hit["_id"] })
|
28
|
+
end
|
29
|
+
|
30
|
+
# sort
|
31
|
+
hits.map do |hit|
|
32
|
+
results[hit["_type"]].find{|r| r.id.to_s == hit["_id"].to_s }
|
23
33
|
end
|
24
|
-
records = records.find(hit_ids)
|
25
|
-
hit_ids = hit_ids.map(&:to_s)
|
26
|
-
records.sort_by{|r| hit_ids.index(r.id.to_s) }
|
27
34
|
else
|
28
35
|
hits.map do |hit|
|
29
36
|
result = hit.except("_source").merge(hit["_source"])
|
@@ -85,6 +92,7 @@ module Searchkick
|
|
85
92
|
def offset_value
|
86
93
|
current_page * per_page
|
87
94
|
end
|
95
|
+
alias_method :offset, :offset_value
|
88
96
|
|
89
97
|
def previous_page
|
90
98
|
current_page > 1 ? (current_page - 1) : nil
|
data/lib/searchkick/version.rb
CHANGED
data/test/inheritance_test.rb
CHANGED
@@ -62,4 +62,12 @@ class TestInheritance < Minitest::Unit::TestCase
|
|
62
62
|
assert_equal ["tiger"], Animal.search("tige", fields: [:name], suggest: true).suggestions.sort
|
63
63
|
end
|
64
64
|
|
65
|
+
# TODO move somewhere better
|
66
|
+
|
67
|
+
def test_multiple_indices
|
68
|
+
store_names ["Product A"]
|
69
|
+
store_names ["Product B"], Animal
|
70
|
+
assert_search "product", ["Product A", "Product B"], index_name: [Product.searchkick_index.name, Animal.searchkick_index.name], conversions: false
|
71
|
+
end
|
72
|
+
|
65
73
|
end
|
data/test/sql_test.rb
CHANGED
@@ -24,13 +24,18 @@ class TestSql < Minitest::Unit::TestCase
|
|
24
24
|
assert_equal ["Product C", "Product D"], products.map(&:name)
|
25
25
|
assert_equal 2, products.current_page
|
26
26
|
assert_equal 2, products.per_page
|
27
|
+
assert_equal 2, products.size
|
28
|
+
assert_equal 2, products.length
|
27
29
|
assert_equal 3, products.total_pages
|
28
30
|
assert_equal 5, products.total_count
|
29
31
|
assert_equal 5, products.total_entries
|
30
32
|
assert_equal 2, products.limit_value
|
31
33
|
assert_equal 4, products.offset_value
|
34
|
+
assert_equal 4, products.offset
|
32
35
|
assert !products.first_page?
|
33
36
|
assert !products.last_page?
|
37
|
+
assert !products.empty?
|
38
|
+
assert products.any?
|
34
39
|
end
|
35
40
|
|
36
41
|
def test_pagination_nil_page
|
data/test/suggest_test.rb
CHANGED
@@ -56,6 +56,11 @@ class TestSuggest < Minitest::Unit::TestCase
|
|
56
56
|
assert_suggest "shar", "shark", fields: [:name, :unknown]
|
57
57
|
end
|
58
58
|
|
59
|
+
def test_fields_word_start
|
60
|
+
store_names ["Great White Shark", "Hammerhead Shark", "Tiger Shark"]
|
61
|
+
assert_suggest "How Big is a Tigre Shar", "how big is a tiger shark", fields: [{name: :word_start}]
|
62
|
+
end
|
63
|
+
|
59
64
|
protected
|
60
65
|
|
61
66
|
def assert_suggest(term, expected, options = {})
|
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.3
|
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
|
+
date: 2014-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|