diff --git a/CHANGELOG.md b/CHANGELOG.md index 397c389..3078c80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.8.5 [unreleased] + +- Added `unsearchable` option + ## 0.8.4 - Added `boost_by_distance` diff --git a/lib/searchkick/reindex.rb b/lib/searchkick/reindex.rb index ad7efb9..f5f6290 100644 --- a/lib/searchkick/reindex.rb +++ b/lib/searchkick/reindex.rb @@ -288,12 +288,19 @@ module Searchkick mapping[field] = field_mapping end - (options[:locations] || []).each do |field| + (options[:locations] || []).map(&:to_s).each do |field| mapping[field] = { type: "geo_point" } end + (options[:unsearchable] || []).map(&:to_s).each do |field| + mapping[field] = { + type: "string", + index: "no" + } + end + mappings = { _default_: { properties: mapping, diff --git a/test/match_test.rb b/test/match_test.rb index 20f2de2..0dad347 100644 --- a/test/match_test.rb +++ b/test/match_test.rb @@ -153,4 +153,11 @@ class TestMatch < Minitest::Test assert_search "to be", ["to be or not to be"] end + def test_unsearchable + store [ + {name: "Unsearchable", description: "Almond"} + ] + assert_search "almond", [] + end + end diff --git a/test/test_helper.rb b/test/test_helper.rb index 3c62258..111cea3 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -95,6 +95,7 @@ else t.string :color t.decimal :latitude, precision: 10, scale: 7 t.decimal :longitude, precision: 10, scale: 7 + t.text :description t.timestamps end @@ -146,7 +147,8 @@ class Product word_start: [:name], word_middle: [:name], word_end: [:name], - highlight: [:name] + highlight: [:name], + unsearchable: [:description] attr_accessor :conversions, :user_ids, :aisle -- libgit2 0.21.0