Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-notes-api
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
edx-notes-api
Commits
75bb5b42
Commit
75bb5b42
authored
Dec 25, 2014
by
Tim Babych
Committed by
Oleg Marshev
Jan 05, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add elasticsearch searcher
parent
10480c3a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
0 deletions
+84
-0
notesapi/v1/models.py
+48
-0
notesserver/settings/common.py
+4
-0
notesserver/settings/dev.py
+4
-0
notesserver/settings/test.py
+27
-0
requirements/base.txt
+1
-0
No files found.
notesapi/v1/models.py
View file @
75bb5b42
import
json
import
json
from
django.db
import
models
from
django.db
import
models
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
django.conf
import
settings
from
django.db.models.signals
import
post_save
from
django.dispatch
import
receiver
from
elasticutils.contrib.django
import
Indexable
,
MappingType
class
Note
(
models
.
Model
):
class
Note
(
models
.
Model
):
...
@@ -69,3 +73,46 @@ class Note(models.Model):
...
@@ -69,3 +73,46 @@ class Note(models.Model):
'created'
:
created
,
'created'
:
created
,
'updated'
:
updated
,
'updated'
:
updated
,
}
}
@receiver
(
post_save
,
sender
=
Note
)
def
update_in_index
(
sender
,
instance
,
**
kw
):
if
settings
.
ES_DISABLED
:
return
NoteMappingType
.
bulk_index
([
instance
.
as_dict
()],
id_field
=
'id'
)
class
NoteMappingType
(
MappingType
,
Indexable
):
@classmethod
def
get_model
(
cls
):
return
Note
@classmethod
def
get_mapping
(
cls
):
"""
Returns an Elasticsearch mapping for Note MappingType
"""
charfield
=
{
'type'
:
'string'
,
'index'
:
'not_analyzed'
,
'store'
:
True
}
return
{
'properties'
:
{
'id'
:
charfield
,
'course_id'
:
charfield
,
'usage_id'
:
charfield
,
'text'
:
{
'type'
:
'string'
,
'index'
:
'snowball'
,
'store'
:
True
},
'quote'
:
{
'type'
:
'string'
,
'index'
:
'snowball'
,
'store'
:
True
},
'created'
:
charfield
,
'updated'
:
charfield
,
}
}
@classmethod
def
extract_document
(
cls
,
obj_id
,
obj
=
None
):
"""Converts this instance into an Elasticsearch document"""
if
obj
is
None
:
obj
=
cls
.
get_model
()
.
objects
.
get
(
pk
=
obj_id
)
return
obj
.
as_dict
()
note_searcher
=
NoteMappingType
.
search
()
\ No newline at end of file
notesserver/settings/common.py
View file @
75bb5b42
...
@@ -19,6 +19,10 @@ CLIENT_SECRET = 'edx-notes-secret'
...
@@ -19,6 +19,10 @@ CLIENT_SECRET = 'edx-notes-secret'
ELASTICSEARCH_URL
=
'http://127.0.0.1:9200'
ELASTICSEARCH_URL
=
'http://127.0.0.1:9200'
ELASTICSEARCH_INDEX
=
'edx-notes'
ELASTICSEARCH_INDEX
=
'edx-notes'
ES_URLS
=
[
'http://localhost:9200'
]
ES_INDEXES
=
{
'default'
:
'main_index'
}
ES_DISABLED
=
False
# Number of rows to return by default in result.
# Number of rows to return by default in result.
RESULTS_DEFAULT_SIZE
=
25
RESULTS_DEFAULT_SIZE
=
25
...
...
notesserver/settings/dev.py
View file @
75bb5b42
...
@@ -19,4 +19,8 @@ DATABASES = {
...
@@ -19,4 +19,8 @@ DATABASES = {
es
.
host
=
ELASTICSEARCH_URL
es
.
host
=
ELASTICSEARCH_URL
es
.
index
=
ELASTICSEARCH_INDEX
es
.
index
=
ELASTICSEARCH_INDEX
annotator
.
elasticsearch
.
RESULTS_MAX_SIZE
=
RESULTS_MAX_SIZE
annotator
.
elasticsearch
.
RESULTS_MAX_SIZE
=
RESULTS_MAX_SIZE
ES_URLS
=
[
'http://localhost:9200'
]
ES_INDEXES
=
{
'default'
:
'main_index'
}
ES_DISABLED
=
False
###############################################################################
###############################################################################
notesserver/settings/test.py
View file @
75bb5b42
...
@@ -21,3 +21,29 @@ es.host = ELASTICSEARCH_URL
...
@@ -21,3 +21,29 @@ es.host = ELASTICSEARCH_URL
es
.
index
=
ELASTICSEARCH_INDEX
es
.
index
=
ELASTICSEARCH_INDEX
annotator
.
elasticsearch
.
RESULTS_MAX_SIZE
=
RESULTS_MAX_SIZE
annotator
.
elasticsearch
.
RESULTS_MAX_SIZE
=
RESULTS_MAX_SIZE
###############################################################################
###############################################################################
LOGGING
=
{
'version'
:
1
,
'disable_existing_loggers'
:
False
,
'handlers'
:
{
'console'
:
{
'level'
:
'DEBUG'
,
'class'
:
'logging.StreamHandler'
,
'stream'
:
sys
.
stderr
,
'formatter'
:
'standard'
,
},
},
'formatters'
:
{
'standard'
:
{
'format'
:
'
%(asctime)
s
%(levelname)
s
%(process)
d [
%(name)
s]
%(filename)
s:
%(lineno)
d -
%(message)
s'
,
},
},
'loggers'
:
{
'django'
:
{
'handlers'
:
[
'console'
],
'level'
:
'ERROR'
,
'propagate'
:
False
,
},
},
}
\ No newline at end of file
requirements/base.txt
View file @
75bb5b42
...
@@ -2,6 +2,7 @@ Django==1.7.1
...
@@ -2,6 +2,7 @@ Django==1.7.1
requests==2.4.3
requests==2.4.3
djangorestframework==2.4.4
djangorestframework==2.4.4
django-rest-swagger==0.2.0
django-rest-swagger==0.2.0
elasticutils==0.10
elasticsearch==1.2.0
elasticsearch==1.2.0
annotator==0.12.0
annotator==0.12.0
django-cors-headers==0.13
django-cors-headers==0.13
...
...
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