Commit d0656e8e by Ibrahim Awwal

Enable searching for multiple commentable_ids. Necessary for paging to work properly.

parent 635303f0
......@@ -17,12 +17,13 @@ get "#{APIPREFIX}/search/threads" do
sort_keyword_valid = (!params["sort_key"] && !params["sort_order"] || sort_key && sort_order)
if (!params["text"] && !params["tags"]) || !sort_keyword_valid
if (!params["text"] && !params["tags"] && !params["commentable_ids"]) || !sort_keyword_valid
{}.to_json
else
page = (params["page"] || DEFAULT_PAGE).to_i
per_page = (params["per_page"] || DEFAULT_PER_PAGE).to_i
# for multi commentable searching
params["commentable_ids"] = params["commentable_ids"].split(',') if params["commentable_ids"]
options = {
sort_key: sort_key,
sort_order: sort_order,
......
......@@ -104,6 +104,7 @@ class CommentThread < Content
search.highlight({title: { number_of_fragments: 0 } } , {body: { number_of_fragments: 0 } }, options: { tag: "<highlight>" })
search.filter(:bool, :must => params["tags"].split(/,/).map{ |tag| { :term => { :tags_array => tag } } }) if params["tags"]
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.sort {|sort| sort.by sort_key, sort_order} if sort_key && sort_order #TODO should have search option 'auto sort or sth'
......
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