Commit 76dfee5646adb43d8169acc890fa36d5c4abfdfe
1 parent
d4ee48c8
Exists in
master
and in
21 other branches
Added ability to search all with *
Showing
2 changed files
with
37 additions
and
24 deletions
Show diff stats
lib/searchkick/search.rb
... | ... | @@ -33,39 +33,43 @@ module Searchkick |
33 | 33 | conversions_field = @searchkick_options[:conversions] |
34 | 34 | personalize_field = @searchkick_options[:personalize] |
35 | 35 | |
36 | + all = term == "*" | |
37 | + | |
36 | 38 | # TODO lose Tire DSL for more flexibility |
37 | 39 | s = |
38 | 40 | Tire::Search::Search.new do |
39 | 41 | query do |
40 | 42 | custom_filters_score do |
41 | 43 | query do |
42 | - boolean do | |
43 | - must do | |
44 | - if options[:autocomplete] | |
45 | - match fields, term, analyzer: "searchkick_autocomplete_search" | |
46 | - else | |
47 | - dis_max do | |
48 | - query do | |
49 | - match fields, term, use_dis_max: false, boost: 10, operator: operator, analyzer: "searchkick_search" | |
50 | - end | |
51 | - query do | |
52 | - match fields, term, use_dis_max: false, boost: 10, operator: operator, analyzer: "searchkick_search2" | |
53 | - end | |
54 | - query do | |
55 | - match fields, term, use_dis_max: false, fuzziness: 1, max_expansions: 3, operator: operator, analyzer: "searchkick_search" | |
56 | - end | |
57 | - query do | |
58 | - match fields, term, use_dis_max: false, fuzziness: 1, max_expansions: 3, operator: operator, analyzer: "searchkick_search2" | |
44 | + if !all | |
45 | + boolean do | |
46 | + must do | |
47 | + if options[:autocomplete] | |
48 | + match fields, term, analyzer: "searchkick_autocomplete_search" | |
49 | + else | |
50 | + dis_max do | |
51 | + query do | |
52 | + match fields, term, use_dis_max: false, boost: 10, operator: operator, analyzer: "searchkick_search" | |
53 | + end | |
54 | + query do | |
55 | + match fields, term, use_dis_max: false, boost: 10, operator: operator, analyzer: "searchkick_search2" | |
56 | + end | |
57 | + query do | |
58 | + match fields, term, use_dis_max: false, fuzziness: 1, max_expansions: 3, operator: operator, analyzer: "searchkick_search" | |
59 | + end | |
60 | + query do | |
61 | + match fields, term, use_dis_max: false, fuzziness: 1, max_expansions: 3, operator: operator, analyzer: "searchkick_search2" | |
62 | + end | |
59 | 63 | end |
60 | 64 | end |
61 | 65 | end |
62 | - end | |
63 | - if conversions_field and options[:conversions] != false | |
64 | - should do | |
65 | - nested path: conversions_field, score_mode: "total" do | |
66 | - query do | |
67 | - custom_score script: "doc['count'].value" do | |
68 | - match "query", term | |
66 | + if conversions_field and options[:conversions] != false | |
67 | + should do | |
68 | + nested path: conversions_field, score_mode: "total" do | |
69 | + query do | |
70 | + custom_score script: "doc['count'].value" do | |
71 | + match "query", term | |
72 | + end | |
69 | 73 | end |
70 | 74 | end |
71 | 75 | end |
... | ... | @@ -182,6 +186,10 @@ module Searchkick |
182 | 186 | |
183 | 187 | payload = s.to_hash |
184 | 188 | |
189 | + if all | |
190 | + payload[:query][:custom_filters_score][:query][:match_all] = {} | |
191 | + end | |
192 | + | |
185 | 193 | # An empty array will cause only the _id and _type for each hit to be returned |
186 | 194 | # http://www.elasticsearch.org/guide/reference/api/search/fields/ |
187 | 195 | payload[:fields] = [] if load | ... | ... |
test/match_test.rb