lib/searchkick/index.rb in searchkick-0.9.0 vs lib/searchkick/index.rb in searchkick-0.9.1
- old
+ new
@@ -128,11 +128,12 @@
end
end
# reindex
- def create_index
+ def create_index(options = {})
+ index_options = options[:index_options] || self.index_options
index = Searchkick::Index.new("#{name}_#{Time.now.strftime('%Y%m%d%H%M%S%L')}", @options)
index.create(index_options)
index
end
@@ -151,11 +152,11 @@
def reindex_scope(scope, options = {})
skip_import = options[:import] == false
clean_indices
- index = create_index
+ index = create_index(index_options: scope.searchkick_index_options)
# check if alias exists
if alias_exists?
# import before swap
index.import_scope(scope) unless skip_import
@@ -215,22 +216,27 @@
tokenizer: "keyword",
filter: ["lowercase"] + (options[:stem_conversions] == false ? [] : ["searchkick_stemmer"])
},
default_index: {
type: "custom",
+ # character filters -> tokenizer -> token filters
+ # https://www.elastic.co/guide/en/elasticsearch/guide/current/analysis-intro.html
+ char_filter: ["ampersand"],
tokenizer: "standard",
# synonym should come last, after stemming and shingle
# shingle must come before searchkick_stemmer
filter: ["standard", "lowercase", "asciifolding", "searchkick_index_shingle", "searchkick_stemmer"]
},
searchkick_search: {
type: "custom",
+ char_filter: ["ampersand"],
tokenizer: "standard",
filter: ["standard", "lowercase", "asciifolding", "searchkick_search_shingle", "searchkick_stemmer"]
},
searchkick_search2: {
type: "custom",
+ char_filter: ["ampersand"],
tokenizer: "standard",
filter: ["standard", "lowercase", "asciifolding", "searchkick_stemmer"]
},
# https://github.com/leschenko/elasticsearch_autocomplete/blob/master/lib/elasticsearch_autocomplete/analyzers.rb
searchkick_autocomplete_index: {
@@ -309,11 +315,21 @@
type: "nGram",
min_gram: 1,
max_gram: 50
},
searchkick_stemmer: {
- type: "snowball",
+ # use stemmer if language is lowercase, snowball otherwise
+ # TODO deprecate language option in favor of stemmer
+ type: options[:language] == options[:language].to_s.downcase ? "stemmer" : "snowball",
language: options[:language] || "English"
+ }
+ },
+ char_filter: {
+ # https://www.elastic.co/guide/en/elasticsearch/guide/current/custom-analyzers.html
+ # &_to_and
+ ampersand: {
+ type: "mapping",
+ mappings: ["&=> and "]
}
},
tokenizer: {
searchkick_autocomplete_ngram: {
type: "edgeNGram",