tmp commit for search. start nccu0621 first
This commit is contained in:
1 parent
cb17fe0825
commit
3f95fe4f13
20 files changed
+949
-1792
No files matched your search
Vendored
+15
-5
@@ -10,12 +10,22 @@ class Panel::News::FrontEnd::NewsBulletinsController < OrbitWidgetController
|
||||
|
||||
def index
|
||||
if !params[:search_query].blank?
|
||||
@news_bulletins = NewsBulletin.solr_search do
|
||||
fulltext params[:search_query] do
|
||||
fields(:text,:title=>2.0)
|
||||
end
|
||||
end.each_hit_with_result
|
||||
search_query =params[:search_query].gsub(/"/,"").split(" ")
|
||||
|
||||
words_query = lambda do |boolean|
|
||||
search_query.each do |word|
|
||||
boolean.should { string "title:#{word}" }
|
||||
#boolean.should { string "sub_title:#{word}" }
|
||||
#boolean.should { string "text:#{word}" }
|
||||
end
|
||||
end
|
||||
|
||||
search_result=Tire.search('news_bulletins') do
|
||||
query {boolean &words_query }
|
||||
#raise to_curl
|
||||
end.results.collect{|t| t.id}
|
||||
|
||||
@news_bulletins = NewsBulletin.can_display.any_in(_id:search_result).page( params[:page_main]).per(10)
|
||||
else
|
||||
date_now = Time.now
|
||||
if !params[:category_id].blank?
|
||||
|
||||
+35
-56
@@ -5,16 +5,13 @@ class NewsBulletin
|
||||
include Mongoid::Timestamps
|
||||
include Mongoid::MultiParameterAttributes
|
||||
include Impressionist::Impressionable
|
||||
# include OrbitBasis::BaseModel
|
||||
# include OrbitSearchLib::ObjectSearchable
|
||||
# include NccuSearch
|
||||
include Tire::Model::Search
|
||||
include Tire::Model::Callbacks
|
||||
# include Redis::Objects
|
||||
include Mongoid::BaseModel
|
||||
|
||||
include Sunspot::Mongoid
|
||||
|
||||
|
||||
# scope :searchable,where(:is_checked=>true,:is_hidden=>false,:is_pending=>false)
|
||||
|
||||
scope :searchable,where(:is_checked=>true,:is_hidden=>false,:is_pending=>false)
|
||||
|
||||
is_impressionable :counter_cache => { :column_name => :view_count }
|
||||
|
||||
@@ -64,61 +61,43 @@ class NewsBulletin
|
||||
|
||||
after_save :save_news_bulletin_links
|
||||
after_save :save_news_bulletin_files
|
||||
# include OrbitBasis::ClassMethods
|
||||
|
||||
|
||||
searchable do
|
||||
text :title do
|
||||
titles = ""
|
||||
titles << (self.title.zh_tw.nil? ? '':self.title.zh_tw)
|
||||
titles << (self.title.en.nil? ? '':self.title.en)
|
||||
#(titles << self.title.en )unless self.title.nil?
|
||||
doc = Nokogiri::HTML(titles)
|
||||
doc.text
|
||||
#VALID_LOCALES
|
||||
end
|
||||
|
||||
text :text do
|
||||
texts = ""
|
||||
texts << (self.text.zh_tw.nil? ? '':self.text.zh_tw)
|
||||
texts << (self.text.en.nil? ? '':self.text.en)
|
||||
#texts << self.text.en )unless self.text.en.nil?
|
||||
doc = Nokogiri::HTML(texts)
|
||||
doc.text
|
||||
#VALID_LOCALES
|
||||
end
|
||||
# text :sub_titles do
|
||||
# self.subtitle.zh_tw
|
||||
# #VALID_LOCALES
|
||||
# end
|
||||
# text :text do
|
||||
# self.text.zh_tw
|
||||
# #VALID_LOCALES
|
||||
# end
|
||||
# text :content, :publish_month
|
||||
# text :comments do
|
||||
# comments.map(&:content)
|
||||
# end
|
||||
# time :published_at
|
||||
# string :publish_month
|
||||
end
|
||||
# Tire.index 'news_bulletin' do
|
||||
# delete
|
||||
# create :mappings =>{
|
||||
# :news_bulletin_by_title => {
|
||||
# :properties=> {
|
||||
# :title => { :type => 'string', :index => 'not_analyzed', :include_in_all => false },
|
||||
# :body => {}
|
||||
# }
|
||||
# }
|
||||
# :news_bulletin_by_body => {
|
||||
# :properties=> {
|
||||
# :body => { :type => 'string', :index => 'not_analyzed', :include_in_all => false },
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# end
|
||||
# mapping do
|
||||
# indexes :title, :analyzer => 'cjk', :boost => 10
|
||||
# indexes :sub_titles, :analyzer => 'cjk', :boost => 5
|
||||
# indexes :text, :analyzer => 'cjk'
|
||||
# end
|
||||
|
||||
# def to_indexed_json
|
||||
# titles = title.zh_tw + title.en
|
||||
# sub_titles = subtitle.zh_tw + subtitle.en
|
||||
# texts = text.zh_tw + text.en
|
||||
# {
|
||||
# :id => id,
|
||||
# :title => titles,
|
||||
# :sub_titles => sub_titles,
|
||||
# :text => texts
|
||||
# }.to_json
|
||||
# end
|
||||
def type
|
||||
"news_bulletin"
|
||||
end
|
||||
|
||||
def to_indexed_json
|
||||
titles = title.zh_tw #+ title.en
|
||||
sub_titles = subtitle.zh_tw #+ subtitle.en
|
||||
texts = text.zh_tw #+ text.en
|
||||
{
|
||||
:_id => _id,
|
||||
:title => Nokogiri::HTML(titles).text,
|
||||
:sub_title => Nokogiri::HTML(sub_titles).text,
|
||||
:text => Nokogiri::HTML(texts).text
|
||||
}.to_json
|
||||
end
|
||||
|
||||
def self.search( search = nil, category_id = nil )
|
||||
if category_id.to_s.size > 0 and search.to_s.size > 0
|
||||
|
||||
Reference in new issue
Block a user