繁体   English   中英

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

[英]undefined method “results” with Sunspot Solr Search

我正在使用Rails 3.1并且一直在使用这个railscast教程来实现太阳黑子。 我正在关注一切(我认为)然而当我像这样运行搜索时:

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 ,无论我在搜索查询中发送什么,我都会得到所有产品的完整列表

任何人都知道我做错了什么?

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

你试过这样做吗?

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

这样你可以确定它使用太阳黑子来搜索而不是其他一些宝石。 此外,如果你需要更多搜索宝石,那么在宝石文件中将太阳黑子放在它们之上。

如果类已经定义了一个,那么太阳黑子将拒绝定义类search方法。 您可以使用solr_search方法获得相同的效果。

谢谢Nick Zadrozny,

由于这个问题,我们的团队今天辩论。

问题的根本原因是我们添加了Active admin。

我们必须将所有“.search”更改为“.solr_search”

在我的例子中是表单的rails标签,它不是@Class_form ,它是<% form_tag posts_path, :method => :get %>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM