fix for duplicate result

This commit is contained in:
Harry Bomrah 2015-08-11 18:43:51 +08:00
parent 6e9b1613bf
commit caf727cb59
1 changed files with 4 additions and 4 deletions

View File

@ -6,13 +6,13 @@ class NewsController < ApplicationController
if params[:keywords] if params[:keywords]
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"} !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
news = NewsBulletin.where(:title.ne => "").any_of(:title => /#{params[:keywords].to_s}/i).can_display_postdate.is_approved.order_by(sort).filter_by_categories(["all"]).per(15) if !params[:keywords].nil? news = NewsBulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).any_of(:title => /#{params[:keywords].to_s}/i).can_display_postdate.is_approved.order_by(sort).filter_by_categories(["all"]).per(15) if !params[:keywords].nil?
news_count = ",共搜尋到" + news.count.to_s + "筆資料" news_count = ",共搜尋到" + news.count.to_s + "筆資料"
keyword = "搜尋標題有關 ' " + params[:keywords] + " '" keyword = "搜尋標題有關 ' " + params[:keywords] + " '"
elsif params[:department] elsif params[:department]
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"} !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",: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).can_display_postdate.is_approved.order_by(sort).filter_by_categories(["all"]) if !dept.nil? news = NewsBulletin.where(:title.ne => "" ,:department => dept,:is_preview.in=>[false,nil]).can_display_postdate.is_approved.order_by(sort).filter_by_categories(["all"]) if !dept.nil?
news_count = ",共搜尋到" + news.count.to_s + "筆資料" news_count = ",共搜尋到" + news.count.to_s + "筆資料"
keywords = params[:department].split("-") keywords = params[:department].split("-")
@ -26,7 +26,7 @@ class NewsController < ApplicationController
elsif params[:unit] elsif params[:unit]
unit = Unit.find_by(:uid => params["unit"].split("-").last) rescue nil unit = Unit.find_by(:uid => params["unit"].split("-").last) rescue nil
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"} !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
news = NewsBulletin.where(:title.ne => "" ,:unit => unit).can_display_postdate.is_approved.order_by(sort).filter_by_categories(["all"]) if !unit.nil? news = NewsBulletin.where(:title.ne => "" ,:unit => unit,:is_preview.in=>[false,nil]).can_display_postdate.is_approved.order_by(sort).filter_by_categories(["all"]) if !unit.nil?
news_count = ",共搜尋到" + news.count.to_s + "筆資料" news_count = ",共搜尋到" + news.count.to_s + "筆資料"
keywords = params[:unit].split("-") keywords = params[:unit].split("-")
@ -39,7 +39,7 @@ class NewsController < ApplicationController
elsif params["category"] elsif params["category"]
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"} !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
category = Category.find_by(:uid => params["category"].split("-").last) rescue nil category = Category.find_by(:uid => params["category"].split("-").last) rescue nil
news = NewsBulletin.all.where(:title.ne => "").can_display_postdate.is_approved.order_by(sort).filter_by_categories([category.id.to_s]) if !category.nil? news = NewsBulletin.all.where(:title.ne => "",:is_preview.in=>[false,nil]).can_display_postdate.is_approved.order_by(sort).filter_by_categories([category.id.to_s]) if !category.nil?
news_count = ",共搜尋到" + news.count.to_s + "筆資料" news_count = ",共搜尋到" + news.count.to_s + "筆資料"
keywords = params[:category].split("-") keywords = params[:category].split("-")