0
我正在嘗試基於用戶輸入的文本進行solr搜索。我必須檢查輸入的文字是商店還是品牌或類別。檢查完條件後,我想使用solr搜索顯示MainNavigationUrls表中相應的riesults。這是控制器操作。如果我進入任何商店並且可以得到適當的結果,它工作正常。但是,如果商店搜索被發現,它不會進入品牌循環。請解釋爲什麼它不執行第二種情況。如果rails中的條件未執行
def search_all
@storesearch=Site.search do
fulltext params[:text]
with(:multibrand,1)
end
if(@storesearch.nil?)
@brandsearch=Brand.search do
fulltext params[:text]
end
if(@brandssearch.nil?)
@itemcategorysearch=MainCategory.search do
fulltext params[:text]
end
@itemcategorysearch.results.each do |result|
@itemcategorysearch1=MainNavigationUrl.search do
with :main_categoty_id, result.id
with :department_id, params[:deptid].to_i
paginate :page=>params[:page], :per_page=>45
end
end
else
@brandsearch.results.each do |result|
@brandsearch1=MainNavigationUrl.search do
with :brand_id, result.id
with :department_id, params[:deptid].to_i
paginate :page=>params[:page], :per_page=>45
end
end
else
@storesearch.results.each do |result|
@storesearch1=MainNavigationUrl.search do
with :site_id, result.id
with :department_id, params[:deptid].to_i
paginate :page=>params[:page], :per_page=>45
end
end
end
end
我得到了答案...我只是用if(@ storesearch.results.empty?)替換(@ storesearch.nil?)......感謝您的支持.... :) – user2218532 2013-04-20 10:21:17