Commit 07901bf8 by Your Name

search working, using course_id index to cut down on corpus, need to test pagination

parent 9b3085e0
...@@ -93,6 +93,7 @@ class CommentThread < Content ...@@ -93,6 +93,7 @@ class CommentThread < Content
end end
def self.perform_search(params, options={}) def self.perform_search(params, options={})
page = [1, options[:page] || 1].max page = [1, options[:page] || 1].max
per_page = options[:per_page] || 20 per_page = options[:per_page] || 20
sort_key = options[:sort_key] sort_key = options[:sort_key]
...@@ -130,68 +131,37 @@ class CommentThread < Content ...@@ -130,68 +131,37 @@ class CommentThread < Content
search.filter :or, [ search.filter :or, [
{:not => {:exists => {:field => :group_id}}}, {:not => {:exists => {:field => :group_id}}},
{:term => {:group_id => params["group_id"]}} {:term => {:group_id => params["group_id"]}}
<<<<<<< Updated upstream
=======
>>>>>>> Stashed changes
] ]
end end
search.sort {|sort| sort.by sort_key, sort_order} if sort_key && sort_order #TODO should have search option 'auto sort or sth' search.sort {|sort| sort.by sort_key, sort_order} if sort_key && sort_order #TODO should have search option 'auto sort or sth'
<<<<<<< Updated upstream
search.size per_page
search.from per_page * (page - 1)
=======
#again, b/c there is no relationship in ordinality, we cannot paginate if it's a text query #again, b/c there is no relationship in ordinality, we cannot paginate if it's a text query
if not params["text"] if not params["text"]
search.size per_page search.size per_page
search.from per_page * (page - 1) search.from per_page * (page - 1)
end end
>>>>>>> Stashed changes
results = search.results results = search.results
#if this is a search query, then also search the comments and harvest the matching comments #if this is a search query, then also search the comments and harvest the matching comments
if params["text"] if params["text"]
<<<<<<< Updated upstream
#temp
params = {}
params["text"] = "test"
#end temp
search = Tire::Search::Search.new 'comments' search = Tire::Search::Search.new 'comments'
search.query {|query| query.text :_all, params["text"]} if params["text"] search.query {|query| query.text :_all, params["text"]} if params["text"]
search.size per_page
search.from per_page * (page - 1)
=======
search = Tire::Search::Search.new 'comments'
search.query {|query| query.text :_all, params["text"]} if params["text"]
search.filter(:term, commentable_id: params["commentable_id"]) if params["commentable_id"]
search.filter(:terms, commentable_id: params["commentable_ids"]) if params["commentable_ids"]
search.filter(:term, course_id: params["course_id"]) if params["course_id"] search.filter(:term, course_id: params["course_id"]) if params["course_id"]
#unforutnately, we cannot paginate here, b/c we don't know how the ordinality is totally #unforutnately, we cannot paginate here, b/c we don't know how the ordinality is totally
#unrelated to that of threads #unrelated to that of threads
>>>>>>> Stashed changes
c_results = search.results c_results = search.results
comment_ids = c_results.collect{|c| c.id}.uniq comment_ids = c_results.collect{|c| c.id}.uniq
comments = Comment.where(:id.in => comment_ids) comments = Comment.where(:id.in => comment_ids)
<<<<<<< Updated upstream
thread_ids = comments.collect{|c| c.comment_thread_id} thread_ids = comments.collect{|c| c.comment_thread_id}
#now run one more search to harvest the threads and filter by group
search = Tire::Search::Search.new 'comment_threads'
search.filter(:term, :thread_id => thread_ids)
=======
thread_ids = comments.collect{|c| c.comment_thread_id}.uniq
original_thread_ids = results.collect{|r| r.id} original_thread_ids = results.collect{|r| r.id}
#now add the original search thread ids #now add the original search thread ids
...@@ -204,9 +174,9 @@ class CommentThread < Content ...@@ -204,9 +174,9 @@ class CommentThread < Content
search.filter(:terms, :thread_id => thread_ids) search.filter(:terms, :thread_id => thread_ids)
search.filter(:terms, commentable_id: params["commentable_ids"]) if params["commentable_ids"] search.filter(:terms, commentable_id: params["commentable_ids"]) if params["commentable_ids"]
search.filter(:term, course_id: params["course_id"]) if params["course_id"] search.filter(:term, course_id: params["course_id"]) if params["course_id"]
search.size per_page search.size per_page
search.from per_page * (page - 1) search.from per_page * (page - 1)
>>>>>>> Stashed changes
if params["group_id"] if params["group_id"]
...@@ -217,13 +187,8 @@ class CommentThread < Content ...@@ -217,13 +187,8 @@ class CommentThread < Content
] ]
end end
<<<<<<< Updated upstream
results += search.results
=======
search.sort {|sort| sort.by sort_key, sort_order} if sort_key && sort_order search.sort {|sort| sort.by sort_key, sort_order} if sort_key && sort_order
results = search.results results = search.results
>>>>>>> Stashed changes
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