未定义的方法“结果”使用太阳黑子 Solr 搜索

发布于 2024-12-12 05:52:42 字数 845 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

如痴如狂 2024-12-19 05:52:42

您确定与其他搜索宝石没有冲突吗?我目前无法测试它,但我相当确定 Sunspot 不使用 MetaSearch::Searches。然而,这个 gem 确实:https://github.com/ernie/meta_search/

你尝试过这样做吗?

@search = Sunspot.search(Product) do
  fulltext params[:search]
end

这样您就可以确定它使用太阳黑子而不是其他宝石进行搜索。另外,如果您需要更多搜索宝石,请将太阳黑子放在宝石文件中的上方。

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.

无言温柔 2024-12-19 05:52:42

如果类已经定义了一个搜索方法,Sunspot 将拒绝定义该类的搜索方法。您可以使用 solr_search 方法来达到相同的效果。

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.

┊风居住的梦幻卍 2024-12-19 05:52:42

谢谢 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"

鲸落 2024-12-19 05:52:42

就我而言,是表单的 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 %>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文