diff --git a/CHANGELOG.md b/CHANGELOG.md index d47e526..17baf00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## 1.0.4 [unreleased] -- Added `word: false` option - Added `match` option +- Added `word: false` option - Added highlighted fields to `load: false` ## 1.0.3 diff --git a/README.md b/README.md index a9efd30..ab947d5 100644 --- a/README.md +++ b/README.md @@ -220,15 +220,11 @@ By default, results must match the entire word - `back` will not match `backpack ```ruby class Product < ActiveRecord::Base - searchkick word_start: [:name] + searchkick match: :word_start end ``` -And to search (after you reindex): - -```ruby -Product.search "back", fields: [{name: :word_start}] -``` +And reindex. Available options are: @@ -242,12 +238,6 @@ Available options are: :text_end ``` -To boost fields, use: - -```ruby -fields: [{"name^2" => :word_start}] # better interface on the way -``` - ### Exact Matches ```ruby diff --git a/lib/searchkick/index.rb b/lib/searchkick/index.rb index 4ce3659..6b500e8 100644 --- a/lib/searchkick/index.rb +++ b/lib/searchkick/index.rb @@ -409,10 +409,12 @@ module Searchkick end mapping_options = Hash[ - [:autocomplete, :suggest, :text_start, :text_middle, :text_end, :word_start, :word_middle, :word_end, :highlight] + [:autocomplete, :suggest, :word, :text_start, :text_middle, :text_end, :word_start, :word_middle, :word_end, :highlight] .map { |type| [type, (options[type] || []).map(&:to_s)] } ] + word = options[:word] != false && (!options[:match] || options[:match] == :word) + mapping_options.values.flatten.uniq.each do |field| field_mapping = { type: "multi_field", @@ -421,7 +423,7 @@ module Searchkick } } - unless options[:word] == false + if word field_mapping[:fields]["analyzed"] = {type: "string", index: "analyzed"} end @@ -431,7 +433,7 @@ module Searchkick end end - if mapping_options[:highlight].include?(field) + if word && mapping_options[:highlight].include?(field) field_mapping[:fields]["analyzed"][:term_vector] = "with_positions_offsets" end @@ -466,7 +468,9 @@ module Searchkick if options[:match] && options[:match] != :word dynamic_fields[options[:match]] = {type: "string", index: "analyzed", analyzer: "searchkick_#{options[:match]}_index"} - elsif options[:word] != false + end + + if word dynamic_fields["analyzed"] = {type: "string", index: "analyzed"} end diff --git a/test/highlight_test.rb b/test/highlight_test.rb index 41d3555..5e1d421 100644 --- a/test/highlight_test.rb +++ b/test/highlight_test.rb @@ -37,6 +37,7 @@ class HighlightTest < Minitest::Test end def test_json + skip if ENV["MATCH"] == "word_start" store_names ["Two Door Cinema Club"] json = { query: { -- libgit2 0.21.0