【问题标题】:How to use Tire for "MoreLikeThis" query of ElasticSearch如何使用 Tire 进行 ElasticSearch 的“MoreLikeThis”查询
【发布时间】:2013-08-28 05:24:35
【问题描述】:

我想执行这个exemple

$ curl -XGET 'http://localhost:9200/twitter/tweet/1/_mlt?mlt_fields=tag,content&min_doc_freq=1'

Tire gem。有可能吗?

我的目标是搜索与另一个文档相关的文档。

【问题讨论】:

    标签: ruby rubygems elasticsearch tire


    【解决方案1】:

    它不是直接在轮胎中实现的。但是,Karmi 已将其实现为 tire-contrib 存储库中的轮胎扩展。

    • 源代码:more_like_this.rb
    • 添加gem 'tire-contrib'
    • more_like_this_field(:tag, like_text, options = {min_doc_freq: 1})

    【讨论】:

    • 感谢您的回答。我不确定使用此扩展程序构建类似的请求。您的示例使用“like_text”而不是文档 ID 来查找相关文档。
    • @BastienD 如果我理解正确,那么这个方法是轮胎 DSL 的一部分,这意味着您可以像任何其他方法(查询、大小等)一样将它添加到轮胎的搜索块中。文档 ID 在您的查询中定义,您将类似文本保留为空。
    【解决方案2】:

    好吧,互联网忘记包含这个调用的一个示例(包括源项目),所以这是它的一种风格。

    related_articles = Article.search {
      query {
        more_like_this("#{current_article.title} #{current_article.body}",
          fields: [:title, :description],
          percent_terms_to_match: 0.1,
          min_term_freq: 1,
          min_doc_freq: 1
        )
      }
    }
    puts related_articles.results.count
    puts related_articles.results.first.title if related_articles.present?
    

    这里的问题是上面的 min_term_freq 和 min_doc_freq 参数。他们default to 2 and 5 respectively in ElasticSearch,这使得在测试时很容易混淆。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-10
      • 1970-01-01
      • 2012-07-26
      • 1970-01-01
      • 2013-10-23
      • 2013-12-12
      • 1970-01-01
      相关资源
      最近更新 更多