Rails elasticsearch 如何 正确滴全文搜索的

hammer · November 25, 2014 · 2532 hits

先引用

include Elasticsearch::Model
include Elasticsearch::Model::Callbacks

分别尝试了 2 种查询方式,根据 topics 的 title 与 body 的内容 全文搜索

Model.search(
  query: {
    multi_match: {
      query: params[:q].to_s,
      fields: ['title', 'body']
    }
  }
).records
def more_like_this(num = 5)
  Topic.search(
    query: {
      more_like_this: {
        fields: ['title', 'body'],
        like_text: title + '\n' + body
      }
    }
  ).records.to_a rescue []
end

对 elasticsearch 不太熟悉,这 2 种形式 查询的都不太准确,时有时无

No Reply at the moment.
You need to Sign in before reply, if you don't have an account, please Sign up first.