开发者

ActsAsSolr::SearchResults

In my ROR application using acts_as_solr plugin as a search engine which runs on top of Lucene library.

now, i am able to search the results as below in controller

def search @user_class=User.find_by_solr("rajesh") respond_to do |format| format.html # search.html.erb format.xml { render :xml => @user_class } end

my question is how can i display the search results in search.html.erb page

prese开发者_开发知识库ntly doing as below

but getting error as

undefined method `each' for ActsAsSolr::SearchResults:0x463c2e4

Help me , Mahesh


Your @user_class object is not an array, but an instance of the class ActsAsSolr::SearchResults. To access the resulting documents, call its docs method:

<% for user_class in @user_class.docs %>
  <%= user_class.name %>
<% end %>

Your @user_class object also contains other useful information like:

@user_class.total     # total number of results
@user_class.max_score # highest score of any result

See lib/search_results.rb in the acts_as_solr source code for all the available methods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜