Sphinx Issue with Ruby 1.9.3?

时间:2018-01-23 19:20:21

标签: ruby-on-rails ruby sphinx thinking-sphinx ruby-1.9.3

I have recently moved a web app from ruby 1.8.7 to 1.9.3 and everything is going great, except for searching. Everything was working fine before bumping ruby. Here's my controller code:

ids = Business.simple_search_for_ids_with_location(@term, @city, @state, {}, :per_page => 2500)
      @results = Business.paginate :conditions => { :id => ids }, :page => ActionController::Base.helpers.sanitize(params[:page]), :include => [:category]
      @results = @results.sort{|a,b| a.name.downcase <=> b.name.downcase}
      @count = @results.total_entries

And from my model:

def self.simple_search_for_ids_with_location(term, city, state, conditions={}, options={})
  ids = Business.compact_search_for_ids(term, {:conditions => { :address_city => city, :address_state => state }.merge(conditions), :order => :business_name}.merge(options))
  if state.blank?
    by_state = Business.compact_search_for_ids(term, {:conditions => { :address_state => city }.merge(conditions), :order => :business_name}.merge(options))
    ids += by_state
  end
  ids
end

def self.compact_search_for_ids(*args)
  search_for_ids(*args).compact
end

When running in the browser I get undefined method total_entries for []:Array

And the offending line is @count = @results.total_entries

I have made sure that sphinx is installed and thinking_sphinx has indexed and is running.

It appears that everything is working somewhat, but an empty array is being returned? Why would this have worked fine before?

I appreciate any help I can get here, as I really don't want to go back to ruby 1.8.7. Thank you.

1 个答案:

答案 0 :(得分:0)

通过上述评论中的一些讨论找到了解决方案。一些想法可能会帮助遇到类似问题的其他人:

  • 如果您使用的是Thinking Sphinx v1.x或2.x,最好坚持使用旧的Sphinx版本。建议不要高于Sphinx v2.0.x.
  • 确保在升级Thinking Sphinx时运行rake ts:rebuild,当然在升级Sphinx时(其索引格式通常会在次要版本之间发生变化)。
  • 如果您能够升级到更新版本的Ruby / Rails / Thinking Sphinx,那么它总是有助于长期维护(但可以理解的并不总是可行)。