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.
答案 0 :(得分:0)
通过上述评论中的一些讨论找到了解决方案。一些想法可能会帮助遇到类似问题的其他人:
rake ts:rebuild
,当然在升级Sphinx时(其索引格式通常会在次要版本之间发生变化)。