I am using Rails 3.1 and have been using this railscast tutorial to implement sunspot. I am following everything right (i think) however when I run the search like this:
class ProductsController < ApplicationController
# GET /products
# GET /products.xml
def index
@search = Product.search do
fulltext params[:search]
end
@products = @search.results
respond_to do |format|
format.html
format.xml { render :xml => @products }
end
end...
Here's how I have declared the searchable
in my product.rb file
searchable do
text :title
end
However I keep running in to the following error
undefined method `results' for #<MetaSearch::Searches::Product:0x12a089f50>
But when I do just a @products = @search
, i get a full list of all the products, no matter what i send in the search query
Anyone have any idea what I am doing wrong?
Are you sure there are no conflicts with other search gems? I can't test it at the moment, but I'm fairly sure Sunspot doesn't use MetaSearch::Searches. However, this gem does: https://github.com/ernie/meta_search/.
Have you tried doing this instead?
@search = Sunspot.search(Product) do
fulltext params[:search]
end
That way you can be sure that it uses Sunspot to search and not some other gem. Also if you need more searching gems then put Sunspot above them in the gemfile.
Sunspot will refuse to define the class search
method if the class already has one defined. You can instead use the solr_search
method to the same effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With