新手问题 ElasticSearch 搜索中文不准的问题

a886937 · April 13, 2020 · Last by a886937 replied at April 15, 2020 · 3562 hits

使用的 gem 是 searchkick
安装了对应版本的 analysis-ik plugin 分词插件
在启动日志也有 loaded plugin [analysis-ik]
查询语句:

FtFamily.search '伯祥',fields: [:fName], match: :word

model:

class FtFamily < ApplicationRecord
    searchkick word: [:fName], language: "chinese"

    self.table_name="FtFamily"
    self.primary_key = "id"
end

从结果看出有些完全无关,搜英文倒是贼准😂 。是不是我插件没安装好啊,各位求教。

你应该要指定 Tokenizer 和 analyzer

2 Floor has deleted

感谢回答,指定是在 model 处添加 mappings,Settings 吗?

在 model 层,贴一小段老代码

settings analysis: {
    analyzer: {
      char_split: {type: 'custom', tokenizer: 'ngram_tokenizer', filter: ['lowercase']},
      comma_separated_path: {type: 'custom', tokenizer: 'comma_separated_path_tokenizer'},
    },
    tokenizer: {
      ngram_tokenizer: {type: 'nGram', min_gram: 1, max_gram: 1, token_chars: ['letter', 'digit', 'punctuation']},
      comma_separated_path_tokenizer: {delimiter: ',', type: 'PathHierarchy'}
    },
    normalizer: { lowercase: {type: 'custom', char_filter: [], filter: ["lowercase"]}},
    filter: {lowercase: { type: 'lowercase'}}
  } do
    mapping dynamic: false do
      indexes :subject, type: :keyword do
        indexes :raw, type: :keyword, normalizer: :lowercase
        indexes :tokenized, analyzer: :char_split
      end

不过没有用 searchkick 用的 elasticsearch ruby 的 gem,searchkick 不熟

Reply to pathbox

谢谢回答,我试试。感觉 es 最难的部分就是这段配置了,没啥很明确的文档看一看,全靠 google

Reply to pathbox

nice,谢谢大佬。

a886937 closed this topic. 06 Mar 17:57
You need to Sign in before reply, if you don't have an account, please Sign up first.