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
6ddd730b
Commit
6ddd730b
authored
Feb 15, 2013
by
Your Name
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge comment and comment thread queries
parent
73c6d89e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
1 deletions
+56
-1
Rakefile
+5
-0
models/comment.rb
+9
-0
models/comment_thread.rb
+42
-1
No files found.
Rakefile
View file @
6ddd730b
...
...
@@ -227,6 +227,11 @@ namespace :db do
Tire
.
index
(
'comment_threads'
).
delete
CommentThread
.
create_elasticsearch_index
Tire
.
index
(
'comment_threads'
)
{
import
CommentThread
.
all
}
Tire
.
index
(
'comments'
).
delete
Comment
.
create_elasticsearch_index
Tire
.
index
(
'comments'
)
{
import
Comment
.
all
}
end
task
:add_anonymous_to_peers
=>
:environment
do
...
...
models/comment.rb
View file @
6ddd730b
...
...
@@ -18,6 +18,15 @@ class Comment < Content
index
({
author_id:
1
,
course_id:
1
})
include
Tire
::
Model
::
Search
include
Tire
::
Model
::
Callbacks
mapping
do
indexes
:body
,
type: :string
,
analyzer: :snowball
,
stored:
true
,
term_vector: :with_positions_offsets
end
belongs_to
:comment_thread
,
index:
true
belongs_to
:author
,
class_name:
"User"
,
index:
true
...
...
models/comment_thread.rb
View file @
6ddd730b
...
...
@@ -44,6 +44,8 @@ class CommentThread < Content
indexes
:commentable_id
,
type: :string
,
index: :not_analyzed
,
included_in_all:
false
indexes
:author_id
,
type: :string
,
as:
'author_id'
,
index: :not_analyzed
,
included_in_all:
false
indexes
:group_id
,
type: :integer
,
as:
'group_id'
,
index: :not_analyzed
,
included_in_all:
false
indexes
:id
,
:index
=>
:not_analyzed
indexes
:thread_id
,
:analyzer
=>
:keyword
,
:as
=>
"_id"
end
belongs_to
:author
,
class_name:
"User"
,
inverse_of: :comment_threads
,
index:
true
#, autosave: true
...
...
@@ -126,6 +128,45 @@ class CommentThread < Content
results
=
search
.
results
#if this is a search query, then also search the comments and harvest the matching comments
if
params
[
"text"
]
#temp
params
=
{}
params
[
"text"
]
=
"test"
#end temp
search
=
Tire
::
Search
::
Search
.
new
'comments'
search
.
query
{
|
query
|
query
.
text
:_all
,
params
[
"text"
]}
if
params
[
"text"
]
search
.
size
per_page
search
.
from
per_page
*
(
page
-
1
)
c_results
=
search
.
results
comment_ids
=
c_results
.
collect
{
|
c
|
c
.
id
}.
uniq
comments
=
Comment
.
where
(
:id
.
in
=>
comment_ids
)
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
)
if
params
[
"group_id"
]
search
.
filter
:or
,
[
{
:not
=>
{
:exists
=>
{
:field
=>
:group_id
}}},
{
:term
=>
{
:group_id
=>
params
[
"group_id"
]}}
]
end
results
+=
search
.
results
end
if
CommentService
.
config
[
:cache_enabled
]
Sinatra
::
Application
.
cache
.
set
(
memcached_key
,
results
,
CommentService
.
config
[
:cache_timeout
][
:threads_search
].
to_i
)
end
...
...
@@ -224,7 +265,7 @@ class CommentThread < Content
!!
(
tag
=~
RE_TAG
)
end
private
private
RE_HEADCHAR
=
/[a-z0-9]/
RE_ENDONLYCHAR
=
/\+/
...
...
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