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
c44af90b
Commit
c44af90b
authored
Aug 17, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
store the entire result
parent
0f44adf2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
12 deletions
+8
-12
api/search.rb
+4
-4
models/comment_thread.rb
+4
-8
No files found.
api/search.rb
View file @
c44af90b
...
@@ -32,14 +32,14 @@ get "#{APIPREFIX}/search/threads" do
...
@@ -32,14 +32,14 @@ get "#{APIPREFIX}/search/threads" do
results
=
CommentThread
.
perform_search
(
params
,
options
)
results
=
CommentThread
.
perform_search
(
params
,
options
)
if
page
>
results
[
:total_pages
]
#TODO find a better way for this
if
page
>
results
.
total_pages
#TODO find a better way for this
results
=
CommentThread
.
perform_search
(
params
,
options
.
merge
(
page:
results
[
:total_pages
]
))
results
=
CommentThread
.
perform_search
(
params
,
options
.
merge
(
page:
results
.
total_pages
))
end
end
num_pages
=
results
[
:total_pages
]
num_pages
=
results
.
total_pages
page
=
[
num_pages
,
[
1
,
page
].
max
].
min
page
=
[
num_pages
,
[
1
,
page
].
max
].
min
{
{
collection:
results
[
:result_ids
].
map
{
|
id
|
CommentThread
.
search_result_id_to_hash
(
id
,
recursive:
bool_recursive
)},
collection:
results
.
map
{
|
t
|
CommentThread
.
search_result_to_hash
(
t
,
recursive:
bool_recursive
)},
num_pages:
num_pages
,
num_pages:
num_pages
,
page:
page
,
page:
page
,
}.
to_json
}.
to_json
...
...
models/comment_thread.rb
View file @
c44af90b
...
@@ -75,14 +75,14 @@ class CommentThread < Content
...
@@ -75,14 +75,14 @@ class CommentThread < Content
c
c
end
end
def
self
.
search_result_
id_to_hash
(
id
,
params
=
{})
def
self
.
search_result_
to_hash
(
result
,
params
=
{})
comment_thread
=
self
.
find
(
result
.
id
)
comment_thread
=
self
.
find
(
result
.
id
)
highlight
=
result
.
highlight
||
{}
highlight
=
result
.
highlight
||
{}
highlighted_body
=
(
highlight
[
:body
]
||
[]).
first
||
comment_thread
.
body
highlighted_body
=
(
highlight
[
:body
]
||
[]).
first
||
comment_thread
.
body
highlighted_title
=
(
highlight
[
:title
]
||
[]).
first
||
comment_thread
.
title
highlighted_title
=
(
highlight
[
:title
]
||
[]).
first
||
comment_thread
.
title
find
(
id
)
.
to_hash
(
params
).
merge
(
highlighted_body:
highlighted_body
,
highlighted_title:
highlighted_title
)
comment_thread
.
to_hash
(
params
).
merge
(
highlighted_body:
highlighted_body
,
highlighted_title:
highlighted_title
)
end
end
def
self
.
perform_search
(
params
,
options
=
{})
def
self
.
perform_search
(
params
,
options
=
{})
...
@@ -109,14 +109,10 @@ class CommentThread < Content
...
@@ -109,14 +109,10 @@ class CommentThread < Content
search
.
size
per_page
search
.
size
per_page
search
.
from
per_page
*
(
page
-
1
)
search
.
from
per_page
*
(
page
-
1
)
results
=
{
result_ids:
search
.
results
.
map
(
&
:id
),
total_pages:
search
.
results
.
total_pages
,
}
if
CommentService
.
config
[
:cache_enabled
]
if
CommentService
.
config
[
:cache_enabled
]
Sinatra
::
Application
.
cache
.
set
(
memcached_key
,
results
,
CommentService
.
config
[
:cache_timeout
][
:threads_search
].
to_i
)
Sinatra
::
Application
.
cache
.
set
(
memcached_key
,
search
.
results
,
CommentService
.
config
[
:cache_timeout
][
:threads_search
].
to_i
)
end
end
results
search
.
results
end
end
def
activity_since
(
from_time
=
nil
)
def
activity_since
(
from_time
=
nil
)
...
...
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