Skip to content

Commit 03a3aa7

Browse files
prepare 0.17
1 parent 2078624 commit 03a3aa7

File tree

10 files changed

+140
-4
lines changed

10 files changed

+140
-4
lines changed

.hgignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ syntax: regexp
1414
^vagrant/\.vagrant
1515
^\.pytest_cache/
1616
node_modules/
17+
yarn-error\.log
1718

1819
^MANIFEST\.in~
1920
^tmp/

CHANGELOG.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ 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
19+
----
20+
2018-12-12
21+
22+
.. note::
23+
24+
Release supported by `whythawk <https://github.com/whythawk>`_.
25+
26+
- Added support for context suggesters (`category` and `geo`).
27+
- Added support for `size` attribute on suggesters.
28+
1829
0.16.3
1930
------
2031
2018-10-31

docs/advanced_usage_examples.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,12 +1782,18 @@ Example for ``phrase`` suggester:
17821782
SUGGESTER_PHRASE,
17831783
]
17841784
'default_suggester': SUGGESTER_COMPLETION,
1785+
'options': {
1786+
'size': 10, # Number of suggestions to retrieve.
1787+
},
17851788
},
17861789
'publisher_suggest': 'publisher.suggest',
17871790
'tag_suggest': 'tags.suggest',
17881791
'summary_suggest': 'summary',
17891792
}
17901793
1794+
Note, that by default the number of suggestions is limited to 5. If you need
1795+
more suggestions, add 'options` dictionary with `size` provided, as show above.
1796+
17911797
Sample requests/responses
17921798
^^^^^^^^^^^^^^^^^^^^^^^^^
17931799
Once you have extended your view set with ``SuggesterFilterBackend``

docs/changelog.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ 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
19+
----
20+
2018-12-12
21+
22+
.. note::
23+
24+
Release supported by `whythawk <https://github.com/whythawk>`_.
25+
26+
- Added support for context suggesters (`category` and `geo`).
27+
- Added support for `size` attribute on suggesters.
28+
1829
0.16.3
1930
------
2031
2018-10-31

docs_src/advanced_usage_examples.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,12 +1782,18 @@ Example for ``phrase`` suggester:
17821782
SUGGESTER_PHRASE,
17831783
]
17841784
'default_suggester': SUGGESTER_COMPLETION,
1785+
'options': {
1786+
'size': 10, # Number of suggestions to retrieve.
1787+
},
17851788
},
17861789
'publisher_suggest': 'publisher.suggest',
17871790
'tag_suggest': 'tags.suggest',
17881791
'summary_suggest': 'summary',
17891792
}
17901793
1794+
Note, that by default the number of suggestions is limited to 5. If you need
1795+
more suggestions, add 'options` dictionary with `size` provided, as show above.
1796+
17911797
Sample requests/responses
17921798
^^^^^^^^^^^^^^^^^^^^^^^^^
17931799
Once you have extended your view set with ``SuggesterFilterBackend``

examples/simple/search_indexes/viewsets/address/frontend.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,15 @@ class FrontAddressDocumentViewSet(DocumentViewSet):
116116
'suggesters': [
117117
SUGGESTER_COMPLETION,
118118
],
119-
119+
'options': {
120+
'size': 10,
121+
},
120122
},
121123
'street_suggest_context': {
122124
'field': 'street.suggest_context',
125+
'suggesters': [
126+
SUGGESTER_COMPLETION,
127+
],
123128
'default_suggester': SUGGESTER_COMPLETION,
124129
# We want to be able to filter the completion filter
125130
# results on the following params: tag, state and publisher.
@@ -130,8 +135,10 @@ class FrontAddressDocumentViewSet(DocumentViewSet):
130135
'geo_filters': {
131136
'title_suggest_loc': 'loc',
132137
},
138+
},
139+
'options': {
133140
'size': 10,
134-
}
141+
},
135142
},
136143
'city_suggest': {
137144
'field': 'city.name.suggest',

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.16.3'
5+
version = '0.17'
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.16.3'
6+
__version__ = '0.17'
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/filter_backends/suggester/native.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,13 @@ def get_suggester_query_params(self, request, view):
504504
'type': view.mapping,
505505
}
506506

507+
if 'options' in _sf and 'size' in _sf['options']:
508+
suggester_query_params[query_param].update(
509+
{
510+
'size': _sf['options']['size']
511+
}
512+
)
513+
507514
if (
508515
suggester_param == SUGGESTER_COMPLETION
509516
and 'completion_options' in _sf

src/django_elasticsearch_dsl_drf/tests/test_suggesters.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ class TestContextSuggesters(BaseRestFrameworkTestCase, AddressesMixin):
354354
@classmethod
355355
def setUpClass(cls):
356356
"""Set up class."""
357+
# Books
357358
cls.books = []
358359
cls.books.append(
359360
factories.BookFactory(
@@ -413,6 +414,70 @@ def setUpClass(cls):
413414
kwargs={}
414415
)
415416

417+
# Addresses
418+
cls.addresses = []
419+
cls.addresses.append(
420+
factories.AddressFactory(
421+
street='Halabyan',
422+
city__name='Yerevan',
423+
latitude=40.0742719,
424+
longitude=44.1930605,
425+
)
426+
)
427+
cls.addresses.append(
428+
factories.AddressFactory(
429+
street='Hambardzumyan',
430+
city__name='Yerevan',
431+
latitude=40.01,
432+
longitude=44.01,
433+
)
434+
)
435+
cls.addresses.append(
436+
factories.AddressFactory(
437+
street='Haghartsin',
438+
city__name='Yerevan',
439+
latitude=39.92,
440+
longitude=43.92,
441+
)
442+
)
443+
cls.addresses.append(
444+
factories.AddressFactory(
445+
street='Hamazaspyan',
446+
city__name='Tatev',
447+
latitude=39.3793612,
448+
longitude=46.2480006,
449+
)
450+
)
451+
cls.addresses.append(
452+
factories.AddressFactory(
453+
street='Harazatyan',
454+
city__name='Tatev',
455+
latitude=39.3793612,
456+
longitude=46.2480006,
457+
)
458+
)
459+
cls.addresses.append(
460+
factories.AddressFactory(
461+
street='Hardewijk',
462+
city__name='Groningen',
463+
latitude=53.2246892,
464+
longitude=6.56429,
465+
)
466+
)
467+
cls.addresses.append(
468+
factories.AddressFactory(
469+
street='Haringstraat',
470+
city__name='Groningen',
471+
latitude=53.2246892,
472+
longitude=6.56429,
473+
)
474+
)
475+
476+
cls.addresses_suggest_context_url = reverse(
477+
'addressdocument_frontend-suggest',
478+
kwargs={}
479+
)
480+
416481
call_command('search_index', '--rebuild', '-f')
417482

418483
def _test_suggesters_completion_context(self, test_data, url):
@@ -467,6 +532,28 @@ def test_suggesters_completion_context(self):
467532
self.books_suggest_context_url
468533
)
469534

535+
# Testing addresses
536+
test_data = {
537+
'street_suggest_context': {
538+
'Ha': {
539+
'expected_results': [
540+
'Halabyan',
541+
'Hambardzumyan',
542+
'Haghartsin',
543+
'Hamazaspyan',
544+
'Harazatyan',
545+
],
546+
'filters': {
547+
'title_suggest_loc': '40__44__1000km',
548+
}
549+
},
550+
},
551+
}
552+
self._test_suggesters_completion_context(
553+
test_data,
554+
self.addresses_suggest_context_url
555+
)
556+
470557

471558
if __name__ == '__main__':
472559
unittest.main()

0 commit comments

Comments
 (0)