的 “MoreLikeThis” 查询我想执行这个exemple:与Tire gem如何使用轮胎ElasticSearch
$ curl -XGET 'http://localhost:9200/twitter/tweet/1/_mlt?mlt_fields=tag,content&min_doc_freq=1'
。这是可能的吗?
我的目标是搜索与其他文档相关的文档。
的 “MoreLikeThis” 查询我想执行这个exemple:与Tire gem如何使用轮胎ElasticSearch
$ curl -XGET 'http://localhost:9200/twitter/tweet/1/_mlt?mlt_fields=tag,content&min_doc_freq=1'
。这是可能的吗?
我的目标是搜索与其他文档相关的文档。
它不是直接在轮胎中实施。但是,Karmi已将其作为tire-contrib存储库中的轮胎扩展实现。
gem 'tire-contrib'
more_like_this_field(:tag, like_text, options = {min_doc_freq: 1})
好互联网忘了,包括这个呼叫(包括开源项目)的一个简单的例子,所以这里是一个它的风格。
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,这使得测试时容易感到困惑。
感谢您的帮助。我不确定用这个扩展名构建类似的请求。你的例子使用“like_text”而不是文件id来查找相关文件。 –
@BastienD如果我已经正确理解了这一点,那么这个方法是轮胎DSL的一部分,这意味着您可以像其他任何方法(查询,尺寸等)一样将它添加到轮胎搜索块中。文档ID在您的查询中定义,您将类似文本留空。 –
你已经使用这个宝石? –