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
51bc34db
Commit
51bc34db
authored
Aug 06, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
switched to elasticsearch
parent
b4cef7d4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
41 deletions
+40
-41
Rakefile
+2
-5
app.rb
+15
-7
models/comment_thread.rb
+16
-29
spec/api/search_spec.rb
+2
-0
spec/spec_helper.rb
+5
-0
No files found.
Rakefile
View file @
51bc34db
...
...
@@ -176,6 +176,8 @@ namespace :db do
User
.
delete_all
Notification
.
delete_all
Subscription
.
delete_all
Tire
.
index
'comment_threads'
do
delete
end
CommentThread
.
create_elasticsearch_index
beginning_time
=
Time
.
now
...
...
@@ -194,11 +196,6 @@ namespace :db do
generate_comments_for
(
"lab_1"
)
generate_comments_for
(
"lab_2"
)
puts
"reindexing solr..."
CommentThread
.
remove_all_from_index!
Sunspot
.
index!
(
CommentThread
.
all
.
to_a
)
end_time
=
Time
.
now
puts
"Number of comments generated:
#{
Comment
.
count
}
"
...
...
app.rb
View file @
51bc34db
...
...
@@ -51,17 +51,25 @@ get "#{api_prefix}/search/threads" do
else
page
=
(
params
[
"page"
]
||
1
).
to_i
per_page
=
(
params
[
"per_page"
]
||
20
).
to_i
binding
.
pry
tags
=
params
[
"tags"
].
split
/,/
if
params
[
"tags"
]
search
=
CommentThread
.
tire
.
search
page:
page
,
per_page:
per_page
,
load:
true
do
|
search
|
search
.
query
do
|
query
|
query
.
text
(
:_all
,
params
[
"text"
])
if
params
[
"text"
]
query
.
term
(
:commentable_id
,
params
[
"commentable_id"
])
if
params
[
"commentable_id"
]
query
.
term
(
:course_id
,
params
[
"course_id"
])
if
params
[
"course_id"
]
query
.
terms
(
:tags
,
params
[
"tags"
].
split
(
/,/
),
minimum_match:
params
[
"tags"
].
split
(
/,/
).
length
)
if
params
[
"tags"
]
if
params
[
"text"
]
or
params
[
"tags"
]
search
.
query
do
|
query
|
query
.
text
(
:_all
,
params
[
"text"
])
if
params
[
"text"
]
if
params
[
"tags"
]
query
.
boolean
do
|
boolean
|
for
tag
in
tags
boolean
.
must
{
string
"tags_array:
#{
tag
}
"
}
end
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
num_pages
=
search
.
total_pages
{
collection:
search
.
results
.
map
{
|
t
|
t
.
to_hash
(
recursive:
bool_recursive
)},
...
...
models/comment_thread.rb
View file @
51bc34db
...
...
@@ -20,36 +20,11 @@ class CommentThread < Content
include
Tire
::
Model
::
Search
include
Tire
::
Model
::
Callbacks
#def to_indexed_json
# self.to_json
#end
settings
:analyzer
=>
{
:tags_analyzer
=>
{
'type'
=>
'stop'
,
'stopwords'
=>
[
','
],
#'tokenizer' => "keyword",
#'type' => "custom",
#'filter' => ['unique'],
}
}
=begin
, :properties => {
:tags_array => {
:type => "mutli_field",
:fields => {
:tags => { :type => :array, index: :analyzed},
:untouched_tags => { :type => :array, index: :not_analyzed},
}
}
}
=end
mapping
do
indexes
:title
,
type: :string
,
analyzer:
'i_do_not_exist'
#:whitespace#:snowball#, boost: 5.0
indexes
:body
,
type: :string
,
analyzer: :whitespace
#:snowball
indexes
:tags_in_text
,
type: :array
,
as:
'tags_array'
,
index: :analyzed
#proc {puts tags_array; tags_array}#, analyzer: :whitespace
indexes
:tags
,
type: :string
,
as:
'tags_array'
,
index: :not_analyzed
#:analyzer: "lowercase_keyword"#, included_in_all: false
indexes
:title
,
type: :string
,
analyzer: :snowball
,
boost:
5.0
indexes
:body
,
type: :string
,
analyzer: :snowball
indexes
:tags_in_text
,
type: :string
,
as:
'tags_array'
,
index: :analyzed
indexes
:tags_array
,
type: :string
,
as:
'tags_array'
,
index: :not_analyzed
,
included_in_all:
false
indexes
:created_at
,
type: :date
,
included_in_all:
false
indexes
:updated_at
,
type: :date
,
included_in_all:
false
indexes
:last_activity_at
,
type: :date
,
included_in_all:
false
...
...
@@ -99,6 +74,18 @@ class CommentThread < Content
c
end
def
self
.
search_tags
(
tags
)
tire
.
search
do
|
search
|
search
.
query
do
|
query
|
query
.
boolean
do
|
boolean
|
for
tag
in
tags
boolean
.
must
{
string
"tags_array:
#{
tag
}
"
}
end
end
end
end
.
results
end
def
root_comments
Comment
.
roots
.
where
(
comment_thread_id:
self
.
id
)
end
...
...
spec/api/search_spec.rb
View file @
51bc34db
...
...
@@ -17,6 +17,8 @@ describe "app" do
thread2
.
tags
=
[
ai
,
ml
,
random2
].
join
","
thread2
.
save
sleep
1
get
"/api/v1/search/threads"
,
tags:
[
ai
,
ml
].
join
(
","
)
last_response
.
should
be_ok
threads
=
parse
(
last_response
.
body
)[
'collection'
]
...
...
spec/spec_helper.rb
View file @
51bc34db
...
...
@@ -34,6 +34,8 @@ def init_without_subscriptions
User
.
delete_all
Notification
.
delete_all
Subscription
.
delete_all
Tire
.
index
'comment_threads'
do
delete
end
CommentThread
.
create_elasticsearch_index
commentable
=
Commentable
.
new
(
"question_1"
)
...
...
@@ -105,6 +107,9 @@ def init_with_subscriptions
Notification
.
delete_all
Subscription
.
delete_all
Tire
.
index
'comment_threads'
do
delete
end
CommentThread
.
create_elasticsearch_index
user1
=
create_test_user
(
1
)
user2
=
create_test_user
(
2
)
...
...
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