Acts_as_solr problem ActsAsSolr::SearchResults:

hi,

 i am using acts_as_solr plugin when i tried with search

by
def search
puts “#####################”
# ids = params[:name]
@id = params[:query]
@emp = Employee.find_by_solr(@id)
puts “------------------------------#{@emp}”

respond_to do |format|
  format.html{render :action => 'search'}
  format.xml
end

end

in my model i gave

acts_as_solr :fields => [ :name ]

when i tried with search

puts “------------------------------#{@emp}” shows me the following

 ------------------------------#<ActsAsSolr::SearchResults:

0x9a0f1dc>

any one say me how to retrive value to view page

EMP id<%= @emp.id %>

EMP Name<%= @emp.name %>

in view error occurs as
“undefined method `id’ for nil:NilClass”

thanks,
-pab

As your example shows, when you do Employee.find_by_solr(@id) it does
not
return an Employee instance, but returns an instance of
ActsAsSolr::SearchResults

You will need to iterate through the results:

results = Employee.find_by_solr(@id)
results.each do |emp|
puts emp.id
end

hi,

it shows following error

NoMethodError (undefined method `each’ for #<ActsAsSolr::SearchResults:
0xaa0eb28>):

thanks,
-pab

Looks like you might need to do results.results.each instead

Check the docs:
http://code.paperplanes.de/acts_as_solr/rdoc/classes/ActsAsSolr/SearchResults.htmlhttp://code.paperplanes.de/acts_as_solr/rdoc/classes/ActsAsSolr/SearchResults.html#M000032

On Thu, Sep 8, 2011 at 6:04 AM, Pab [email protected] wrote:

when i tried with search

---------------#ActsAsSolr::SearchResults:0x9a0f1dc

What did you find unclear about the doc for ActsAsSolr::SearchResults?


Hassan S. ------------------------ [email protected]

twitter: @hassan

Did you check the documentation I linked to?

http://code.paperplanes.de/acts_as_solr/rdoc/classes/ActsAsSolr/SearchResults.html

Specifically, have a look at the records() results() or docs() methods.

hi,

i got data using this three and i got another doubt
in table i have changed id as emp_id, when i searched it
it throws an error like

Mysql::Error: Unknown column ‘employees.id’ in ‘where clause’: SELECT
employees.* FROM employees WHERE (employees.id in (NULL))

how can i over come this

thanks,
-pab

hi,

i am using https://github.com/mattmatt/acts_as_solr

which contains no “each” method in acts_as_solr/libs/
search_results.rb

so for me each is not working with ActsAsSolr::SearchResults

and i tried with GitHub - mauricio/acts_as_solr: acts_as_solr active_record plugin to make your active_record models indexable using the Solr full text search tool plugin

wich results in following error "undefined method ‘find_by_solr’ for "

can any one provide me solution for this

thanks
-pab

its searching for id where as i changed it as emp_id
is there any solution for this?