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
87c93097
Commit
87c93097
authored
Aug 06, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed unnecessary lines
parent
4ddc0624
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
57 deletions
+6
-57
app.rb
+6
-18
models/comment_thread.rb
+0
-39
No files found.
app.rb
View file @
87c93097
...
@@ -52,11 +52,6 @@ get "#{api_prefix}/search/threads" do
...
@@ -52,11 +52,6 @@ get "#{api_prefix}/search/threads" do
page
=
(
params
[
"page"
]
||
1
).
to_i
page
=
(
params
[
"page"
]
||
1
).
to_i
per_page
=
(
params
[
"per_page"
]
||
20
).
to_i
per_page
=
(
params
[
"per_page"
]
||
20
).
to_i
tags
=
params
[
"tags"
].
split
/,/
if
params
[
"tags"
]
tags
=
params
[
"tags"
].
split
/,/
if
params
[
"tags"
]
#search = Tire::Search::Search.new 'comment_threads', page: page, per_page: per_page
#search.query {|query| query.text(:_all, params["text"])} if params["text"]
#search.filter :bool, :must => tags.map{|tag| {:term => {:tags_array => tag}}} if params["tags"]
#search.highlight({title: { number_of_fragments: 0 } } , {body: { number_of_fragments: 0 } }, options: { tag: "<highlight>" })
#search.query {|query| query.boolean {|boolean| tags.each {|tag| boolean.must { string "tags_array:#{tag}" }}}} if params["tags"]
search
=
CommentThread
.
tire
.
search
page:
page
,
per_page:
per_page
do
|
search
|
search
=
CommentThread
.
tire
.
search
page:
page
,
per_page:
per_page
do
|
search
|
if
params
[
"text"
]
if
params
[
"text"
]
...
@@ -66,19 +61,12 @@ get "#{api_prefix}/search/threads" do
...
@@ -66,19 +61,12 @@ get "#{api_prefix}/search/threads" do
search
.
highlight
({
title:
{
number_of_fragments:
0
}
}
,
{
body:
{
number_of_fragments:
0
}
},
options:
{
tag:
"<highlight>"
})
search
.
highlight
({
title:
{
number_of_fragments:
0
}
}
,
{
body:
{
number_of_fragments:
0
}
},
options:
{
tag:
"<highlight>"
})
end
end
search
.
filter
:bool
,
:must
=>
tags
.
map
{
|
tag
|
{
:term
=>
{
:tags_array
=>
tag
}}}
if
params
[
"tags"
]
search
.
filter
:bool
,
:must
=>
tags
.
map
{
|
tag
|
{
:term
=>
{
:tags_array
=>
tag
}
}
}
if
params
[
"tags"
]
=begin
if params["tags"]
search
.
filter
(
:term
,
commentable_id:
params
[
"commentable_id"
])
if
params
[
"commentable_id"
]
query.boolean do |boolean|
search
.
filter
(
:term
,
course_id:
params
[
"course_id"
])
if
params
[
"course_id"
]
for tag in tags
search
.
sort
{
|
sort
|
sort
.
by
sort_key
,
sort_order
}
if
sort_key
&&
sort_order
#TODO should have search option 'auto sort or sth'
boolean.must { string "tags_array:#{tag}" }
end
end
end
=end
#search.filter(:term, commentable_id: params["commentable_id"]) if params["commentable_id"]
#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
end
end
num_pages
=
search
.
total_pages
num_pages
=
search
.
total_pages
...
...
models/comment_thread.rb
View file @
87c93097
...
@@ -54,11 +54,6 @@ class CommentThread < Content
...
@@ -54,11 +54,6 @@ class CommentThread < Content
before_create
:set_last_activity_at
before_create
:set_last_activity_at
before_update
:set_last_activity_at
before_update
:set_last_activity_at
def
self
.
recreate_index
Tire
.
index
'comment_threads'
do
delete
;
end
CommentThread
.
create_elastic_index
end
def
self
.
new_dumb_thread
(
options
=
{})
def
self
.
new_dumb_thread
(
options
=
{})
c
=
self
.
new
c
=
self
.
new
c
.
title
=
options
[
:title
]
||
"title"
c
.
title
=
options
[
:title
]
||
"title"
...
@@ -71,40 +66,6 @@ class CommentThread < Content
...
@@ -71,40 +66,6 @@ class CommentThread < Content
c
c
end
end
def
self
.
search_text_with_highlight
(
text
)
search
=
tire
.
search
do
|
search
|
search
.
query
{
|
query
|
query
.
text
:_all
,
text
}
search
.
highlight
({
title:
{
number_of_fragments:
0
}
}
,
{
body:
{
number_of_fragments:
0
}
},
options:
{
tag:
"<strong>"
})
end
search
.
results
end
def
self
.
search_result_to_hash
(
result
,
params
=
{})
comment_thread
=
self
.
find
(
result
.
id
)
highlight
=
result
.
highlight
||
{}
highlighted_body
=
(
highlight
[
:body
]
||
[]).
first
||
comment_thread
.
body
highlighted_title
=
(
highlight
[
:title
]
||
[]).
first
||
comment_thread
.
title
find
(
result
.
id
).
to_hash
(
params
).
merge
(
highlighted_body:
highlighted_body
,
highlighted_title:
highlighted_title
)
end
def
self
.
search_tags
(
tags
)
tire
.
search
do
|
search
|
=begin
search.query do |query|
query.boolean do |boolean|
for tag in tags
boolean.must { string "tags_array:#{tag}" }
end
end
end
=end
end
.
results
end
def
root_comments
def
root_comments
Comment
.
roots
.
where
(
comment_thread_id:
self
.
id
)
Comment
.
roots
.
where
(
comment_thread_id:
self
.
id
)
end
end
...
...
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