Skip to content

Commit 5f70096

Browse files
prepare 0.17.1
1 parent 03a3aa7 commit 5f70096

File tree

9 files changed

+125
-64
lines changed

9 files changed

+125
-64
lines changed

CHANGELOG.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ 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.1
19+
------
20+
2018-12-12
21+
22+
- Skipping the new context suggester tests for Elasticsearch 2.x and a number
23+
of other 2.x related fixes in tests.
24+
- A number of 5.x fixes in tests.
25+
1826
0.17
1927
----
2028
2018-12-12
@@ -23,7 +31,9 @@ are used for versioning (schema follows below):
2331

2432
Release supported by `whythawk <https://github.com/whythawk>`_.
2533

26-
- Added support for context suggesters (`category` and `geo`).
34+
- Added support for context suggesters (`category` and `geo`). Note, that
35+
this functionality is available for Elasticsearch 5.x and 6.x (thus, not
36+
for Elasticsearch 2.x).
2737
- Added support for `size` attribute on suggesters.
2838

2939
0.16.3

docs/advanced_usage_examples.rst

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,8 +1384,10 @@ ViewSet should altered as follows:
13841384
# `suggest_context` of the `BookDocument`.
13851385
'title_suggest_tag': 'tag',
13861386
},
1387-
'size': 10,
1388-
}
1387+
},
1388+
'options': {
1389+
'size': 10, # By default, number of results is 5.
1390+
},
13891391
},
13901392
}
13911393
@@ -1428,9 +1430,12 @@ In that case, the document definition should be altered as follows:
14281430
"name": "loc",
14291431
"type": "geo",
14301432
"path": "location",
1431-
"precision": "100km",
1433+
# You could also optionally add precision value.
1434+
# However, this is not required and can be
1435+
# specified in the query during runtime.
1436+
# "precision": "100km",
14321437
},
1433-
]
1438+
],
14341439
),
14351440
}
14361441
)
@@ -1465,7 +1470,9 @@ ViewSet should altered as follows:
14651470
'geo_filters': {
14661471
'title_suggest_loc': 'loc',
14671472
},
1468-
'size': 10,
1473+
},
1474+
'options': {
1475+
'size': 10, # By default, number of results is 5.
14691476
}
14701477
},
14711478
}
@@ -1483,7 +1490,7 @@ from geo-point (-30, -100).
14831490
14841491
GET http://localhost:8000/search/addresses-frontend/suggest/?street_suggest_context=L&title_suggest_loc=-30__-100__8000km
14851492
1486-
Same query with boosting as well (boost value 2.0):
1493+
Same query with boosting (boost value 2.0):
14871494

14881495
.. code-block:: text
14891496

docs/changelog.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ 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.1
19+
------
20+
2018-12-12
21+
22+
- Skipping the new context suggester tests for Elasticsearch 2.x and a number
23+
of other 2.x related fixes in tests.
24+
- A number of 5.x fixes in tests.
25+
1826
0.17
1927
----
2028
2018-12-12
@@ -23,7 +31,9 @@ are used for versioning (schema follows below):
2331

2432
Release supported by `whythawk <https://github.com/whythawk>`_.
2533

26-
- Added support for context suggesters (`category` and `geo`).
34+
- Added support for context suggesters (`category` and `geo`). Note, that
35+
this functionality is available for Elasticsearch 5.x and 6.x (thus, not
36+
for Elasticsearch 2.x).
2737
- Added support for `size` attribute on suggesters.
2838

2939
0.16.3

docs_src/advanced_usage_examples.rst

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,8 +1384,10 @@ ViewSet should altered as follows:
13841384
# `suggest_context` of the `BookDocument`.
13851385
'title_suggest_tag': 'tag',
13861386
},
1387-
'size': 10,
1388-
}
1387+
},
1388+
'options': {
1389+
'size': 10, # By default, number of results is 5.
1390+
},
13891391
},
13901392
}
13911393
@@ -1428,9 +1430,12 @@ In that case, the document definition should be altered as follows:
14281430
"name": "loc",
14291431
"type": "geo",
14301432
"path": "location",
1431-
"precision": "100km",
1433+
# You could also optionally add precision value.
1434+
# However, this is not required and can be
1435+
# specified in the query during runtime.
1436+
# "precision": "100km",
14321437
},
1433-
]
1438+
],
14341439
),
14351440
}
14361441
)
@@ -1465,7 +1470,9 @@ ViewSet should altered as follows:
14651470
'geo_filters': {
14661471
'title_suggest_loc': 'loc',
14671472
},
1468-
'size': 10,
1473+
},
1474+
'options': {
1475+
'size': 10, # By default, number of results is 5.
14691476
}
14701477
},
14711478
}
@@ -1483,7 +1490,7 @@ from geo-point (-30, -100).
14831490
14841491
GET http://localhost:8000/search/addresses-frontend/suggest/?street_suggest_context=L&title_suggest_loc=-30__-100__8000km
14851492
1486-
Same query with boosting as well (boost value 2.0):
1493+
Same query with boosting (boost value 2.0):
14871494

14881495
.. code-block:: text
14891496

examples/simple/search_indexes/documents/address.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from django_elasticsearch_dsl import DocType, Index, fields
44
from django_elasticsearch_dsl_drf.compat import KeywordField, StringField
5+
from django_elasticsearch_dsl_drf.versions import ELASTICSEARCH_GTE_5_0
56

67
from books.models import Address
78

@@ -36,23 +37,30 @@ class AddressDocument(DocType):
3637
# ********************************************************************
3738
# *********************** Main data fields for search ****************
3839
# ********************************************************************
39-
40+
__street_fields = {
41+
'raw': KeywordField(),
42+
'suggest': fields.CompletionField(),
43+
44+
}
45+
46+
if ELASTICSEARCH_GTE_5_0:
47+
__street_fields.update(
48+
{
49+
'suggest_context': fields.CompletionField(
50+
contexts=[
51+
{
52+
"name": "loc",
53+
"type": "geo",
54+
"path": "location",
55+
"precision": "1000km",
56+
},
57+
]
58+
),
59+
}
60+
)
4061
street = StringField(
4162
analyzer=html_strip,
42-
fields={
43-
'raw': KeywordField(),
44-
'suggest': fields.CompletionField(),
45-
'suggest_context': fields.CompletionField(
46-
contexts=[
47-
{
48-
"name": "loc",
49-
"type": "geo",
50-
"path": "location",
51-
"precision": "100km",
52-
},
53-
]
54-
),
55-
}
63+
fields=__street_fields
5664
)
5765

5866
house_number = StringField(analyzer=html_strip)

examples/simple/search_indexes/documents/book.py

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django_elasticsearch_dsl import DocType, Index, fields
44
from django_elasticsearch_dsl_drf.compat import KeywordField, StringField
55
from django_elasticsearch_dsl_drf.analyzers import edge_ngram_completion
6+
from django_elasticsearch_dsl_drf.versions import ELASTICSEARCH_GTE_5_0
67

78
from books.models import Book
89

@@ -37,36 +38,43 @@ class BookDocument(DocType):
3738
# ********************************************************************
3839
# *********************** Main data fields for search ****************
3940
# ********************************************************************
41+
__title_fields = {
42+
'raw': KeywordField(),
43+
'suggest': fields.CompletionField(),
44+
'edge_ngram_completion': StringField(
45+
analyzer=edge_ngram_completion
46+
),
47+
'mlt': StringField(analyzer='english'),
48+
}
49+
50+
if ELASTICSEARCH_GTE_5_0:
51+
__title_fields.update(
52+
{
53+
'suggest_context': fields.CompletionField(
54+
contexts=[
55+
{
56+
"name": "tag",
57+
"type": "category",
58+
"path": "tags.raw",
59+
},
60+
{
61+
"name": "state",
62+
"type": "category",
63+
"path": "state.raw",
64+
},
65+
{
66+
"name": "publisher",
67+
"type": "category",
68+
"path": "publisher.raw",
69+
},
70+
]
71+
),
72+
}
73+
)
4074

4175
title = StringField(
4276
analyzer=html_strip,
43-
fields={
44-
'raw': KeywordField(),
45-
'suggest': fields.CompletionField(),
46-
'suggest_context': fields.CompletionField(
47-
contexts=[
48-
{
49-
"name": "tag",
50-
"type": "category",
51-
"path": "tags.raw",
52-
},
53-
{
54-
"name": "state",
55-
"type": "category",
56-
"path": "state.raw",
57-
},
58-
{
59-
"name": "publisher",
60-
"type": "category",
61-
"path": "publisher.raw",
62-
},
63-
]
64-
),
65-
'edge_ngram_completion': StringField(
66-
analyzer=edge_ngram_completion
67-
),
68-
'mlt': StringField(analyzer='english'),
69-
}
77+
fields=__title_fields
7078
)
7179

7280
description = StringField(

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from setuptools import find_packages, setup
44

5-
version = '0.17'
5+
version = '0.17.1'
66

77
DOCS_TRANSFORMATIONS = (
88
(

src/django_elasticsearch_dsl_drf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
__title__ = 'django-elasticsearch-dsl-drf'
6-
__version__ = '0.17'
6+
__version__ = '0.17.1'
77
__author__ = 'Artur Barseghyan <[email protected]>'
88
__copyright__ = '2017-2018 Artur Barseghyan'
99
__license__ = 'GPL 2.0/LGPL 2.1'

src/django_elasticsearch_dsl_drf/tests/test_suggesters.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import factories
1919

20+
from ..versions import ELASTICSEARCH_GTE_5_0, ELASTICSEARCH_GTE_6_0
2021
from .base import BaseRestFrameworkTestCase
2122
from .data_mixins import AddressesMixin
2223

@@ -341,10 +342,16 @@ def test_suggesters_on_empty_index(self):
341342
{}
342343
)
343344
self.assertEqual(response.status_code, status.HTTP_200_OK)
344-
self.assertFalse(bool(response.data))
345-
# self.assertFalse(bool(response.data.get('name_suggest__completion')))
345+
346+
if ELASTICSEARCH_GTE_6_0:
347+
self.assertFalse(bool(response.data))
348+
else:
349+
self.assertFalse(
350+
bool(response.data.get('name_suggest__completion'))
351+
)
346352

347353

354+
@unittest.skipIf(not ELASTICSEARCH_GTE_5_0, 'ES >=5.x only')
348355
@pytest.mark.django_db
349356
class TestContextSuggesters(BaseRestFrameworkTestCase, AddressesMixin):
350357
"""Test context suggesters."""
@@ -392,12 +399,12 @@ def setUpClass(cls):
392399
cls.books.append(
393400
factories.BookFactory(
394401
title='Ccccc Eeee',
395-
summary='He took his vorpal sword in his hand,'
402+
summary='She took his zorpal blade in his hand,'
396403
'Long time the manxome foe he sought --'
397404
'So rested he by the Tumtum tree,'
398405
'And stood awhile in thought.',
399-
publisher__name='Mario',
400-
publisher__country='US',
406+
# publisher__name='Mario',
407+
# publisher__country='US',
401408
)
402409
)
403410

@@ -544,7 +551,11 @@ def test_suggesters_completion_context(self):
544551
'Harazatyan',
545552
],
546553
'filters': {
547-
'title_suggest_loc': '40__44__1000km',
554+
'title_suggest_loc': (
555+
'40__44__1000km'
556+
if ELASTICSEARCH_GTE_6_0
557+
else '40__44'
558+
),
548559
}
549560
},
550561
},

0 commit comments

Comments
 (0)