Commit e028b9ba369ef368dd8fc23a7913cf88cae532d1

Authored by Andrew Kane
1 parent cd7c1bf0

Added word option

CHANGELOG.md
1 1 ## 1.0.4 [unreleased]
2 2  
3   -- Added `word: false` option
4 3 - Added `match` option
  4 +- Added `word: false` option
5 5 - Added highlighted fields to `load: false`
6 6  
7 7 ## 1.0.3
... ...
README.md
... ... @@ -220,15 +220,11 @@ By default, results must match the entire word - `back` will not match `backpack
220 220  
221 221 ```ruby
222 222 class Product < ActiveRecord::Base
223   - searchkick word_start: [:name]
  223 + searchkick match: :word_start
224 224 end
225 225 ```
226 226  
227   -And to search (after you reindex):
228   -
229   -```ruby
230   -Product.search "back", fields: [{name: :word_start}]
231   -```
  227 +And reindex.
232 228  
233 229 Available options are:
234 230  
... ... @@ -242,12 +238,6 @@ Available options are:
242 238 :text_end
243 239 ```
244 240  
245   -To boost fields, use:
246   -
247   -```ruby
248   -fields: [{"name^2" => :word_start}] # better interface on the way
249   -```
250   -
251 241 ### Exact Matches
252 242  
253 243 ```ruby
... ...
lib/searchkick/index.rb
... ... @@ -409,10 +409,12 @@ module Searchkick
409 409 end
410 410  
411 411 mapping_options = Hash[
412   - [:autocomplete, :suggest, :text_start, :text_middle, :text_end, :word_start, :word_middle, :word_end, :highlight]
  412 + [:autocomplete, :suggest, :word, :text_start, :text_middle, :text_end, :word_start, :word_middle, :word_end, :highlight]
413 413 .map { |type| [type, (options[type] || []).map(&:to_s)] }
414 414 ]
415 415  
  416 + word = options[:word] != false && (!options[:match] || options[:match] == :word)
  417 +
416 418 mapping_options.values.flatten.uniq.each do |field|
417 419 field_mapping = {
418 420 type: "multi_field",
... ... @@ -421,7 +423,7 @@ module Searchkick
421 423 }
422 424 }
423 425  
424   - unless options[:word] == false
  426 + if word
425 427 field_mapping[:fields]["analyzed"] = {type: "string", index: "analyzed"}
426 428 end
427 429  
... ... @@ -431,7 +433,7 @@ module Searchkick
431 433 end
432 434 end
433 435  
434   - if mapping_options[:highlight].include?(field)
  436 + if word && mapping_options[:highlight].include?(field)
435 437 field_mapping[:fields]["analyzed"][:term_vector] = "with_positions_offsets"
436 438 end
437 439  
... ... @@ -466,7 +468,9 @@ module Searchkick
466 468  
467 469 if options[:match] && options[:match] != :word
468 470 dynamic_fields[options[:match]] = {type: "string", index: "analyzed", analyzer: "searchkick_#{options[:match]}_index"}
469   - elsif options[:word] != false
  471 + end
  472 +
  473 + if word
470 474 dynamic_fields["analyzed"] = {type: "string", index: "analyzed"}
471 475 end
472 476  
... ...
test/highlight_test.rb
... ... @@ -37,6 +37,7 @@ class HighlightTest &lt; Minitest::Test
37 37 end
38 38  
39 39 def test_json
  40 + skip if ENV["MATCH"] == "word_start"
40 41 store_names ["Two Door Cinema Club"]
41 42 json = {
42 43 query: {
... ...