加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – sunspot_solr – NoMethodError(未定义的方

发布时间:2020-12-17 02:02:40 所属栏目:百科 来源:网络整理
导读:我有一个与使用sunspot_solr有关的问题.我有一个应用程序,使用此gem执行一些搜索.有5个型号具有此功能,其中只有1个显示错误 @search.resultsNoMethodError (undefined method `result=' for nil:NilClass): app/controllers/financial_dashboards_controller
我有一个与使用sunspot_solr有关的问题.我有一个应用程序,使用此gem执行一些搜索.有5个型号具有此功能,其中只有1个显示错误

@search.results

NoMethodError (undefined method `result=' for nil:NilClass):
  app/controllers/financial_dashboards_controller.rb:27:in `index'

这是我的代码:

调节器

@search = Sunspot.search(Purchase) do
   fulltext params[:search]
   with(:product_owner).equal_to(current_user.id)
   facet(:status)
   if params[:status].present?
      with(:status).equal_to(params[:status]) 
   end
   facet(:sell_date)
   if params[:sell_date].present?
      with(:sell_date).equal_to(params[:sell_date])
   end
   order_by(:sell_date,:desc)
end

#line 27
@sales = @search.results.paginate(:page => params[:page],:per_page => 5)

型号(购买):

searchable do
  text :product_name
  text :product_short_description
  integer :product_owner
  string :status
  string :sell_date
end         

def product_name
  product.name
end

def product_short_description
  product.short_description
end

def product_owner
  product.user.id
end

def sell_date
  date.to_s(:year_month)
end

#indicates status of the payment and delivery
def status()
    if !self.closed.nil?
    I18n.t('purchases.status.finished')
    elsif !self.measured.nil?
    I18n.t('purchases.status.measured')
    elsif !self.accomplished.nil?
    I18n.t('purchases.status.delivered')
    elsif !self.paid.nil?
    I18n.t('purchases.status.paid')
    elsif !self.canceled.nil?
    I18n.t('purchases.status.canceled')
    elsif !self.date.nil?
    I18n.t('purchases.status.waiting_payment')
    end
end

另一个奇怪的事情是,在我的开发机器上,这段代码完美无缺.在使用nginx的生产计算机上,代码显示此错误.

我检查了宝石的版本,他们匹配.我试过了

rake sunspot:solr:reindex RAILS_ENV=production

重新索引.我试过了

rake sunspot:solr:stop RAILS_ENV=production
rake sunspot:solr:start RAILS_ENV=production

重新启动搜索服务器.甚至尝试删除solr /文件夹并让启动脚本再次复制它.

为什么其他型号完美运作?任何想法如何解决这个问题?

谢谢

解决方法

就我而言,这是一个关键字段(id)不唯一的情况.

之所以发生这种情况是因为我设计了一个具有非独特id字段的mysql视图.

这就是为什么太阳黑子在下一个非独特行指数化过程中总是“下降”首次命中为零.

所以

hit.result = result

在太阳黑子宝石代码的某个地方引发了一个错误

当我想出来的时候(我已经花了几个小时),我只是让我的id字段独一无二,重新索引我的模型并且问题已经消失了.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读