【问题标题】:Is it possible to use more_like_this across different data types?是否可以在不同的数据类型中使用 more_like_this?
【发布时间】:2012-12-27 21:10:22
【问题描述】:

The documentation for more_like_this 展示了如何使用它来获取更多基于标准相似的相同类型的内容:

class Post < ActiveRecord::Base
  searchable do
    # The :more_like_this option must be set to true
    text :body, :more_like_this => true
  end
end

post = Post.first

results = Sunspot.more_like_this(post) do
  fields :body
  minimum_term_frequency 5
end

我想知道是否可以返回不同数据类型的相关项目。例如,VideosArticles 相关/相似。

我想这取决于more_like_this 是按照“更多Articles 基于一组标准与Article 相似”的思路运行,还是按照“更多基于一组标准,类似于此Article"...

我的用例是如果我要显示 Article,并且我想在页面的一侧显示相关内容 - 可能是其他 ArticlesVideos 相同的内容类别,或Events 相关主题等。

【问题讨论】:

    标签: ruby-on-rails sunspot sunspot-rails sunspot-solr


    【解决方案1】:

    http://sunspot.github.com/sunspot/docs/Sunspot.html#more_like_this-class_method

    + (Object) more_like_this(object, *types, &block) 启动 MoreLikeThis 搜索。 MoreLikeThis 是一种特殊类型的搜索, 使用全文比较查找相似的文档。要成为的领域 比较的是使用 :more_like_this 选项设置的 text 字段 设置为true。默认情况下,更像这样返回相同的对象 类型作为用于比较的对象,但类型列表可以 可选地传递给此方法以返回类似的文档 其他类型。这仅适用于具有公共字段的类型。

    示例:

      post = Post.first
      Sunspot.more_like_this(post, Post, Page) do
        fields :title, :body
        with(:updated_at).greater_than(1.month.ago)
        facet(:category_ids)
      end
    

    另见:http://sunspot.github.com/sunspot/docs/Sunspot/Query/MoreLikeThis.html

    【讨论】:

    • 谢谢!不幸的是,我遇到了this bug,它禁止通过more_like_this 传递多个对象-因此,在您的示例中Page ...或Sunspot.more_like_this(post, Post, Page, Video, Event) 作为另一个示例失败并出现undefined method 'more_like_this_fields' 错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-15
    • 1970-01-01
    相关资源
    最近更新 更多