是否可以在不同的数据类型中使用more_like_this?

时间:2012-12-27 21:10:23

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

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

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

我想这取决于more_like_this是否按照“Articles基于一组标准与Article相似”的行进行操作“或者是否按照根据一系列标准“更多与此Article相似的内容”......

我的用例是,如果我正在显示Article,并且我想在页面的一侧显示相关内容 - 可能是其他Articles,{{ 1}}在同一类别中,或Videos在相关主题上等。

1 个答案:

答案 0 :(得分:4)

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

  

+(Object)more_like_this(object,* types,&amp; block)启动MoreLikeThis搜索。 MoreLikeThis是一种特殊类型的搜索   使用全文比较查找类似的文档。要成为的领域   比较是使用text选项设置的:more_like_this字段   设为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

相关问题