未定义的方法“结果”使用太阳黑子 Solr 搜索
我正在使用 Rails 3.1,并一直在使用这个railscast 教程来实现 sunspot。我遵循的一切都是正确的(我认为)但是当我像这样运行搜索时:
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...
这是我在我的product.rb文件中声明searchable
的方式
searchable do
text :title
end
但是我一直遇到以下错误
undefined method `results' for #<MetaSearch::Searches::Product:0x12a089f50>
但是当我只需执行 @products = @search
,我就会得到所有产品的完整列表,无论我在搜索查询中发送什么内容
有人知道我做错了什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您确定与其他搜索宝石没有冲突吗?我目前无法测试它,但我相当确定 Sunspot 不使用 MetaSearch::Searches。然而,这个 gem 确实:https://github.com/ernie/meta_search/。
你尝试过这样做吗?
这样您就可以确定它使用太阳黑子而不是其他宝石进行搜索。另外,如果您需要更多搜索宝石,请将太阳黑子放在宝石文件中的上方。
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?
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 将拒绝定义该类的搜索方法。您可以使用 solr_search 方法来达到相同的效果。
Sunspot will refuse to define the class
search
method if the class already has one defined. You can instead use thesolr_search
method to the same effect.谢谢 Nick Zadrozny,
我们团队今天因为这个问题进行辩论。
问题的根本原因是我们添加了活动管理员。
我们必须将所有“.search”更改为“.solr_search”
Thank you Nick Zadrozny,
Our team debate today because of this issue.
The root cause of issue is because of we added Active admin.
We had to change all ".search" into ".solr_search"
就我而言,是表单的 Rails 标签,它不是 @Class_form,而是
<% form_tag posts_path, :method =>; :获取%>
In my case was the rails tag of the form, it's not @Class_form, it's
<% form_tag posts_path, :method => :get %>