我有一个使用sunspot_solr的问题。我有一个应用程序使用这个宝石执行一些搜索。有5种型号具有此功能,但其中只有1示出了sunspot_solr - NoMethodError(undefined方法`结果='为零:NilClass)
@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 /文件夹,并让启动脚本再次复制它。
为什么其他模型完美工作?任何想法如何解决这个问题?
谢谢
你能找到你的问题的答案? –
@ search.hits包含什么? –