Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cs_comments_service
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
cs_comments_service
Commits
d0656e8e
Commit
d0656e8e
authored
Sep 14, 2012
by
Ibrahim Awwal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable searching for multiple commentable_ids. Necessary for paging to work properly.
parent
635303f0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
7 deletions
+9
-7
api/search.rb
+8
-7
models/comment_thread.rb
+1
-0
No files found.
api/search.rb
View file @
d0656e8e
get
"
#{
APIPREFIX
}
/search/threads"
do
get
"
#{
APIPREFIX
}
/search/threads"
do
sort_key_mapper
=
{
"date"
=>
:created_at
,
...
...
@@ -11,18 +11,19 @@ get "#{APIPREFIX}/search/threads" do
"desc"
=>
:desc
,
"asc"
=>
:asc
,
}
sort_key
=
sort_key_mapper
[
params
[
"sort_key"
]]
sort_order
=
sort_order_mapper
[
params
[
"sort_order"
]]
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
,
...
...
@@ -46,7 +47,7 @@ get "#{APIPREFIX}/search/threads" do
end
end
get
"
#{
APIPREFIX
}
/search/threads/more_like_this"
do
get
"
#{
APIPREFIX
}
/search/threads/more_like_this"
do
CommentThread
.
tire
.
search
page:
1
,
per_page:
5
,
load:
true
do
|
search
|
search
.
query
do
|
query
|
query
.
more_like_this
params
[
"text"
],
fields:
[
"title"
,
"body"
],
min_doc_freq:
1
,
min_term_freq:
1
...
...
@@ -58,7 +59,7 @@ get "#{APIPREFIX}/search/threads/recent_active" do
return
[].
to_json
if
not
params
[
"course_id"
]
follower_id
=
params
[
"follower_id"
]
follower_id
=
params
[
"follower_id"
]
from_time
=
{
"today"
=>
Date
.
today
.
to_time
,
"this_week"
=>
Date
.
today
.
to_time
-
1
.
weeks
,
...
...
@@ -69,7 +70,7 @@ get "#{APIPREFIX}/search/threads/recent_active" do
query_params
[
"course_id"
]
=
params
[
"course_id"
]
if
params
[
"course_id"
]
query_params
[
"commentable_id"
]
=
params
[
"commentable_id"
]
if
params
[
"commentable_id"
]
comment_threads
=
if
follower_id
comment_threads
=
if
follower_id
User
.
find
(
follower_id
).
subscribed_threads
else
CommentThread
.
all
...
...
models/comment_thread.rb
View file @
d0656e8e
...
...
@@ -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'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment