0
votes

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

presently doing as below

but getting error as

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

Help me , Mahesh

1

1 Answers

1
votes

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.