Skip to content

Commit c8cc7fb

Browse files
prepare 0.17.4
1 parent a2be584 commit c8cc7fb

File tree

11 files changed

+155
-3
lines changed

11 files changed

+155
-3
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ are used for versioning (schema follows below):
1717

1818
0.17.4
1919
------
20-
2019-03-12
20+
2019-03-13
2121

2222
- Source backend.
2323

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Main features and highlights
8888
- :doc:`Simple search query search filter backend <search_backends>`.
8989
- :doc:`More-like-this support (detail action) <more_like_this>`.
9090
- :doc:`Global aggregations support <global_aggregations>`.
91+
- :doc:`Source filter backend <source_backend>`.
9192

9293
Installation
9394
============

docs/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ are used for versioning (schema follows below):
1515
0.3.4 to 0.4).
1616
- All backwards incompatible changes are mentioned in this document.
1717

18+
0.17.4
19+
------
20+
2019-03-13
21+
22+
- Source backend.
23+
1824
0.17.3
1925
------
2026
2019-02-08

docs/documentation.rst.distrib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Contents:
1919
more_like_this
2020
global_aggregations
2121
configuration_tweaks
22+
source_backend
2223
demo
2324
frontend_demo
2425
changelog

docs/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Main features and highlights
8888
- :doc:`Simple search query search filter backend <search_backends>`.
8989
- :doc:`More-like-this support (detail action) <more_like_this>`.
9090
- :doc:`Global aggregations support <global_aggregations>`.
91+
- :doc:`Source filter backend <source_backend>`.
9192

9293
Installation
9394
============
@@ -243,6 +244,7 @@ Contents:
243244
more_like_this
244245
global_aggregations
245246
configuration_tweaks
247+
source_backend
246248
demo
247249
frontend_demo
248250
changelog

docs/source_backend.rst

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
========================
2+
Source filtering backend
3+
========================
4+
Allows to control how the `_source` field is returned with every hit.
5+
6+
By default operations return the contents of the _source field unless you have
7+
used the `stored_fields` parameter or if the `_source` field is disabled.
8+
9+
You can turn off `_source` retrieval by using the `source` parameter:
10+
11+
.. code-block:: python
12+
13+
from django_elasticsearch_dsl_drf.filter_backends import (
14+
SourceBackend
15+
)
16+
from django_elasticsearch_dsl_drf.viewsets import (
17+
BaseDocumentViewSet,
18+
)
19+
20+
# Local article document definition
21+
from .documents import ArticleDocument
22+
23+
# Local article document serializer
24+
from .serializers import ArticleDocumentSerializer
25+
26+
class ArticleDocumentView(BaseDocumentViewSet):
27+
28+
document = ArticleDocument
29+
serializer_class = ArticleDocumentSerializer
30+
filter_backends = [SourceBackend,]
31+
source = ["title"]
32+
33+
34+
To disable `_source` retrieval set to False:
35+
36+
.. code-block:: python
37+
38+
# ...
39+
source = False
40+
# ...
41+
42+
43+
The `source` also accepts one or more wildcard patterns to control what parts
44+
of the `_source` should be returned:
45+
46+
.. code-block:: python
47+
48+
# ...
49+
source = ["title", "author.*"]
50+
# ...
51+
52+
Finally, for complete control, you can specify both `includes` and `excludes`
53+
patterns:
54+
55+
.. code-block:: python
56+
57+
# ...
58+
source = {
59+
"includes": ["title", "author.*"],
60+
"excludes": [ "*.description" ]
61+
}
62+
# ...
63+
64+
.. note::
65+
66+
Source can make queries lighter. However, it can break current
67+
functionality. Use it with caution.

docs_src/source_backend.rst

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
========================
2+
Source filtering backend
3+
========================
4+
Allows to control how the `_source` field is returned with every hit.
5+
6+
By default operations return the contents of the _source field unless you have
7+
used the `stored_fields` parameter or if the `_source` field is disabled.
8+
9+
You can turn off `_source` retrieval by using the `source` parameter:
10+
11+
.. code-block:: python
12+
13+
from django_elasticsearch_dsl_drf.filter_backends import (
14+
SourceBackend
15+
)
16+
from django_elasticsearch_dsl_drf.viewsets import (
17+
BaseDocumentViewSet,
18+
)
19+
20+
# Local article document definition
21+
from .documents import ArticleDocument
22+
23+
# Local article document serializer
24+
from .serializers import ArticleDocumentSerializer
25+
26+
class ArticleDocumentView(BaseDocumentViewSet):
27+
28+
document = ArticleDocument
29+
serializer_class = ArticleDocumentSerializer
30+
filter_backends = [SourceBackend,]
31+
source = ["title"]
32+
33+
34+
To disable `_source` retrieval set to False:
35+
36+
.. code-block:: python
37+
38+
# ...
39+
source = False
40+
# ...
41+
42+
43+
The `source` also accepts one or more wildcard patterns to control what parts
44+
of the `_source` should be returned:
45+
46+
.. code-block:: python
47+
48+
# ...
49+
source = ["title", "author.*"]
50+
# ...
51+
52+
Finally, for complete control, you can specify both `includes` and `excludes`
53+
patterns:
54+
55+
.. code-block:: python
56+
57+
# ...
58+
source = {
59+
"includes": ["title", "author.*"],
60+
"excludes": [ "*.description" ]
61+
}
62+
# ...
63+
64+
.. note::
65+
66+
Source can make queries lighter. However, it can break current
67+
functionality. Use it with caution.

examples/simple/search_indexes/documents/book.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class Meta(object):
168168

169169
def prepare_summary(self, instance):
170170
"""Prepare summary."""
171-
return instance.summary[:32766]
171+
return instance.summary[:32766] if instance.summary else None
172172

173173
def prepare_authors(self, instance):
174174
"""Prepare authors."""

scripts/prepare_docs.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ cat docs_src/advanced_usage_examples.rst > docs/advanced_usage_examples.rst
99
cat docs_src/nested_fields_usage_examples.rst > docs/nested_fields_usage_examples.rst
1010
cat docs_src/filtering_usage_examples.rst > docs/filtering_usage_examples.rst
1111
cat docs_src/more_like_this.rst > docs/more_like_this.rst
12+
cat docs_src/source_backend.rst > docs/source_backend.rst
1213
cat docs_src/configuration_tweaks.rst > docs/configuration_tweaks.rst
1314
cat docs_src/global_aggregations.rst > docs/global_aggregations.rst
1415
cat examples/frontend/README.rst > docs/frontend_demo.rst

setup.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@
139139
'global_aggregations.html'
140140
'>`_'.format(version)
141141
),
142+
(
143+
':doc:`Source filter backend <source_backend>`',
144+
'`Source filter backend <'
145+
'http://django-elasticsearch-dsl-drf.readthedocs.io/en/{}/'
146+
'source_backend.html'
147+
'>`_'.format(version)
148+
),
142149
)
143150

144151
try:

0 commit comments

Comments
 (0)