fix search result removed UID

This commit is contained in:
nccu 2014-11-10 10:03:21 +08:00
parent d82005a7f4
commit b4a9e406eb
1 changed files with 38 additions and 11 deletions

View File

@ -5,26 +5,53 @@ class NewsController < ApplicationController
news = nil news = nil
if params[:keywords] if params[:keywords]
news = NewsBulletin.where(:title.ne => "").any_of(:title => /#{params[:keywords].to_s}/i).is_approved.order_by(:created_at=>'desc').filter_by_categories(["all"]).per(15) if !params[:keywords].nil? !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:postdate=>"desc"}
news = NewsBulletin.where(:title.ne => "").any_of(:title => /#{params[:keywords].to_s}/i).is_approved.order_by(sort).filter_by_categories(["all"]).per(15) if !params[:keywords].nil?
news_count = news.count news_count = news.count
keyword = params[:keywords] keyword = params[:keywords]
elsif params["department"] elsif params[:department]
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:postdate=>"desc"}
dept = Department.find_by(:uid => params["department"].split("-").last) rescue nil dept = Department.find_by(:uid => params["department"].split("-").last) rescue nil
news = NewsBulletin.where(:title.ne => "" ,:department => dept).is_approved.order_by(:created_at=>'desc').filter_by_categories(["all"]) if !dept.nil? news = NewsBulletin.where(:title.ne => "" ,:department => dept).is_approved.order_by(sort).filter_by_categories(["all"]) if !dept.nil?
news_count = news.count news_count = news.count
keyword = params[:department]
elsif params["unit"] keywords = params[:department].split("-")
unit = Unit.find_by(:uid => params["unit"].split("-").last) rescue nil keywords.delete(keywords.last)
news = NewsBulletin.where(:title.ne => "" ,:unit => unit).is_approved.order_by(:created_at=>'desc').filter_by_categories(["all"]) if !unit.nil? if keywords.kind_of?(Array)
news_count = news.count keyword = keywords.join("-")
keyword = params[:unit] else
elsif params["category"] keyword = keywords
category = Category.find_by(:uid => params["category"].split("-").last) rescue nil
news = NewsBulletin.all.where(:title.ne => "").is_approved.order_by(:created_at=>'desc').filter_by_categories([category.id.to_s]) if !category.nil?
news_count = news.count
keyword = params[:category]
end end
news = NewsBulletin.where(:title.ne => "" ,:is_preview.in=>[false,nil]).is_approved.order_by(:created_at=>'desc').filter_by_categories.filter_by_tags(OrbitHelper.params['tags']) if news.nil?
elsif params[:unit]
unit = Unit.find_by(:uid => params["unit"].split("-").last) rescue nil
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:postdate=>"desc"}
news = NewsBulletin.where(:title.ne => "" ,:unit => unit).is_approved.order_by(sort).filter_by_categories(["all"]) if !unit.nil?
news_count = news.count
keywords = params[:unit].split("-")
keywords.delete(keywords.last)
if keywords.kind_of?(Array)
keyword = keywords.join("-")
else
keyword = keywords
end
elsif params["category"]
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:postdate=>"desc"}
category = Category.find_by(:uid => params["category"].split("-").last) rescue nil
news = NewsBulletin.all.where(:title.ne => "").is_approved.order_by(sort).filter_by_categories([category.id.to_s]) if !category.nil?
news_count = news.count
keywords = params[:category].split("-")
keywords.delete(keywords.last)
if keywords.kind_of?(Array)
keyword = keywords.join("-")
else
keyword = keywords
end
end
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:postdate=>"desc"}
news = NewsBulletin.where(:title.ne => "" ,:is_preview.in=>[false,nil]).is_approved.order_by(sort).filter_by_categories.filter_by_tags(OrbitHelper.params['tags']) if news.nil?
page = Page.where(:module => "news").first rescue nil page = Page.where(:module => "news").first rescue nil
ma = ModuleApp.find_by_key("news") rescue nil ma = ModuleApp.find_by_key("news") rescue nil
categories = ma.categories.enabled.collect do |cat| categories = ma.categories.enabled.collect do |cat|