Commit 899ce33a121f26c56878f0291fb46a024e158567
1 parent
dd1d3724
Exists in
master
and in
18 other branches
Fixed with_hit and with_highlights when records in search index do not exist in database
Showing
2 changed files
with
12 additions
and
9 deletions
Show diff stats
CHANGELOG.md
@@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
3 | - Added `:inline` as alias for `true` for `callbacks` and `mode` options | 3 | - Added `:inline` as alias for `true` for `callbacks` and `mode` options |
4 | - Friendlier error message for bad mapping with partial matches | 4 | - Friendlier error message for bad mapping with partial matches |
5 | - Warn when records in search index do not exist in database | 5 | - Warn when records in search index do not exist in database |
6 | +- Fixed `with_hit` and `with_highlights` when records in search index do not exist in database | ||
6 | - Fixed error with highlights and match all | 7 | - Fixed error with highlights and match all |
7 | 8 | ||
8 | ## 3.0.3 | 9 | ## 3.0.3 |
lib/searchkick/results.rb
@@ -16,7 +16,11 @@ module Searchkick | @@ -16,7 +16,11 @@ module Searchkick | ||
16 | end | 16 | end |
17 | 17 | ||
18 | def results | 18 | def results |
19 | - @results ||= begin | 19 | + @results ||= with_hit.map(&:first) |
20 | + end | ||
21 | + | ||
22 | + def with_hit | ||
23 | + @with_hit ||= begin | ||
20 | if options[:load] | 24 | if options[:load] |
21 | # results can have different types | 25 | # results can have different types |
22 | results = {} | 26 | results = {} |
@@ -38,8 +42,8 @@ module Searchkick | @@ -38,8 +42,8 @@ module Searchkick | ||
38 | end | 42 | end |
39 | end | 43 | end |
40 | end | 44 | end |
41 | - result | ||
42 | - end.compact | 45 | + [result, hit] |
46 | + end.select { |v| v[0] } | ||
43 | 47 | ||
44 | if results.size != hits.size | 48 | if results.size != hits.size |
45 | warn "[searchkick] WARNING: Records in search index do not exist in database" | 49 | warn "[searchkick] WARNING: Records in search index do not exist in database" |
@@ -65,7 +69,7 @@ module Searchkick | @@ -65,7 +69,7 @@ module Searchkick | ||
65 | end | 69 | end |
66 | 70 | ||
67 | result["id"] ||= result["_id"] # needed for legacy reasons | 71 | result["id"] ||= result["_id"] # needed for legacy reasons |
68 | - HashWrapper.new(result) | 72 | + [HashWrapper.new(result), hit] |
69 | end | 73 | end |
70 | end | 74 | end |
71 | end | 75 | end |
@@ -179,10 +183,6 @@ module Searchkick | @@ -179,10 +183,6 @@ module Searchkick | ||
179 | end | 183 | end |
180 | end | 184 | end |
181 | 185 | ||
182 | - def with_hit | ||
183 | - results.zip(hits) | ||
184 | - end | ||
185 | - | ||
186 | def highlights(multiple: false) | 186 | def highlights(multiple: false) |
187 | hits.map do |hit| | 187 | hits.map do |hit| |
188 | hit_highlights(hit, multiple: multiple) | 188 | hit_highlights(hit, multiple: multiple) |
@@ -190,7 +190,9 @@ module Searchkick | @@ -190,7 +190,9 @@ module Searchkick | ||
190 | end | 190 | end |
191 | 191 | ||
192 | def with_highlights(multiple: false) | 192 | def with_highlights(multiple: false) |
193 | - results.zip(highlights(multiple: multiple)) | 193 | + with_hit do |result, hit| |
194 | + [result, hit_highlights(hit, multiple: multiple)] | ||
195 | + end | ||
194 | end | 196 | end |
195 | 197 | ||
196 | def misspellings? | 198 | def misspellings? |