将相关记录添加到搜索结果中

时间:2014-06-27 21:03:01

标签: ruby-on-rails solr sunspot

我正在尝试为用户查询我的solr索引。我有一个与User模型关联的UsersPhoto模型。当我查询索引时,我希望能够获得每个结果的关联用户照片。

这是我的搜索方法:

def json_index_searches_users_profile_with_limit_and_offset_and_keyword

    search_term = params[:keyword]
    search_term.downcase!

    @search = Sunspot.search(Users) do
      fulltext search_term
    end

    @users = @search.results

    respond_to do |format|
      format.json { render json: @ users }
    end
  end



@users = [#<User id: 25, email: "********.com", created_at: "2013-07-16 22:32:23",
 updated_at: "2014-04-18 18:36:46", password_digest: 
"$2a$10$cEQ3u7pI8n23MheSLI2KIOvYOdaG86TXV6utgGMHCslE...", remember_token: "7T6pIm-BTus9-
USjM314fA", admin: true, username: "********", password_reset_token: nil, 
password_reset_sent_at: nil, provider: nil, uid: nil, generated_password: false>, #<User 
id: 37690, email: "********.com", created_at: "2014-06-09 16:07:59", updated_at: "2014-
06-09 16:07:59", password_digest: 
"$2a$10$g8F9QjmgWhkMDomUWIdgUekVzGrFMe7aCmZiL0MZsbJM...", remember_token: "l3g9P-
1VH5byOSB8C2azXg", admin: false, username: "********", password_reset_token: nil, 
password_reset_sent_at: nil, provider: nil, uid: nil, generated_password: false>, #<User
 id: 41480, email: "********.com", created_at: "2014-06-14 00:44:55", updated_at: "2014-
06-14 00:44:55", password_digest: "$2a$10$JQPT/JhXp9CQ81TtT0p ....

0 个答案:

没有答案