Commit 87c93097 by Rocky Duan

removed unnecessary lines

parent 4ddc0624
...@@ -52,11 +52,6 @@ get "#{api_prefix}/search/threads" do ...@@ -52,11 +52,6 @@ get "#{api_prefix}/search/threads" do
page = (params["page"] || 1).to_i page = (params["page"] || 1).to_i
per_page = (params["per_page"] || 20).to_i per_page = (params["per_page"] || 20).to_i
tags = params["tags"].split /,/ if params["tags"] tags = params["tags"].split /,/ if params["tags"]
#search = Tire::Search::Search.new 'comment_threads', page: page, per_page: per_page
#search.query {|query| query.text(:_all, params["text"])} if params["text"]
#search.filter :bool, :must => tags.map{|tag| {:term => {:tags_array => tag}}} if params["tags"]
#search.highlight({title: { number_of_fragments: 0 } } , {body: { number_of_fragments: 0 } }, options: { tag: "<highlight>" })
#search.query {|query| query.boolean {|boolean| tags.each {|tag| boolean.must { string "tags_array:#{tag}" }}}} if params["tags"]
search = CommentThread.tire.search page: page, per_page: per_page do |search| search = CommentThread.tire.search page: page, per_page: per_page do |search|
if params["text"] if params["text"]
...@@ -66,19 +61,12 @@ get "#{api_prefix}/search/threads" do ...@@ -66,19 +61,12 @@ get "#{api_prefix}/search/threads" do
search.highlight({title: { number_of_fragments: 0 } } , {body: { number_of_fragments: 0 } }, options: { tag: "<highlight>" }) search.highlight({title: { number_of_fragments: 0 } } , {body: { number_of_fragments: 0 } }, options: { tag: "<highlight>" })
end end
search.filter :bool, :must => tags.map{|tag| {:term => {:tags_array => tag}}} if params["tags"] search.filter :bool, :must => tags.map{ |tag| { :term => { :tags_array => tag } } } if params["tags"]
=begin
if params["tags"] search.filter(:term, commentable_id: params["commentable_id"]) if params["commentable_id"]
query.boolean do |boolean| search.filter(:term, course_id: params["course_id"]) if params["course_id"]
for tag in tags search.sort {|sort| sort.by sort_key, sort_order} if sort_key && sort_order #TODO should have search option 'auto sort or sth'
boolean.must { string "tags_array:#{tag}" }
end
end
end
=end
#search.filter(:term, commentable_id: params["commentable_id"]) if params["commentable_id"]
#search.filter(:term, course_id: params["course_id"]) if params["course_id"]
#search.sort {|sort| sort.by sort_key, sort_order} if sort_key && sort_order
end end
num_pages = search.total_pages num_pages = search.total_pages
......
...@@ -54,11 +54,6 @@ class CommentThread < Content ...@@ -54,11 +54,6 @@ class CommentThread < Content
before_create :set_last_activity_at before_create :set_last_activity_at
before_update :set_last_activity_at before_update :set_last_activity_at
def self.recreate_index
Tire.index 'comment_threads' do delete; end
CommentThread.create_elastic_index
end
def self.new_dumb_thread(options={}) def self.new_dumb_thread(options={})
c = self.new c = self.new
c.title = options[:title] || "title" c.title = options[:title] || "title"
...@@ -71,40 +66,6 @@ class CommentThread < Content ...@@ -71,40 +66,6 @@ class CommentThread < Content
c c
end end
def self.search_text_with_highlight(text)
search = tire.search do |search|
search.query { |query| query.text :_all, text }
search.highlight({title: { number_of_fragments: 0 } } , {body: { number_of_fragments: 0 } }, options: { tag: "<strong>" })
end
search.results
end
def self.search_result_to_hash(result, params={})
comment_thread = self.find(result.id)
highlight = result.highlight || {}
highlighted_body = (highlight[:body] || []).first || comment_thread.body
highlighted_title = (highlight[:title] || []).first || comment_thread.title
find(result.id).to_hash(params).merge(highlighted_body: highlighted_body, highlighted_title: highlighted_title)
end
def self.search_tags(tags)
tire.search do |search|
=begin
search.query do |query|
query.boolean do |boolean|
for tag in tags
boolean.must { string "tags_array:#{tag}" }
end
end
end
=end
end.results
end
def root_comments def root_comments
Comment.roots.where(comment_thread_id: self.id) Comment.roots.where(comment_thread_id: self.id)
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment