Solr Sunspot - 如何通过Sunspot搜索提升belongs_to关联?

时间:2016-04-20 14:09:45

标签: ruby-on-rails mongodb solr sunspot

我使用Sunspot Solr在我们的Ruby on Rails应用程序中使用MongoDB数据库(Mongo mapper)进行索引和搜索

我有类文章属于用户。我使用Sunspot SOLR索引我的对象User。它看起来像这样:

    class Article
    include ActiveModel::Serializers::JSON
    include MongoMapper::Document
    include Sunspot::Mongo
    ...


    key :title, String
    key :introduction, String
    key :cover, String
    ...

    belongs_to :user
    ...

    searchable do
      text :title, :boost => 5
      text :user do
        user.username if user
      end
      string(:category)
      boolean(:published)
    end

我能够成功搜索Top模型的user.username字段,但是当我提升此字段时,例如:

  text :user, :boost => 10  do
    user.username if user
  end

它不工作,太阳黑子完全忽略了提升(标题字段效果很好)

是语法错误吗?

请帮忙!

感谢。

0 个答案:

没有答案