lib/searchkick/index_options.rb in searchkick-4.4.4 vs lib/searchkick/index_options.rb in searchkick-4.5.0

- old
+ new

@@ -233,10 +233,31 @@ }, searchkick_search2: { type: "kuromoji" } ) + when "japanese2" + analyzer = { + type: "custom", + tokenizer: "kuromoji_tokenizer", + filter: [ + "kuromoji_baseform", + "kuromoji_part_of_speech", + "cjk_width", + "ja_stop", + "searchkick_stemmer", + "lowercase" + ] + } + settings[:analysis][:analyzer].merge!( + default_analyzer => analyzer.deep_dup, + searchkick_search: analyzer.deep_dup, + searchkick_search2: analyzer.deep_dup + ) + settings[:analysis][:filter][:searchkick_stemmer] = { + type: "kuromoji_stemmer" + } when "korean" settings[:analysis][:analyzer].merge!( default_analyzer => { type: "openkoreantext-analyzer" }, @@ -510,11 +531,21 @@ synonyms: search_synonyms.select { |s| s.size > 1 }.map { |s| s.is_a?(Array) ? s.join(",") : s }.map(&:downcase) } end settings[:analysis][:filter][:searchkick_synonym_graph] = synonym_graph - [:searchkick_search2, :searchkick_word_search].each do |analyzer| - settings[:analysis][:analyzer][analyzer][:filter].insert(2, "searchkick_synonym_graph") + if options[:language] == "japanese2" + [:searchkick_search, :searchkick_search2].each do |analyzer| + settings[:analysis][:analyzer][analyzer][:filter].insert(4, "searchkick_synonym_graph") + end + else + [:searchkick_search2, :searchkick_word_search].each do |analyzer| + unless settings[:analysis][:analyzer][analyzer].key?(:filter) + raise Searchkick::Error, "Search synonyms are not supported yet for language" + end + + settings[:analysis][:analyzer][analyzer][:filter].insert(2, "searchkick_synonym_graph") + end end end end def add_wordnet(settings)