-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:barseghyanartur/django-elasticsea…
…rch-dsl-drf
- Loading branch information
Showing
11 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ | |
from .books_order import * | ||
from .books_orderline import * | ||
from .books_publisher import * | ||
from .books_tag import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from django.conf import settings | ||
from django_elasticsearch_dsl import Document, Index, fields | ||
|
||
from books.models import Tag | ||
from .analyzers import html_strip | ||
|
||
|
||
__all__ = ('TagDocument',) | ||
|
||
INDEX = Index(settings.ELASTICSEARCH_INDEX_NAMES[__name__]) | ||
|
||
INDEX.settings( | ||
number_of_shards=1, | ||
number_of_replicas=1, | ||
blocks={'read_only_allow_delete': None} | ||
) | ||
|
||
|
||
@INDEX.doc_type | ||
class TagDocument(Document): | ||
"""Elasticsearch document for a Tag.""" | ||
|
||
# Set unique title as the document id. | ||
id = fields.KeywordField(attr='title') | ||
title = fields.KeywordField() | ||
|
||
class Django(object): | ||
"""Django Elasticsearch DSL ORM Meta.""" | ||
|
||
model = Tag | ||
|
||
class Meta(object): | ||
"""Meta options.""" | ||
|
||
parellel_indexing = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django_elasticsearch_dsl_drf.serializers import DocumentSerializer | ||
|
||
from ..documents import TagDocument | ||
|
||
|
||
__all__ = ('TagDocumentSerializer',) | ||
|
||
|
||
class TagDocumentSerializer(DocumentSerializer): | ||
"""Serializer for a Tag document.""" | ||
|
||
class Meta(object): | ||
"""Meta options.""" | ||
|
||
document = TagDocument | ||
fields = ( | ||
'id', | ||
'title', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django_elasticsearch_dsl_drf.pagination import LimitOffsetPagination | ||
from django_elasticsearch_dsl_drf.viewsets import DocumentViewSet | ||
|
||
from ..documents import TagDocument | ||
from ..serializers import TagDocumentSerializer | ||
|
||
__all__ = ( | ||
'TagDocumentViewSet', | ||
) | ||
|
||
|
||
class TagDocumentViewSet(DocumentViewSet): | ||
"""Document viewset for tags.""" | ||
|
||
document = TagDocument | ||
serializer_class = TagDocumentSerializer | ||
lookup_field = 'title' | ||
filter_backends = [] | ||
pagination_class = LimitOffsetPagination |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters