From 03a3aa716db31868ca3a71340513a993741a4177 Mon Sep 17 00:00:00 2001 From: Artur Barseghyan Date: Wed, 12 Dec 2018 00:25:53 +0100 Subject: [PATCH] prepare 0.17 --- .hgignore | 1 + CHANGELOG.rst | 11 +++ docs/advanced_usage_examples.rst | 6 ++ docs/changelog.rst | 11 +++ docs_src/advanced_usage_examples.rst | 6 ++ .../viewsets/address/frontend.py | 11 ++- setup.py | 2 +- src/django_elasticsearch_dsl_drf/__init__.py | 2 +- .../filter_backends/suggester/native.py | 7 ++ .../tests/test_suggesters.py | 87 +++++++++++++++++++ 10 files changed, 140 insertions(+), 4 deletions(-) diff --git a/.hgignore b/.hgignore index 1c95ff20..6fc1ed77 100755 --- a/.hgignore +++ b/.hgignore @@ -14,6 +14,7 @@ syntax: regexp ^vagrant/\.vagrant ^\.pytest_cache/ node_modules/ +yarn-error\.log ^MANIFEST\.in~ ^tmp/ diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5ee8ee54..1cb43451 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,6 +15,17 @@ are used for versioning (schema follows below): 0.3.4 to 0.4). - All backwards incompatible changes are mentioned in this document. +0.17 +---- +2018-12-12 + +.. note:: + + Release supported by `whythawk `_. + +- Added support for context suggesters (`category` and `geo`). +- Added support for `size` attribute on suggesters. + 0.16.3 ------ 2018-10-31 diff --git a/docs/advanced_usage_examples.rst b/docs/advanced_usage_examples.rst index 49008ac0..a02eb36e 100644 --- a/docs/advanced_usage_examples.rst +++ b/docs/advanced_usage_examples.rst @@ -1782,12 +1782,18 @@ Example for ``phrase`` suggester: SUGGESTER_PHRASE, ] 'default_suggester': SUGGESTER_COMPLETION, + 'options': { + 'size': 10, # Number of suggestions to retrieve. + }, }, 'publisher_suggest': 'publisher.suggest', 'tag_suggest': 'tags.suggest', 'summary_suggest': 'summary', } +Note, that by default the number of suggestions is limited to 5. If you need +more suggestions, add 'options` dictionary with `size` provided, as show above. + Sample requests/responses ^^^^^^^^^^^^^^^^^^^^^^^^^ Once you have extended your view set with ``SuggesterFilterBackend`` diff --git a/docs/changelog.rst b/docs/changelog.rst index 5ee8ee54..1cb43451 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -15,6 +15,17 @@ are used for versioning (schema follows below): 0.3.4 to 0.4). - All backwards incompatible changes are mentioned in this document. +0.17 +---- +2018-12-12 + +.. note:: + + Release supported by `whythawk `_. + +- Added support for context suggesters (`category` and `geo`). +- Added support for `size` attribute on suggesters. + 0.16.3 ------ 2018-10-31 diff --git a/docs_src/advanced_usage_examples.rst b/docs_src/advanced_usage_examples.rst index 49008ac0..a02eb36e 100644 --- a/docs_src/advanced_usage_examples.rst +++ b/docs_src/advanced_usage_examples.rst @@ -1782,12 +1782,18 @@ Example for ``phrase`` suggester: SUGGESTER_PHRASE, ] 'default_suggester': SUGGESTER_COMPLETION, + 'options': { + 'size': 10, # Number of suggestions to retrieve. + }, }, 'publisher_suggest': 'publisher.suggest', 'tag_suggest': 'tags.suggest', 'summary_suggest': 'summary', } +Note, that by default the number of suggestions is limited to 5. If you need +more suggestions, add 'options` dictionary with `size` provided, as show above. + Sample requests/responses ^^^^^^^^^^^^^^^^^^^^^^^^^ Once you have extended your view set with ``SuggesterFilterBackend`` diff --git a/examples/simple/search_indexes/viewsets/address/frontend.py b/examples/simple/search_indexes/viewsets/address/frontend.py index fd7f4467..77518085 100644 --- a/examples/simple/search_indexes/viewsets/address/frontend.py +++ b/examples/simple/search_indexes/viewsets/address/frontend.py @@ -116,10 +116,15 @@ class FrontAddressDocumentViewSet(DocumentViewSet): 'suggesters': [ SUGGESTER_COMPLETION, ], - + 'options': { + 'size': 10, + }, }, 'street_suggest_context': { 'field': 'street.suggest_context', + 'suggesters': [ + SUGGESTER_COMPLETION, + ], 'default_suggester': SUGGESTER_COMPLETION, # We want to be able to filter the completion filter # results on the following params: tag, state and publisher. @@ -130,8 +135,10 @@ class FrontAddressDocumentViewSet(DocumentViewSet): 'geo_filters': { 'title_suggest_loc': 'loc', }, + }, + 'options': { 'size': 10, - } + }, }, 'city_suggest': { 'field': 'city.name.suggest', diff --git a/setup.py b/setup.py index 10cdee3d..4543f6ef 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import find_packages, setup -version = '0.16.3' +version = '0.17' DOCS_TRANSFORMATIONS = ( ( diff --git a/src/django_elasticsearch_dsl_drf/__init__.py b/src/django_elasticsearch_dsl_drf/__init__.py index 74defffb..fd74f4f7 100644 --- a/src/django_elasticsearch_dsl_drf/__init__.py +++ b/src/django_elasticsearch_dsl_drf/__init__.py @@ -3,7 +3,7 @@ """ __title__ = 'django-elasticsearch-dsl-drf' -__version__ = '0.16.3' +__version__ = '0.17' __author__ = 'Artur Barseghyan ' __copyright__ = '2017-2018 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' diff --git a/src/django_elasticsearch_dsl_drf/filter_backends/suggester/native.py b/src/django_elasticsearch_dsl_drf/filter_backends/suggester/native.py index 29c8cdbd..2257c7a1 100644 --- a/src/django_elasticsearch_dsl_drf/filter_backends/suggester/native.py +++ b/src/django_elasticsearch_dsl_drf/filter_backends/suggester/native.py @@ -504,6 +504,13 @@ def get_suggester_query_params(self, request, view): 'type': view.mapping, } + if 'options' in _sf and 'size' in _sf['options']: + suggester_query_params[query_param].update( + { + 'size': _sf['options']['size'] + } + ) + if ( suggester_param == SUGGESTER_COMPLETION and 'completion_options' in _sf diff --git a/src/django_elasticsearch_dsl_drf/tests/test_suggesters.py b/src/django_elasticsearch_dsl_drf/tests/test_suggesters.py index 33e8c093..12329102 100644 --- a/src/django_elasticsearch_dsl_drf/tests/test_suggesters.py +++ b/src/django_elasticsearch_dsl_drf/tests/test_suggesters.py @@ -354,6 +354,7 @@ class TestContextSuggesters(BaseRestFrameworkTestCase, AddressesMixin): @classmethod def setUpClass(cls): """Set up class.""" + # Books cls.books = [] cls.books.append( factories.BookFactory( @@ -413,6 +414,70 @@ def setUpClass(cls): kwargs={} ) + # Addresses + cls.addresses = [] + cls.addresses.append( + factories.AddressFactory( + street='Halabyan', + city__name='Yerevan', + latitude=40.0742719, + longitude=44.1930605, + ) + ) + cls.addresses.append( + factories.AddressFactory( + street='Hambardzumyan', + city__name='Yerevan', + latitude=40.01, + longitude=44.01, + ) + ) + cls.addresses.append( + factories.AddressFactory( + street='Haghartsin', + city__name='Yerevan', + latitude=39.92, + longitude=43.92, + ) + ) + cls.addresses.append( + factories.AddressFactory( + street='Hamazaspyan', + city__name='Tatev', + latitude=39.3793612, + longitude=46.2480006, + ) + ) + cls.addresses.append( + factories.AddressFactory( + street='Harazatyan', + city__name='Tatev', + latitude=39.3793612, + longitude=46.2480006, + ) + ) + cls.addresses.append( + factories.AddressFactory( + street='Hardewijk', + city__name='Groningen', + latitude=53.2246892, + longitude=6.56429, + ) + ) + cls.addresses.append( + factories.AddressFactory( + street='Haringstraat', + city__name='Groningen', + latitude=53.2246892, + longitude=6.56429, + ) + ) + + cls.addresses_suggest_context_url = reverse( + 'addressdocument_frontend-suggest', + kwargs={} + ) + call_command('search_index', '--rebuild', '-f') def _test_suggesters_completion_context(self, test_data, url): @@ -467,6 +532,28 @@ def test_suggesters_completion_context(self): self.books_suggest_context_url ) + # Testing addresses + test_data = { + 'street_suggest_context': { + 'Ha': { + 'expected_results': [ + 'Halabyan', + 'Hambardzumyan', + 'Haghartsin', + 'Hamazaspyan', + 'Harazatyan', + ], + 'filters': { + 'title_suggest_loc': '40__44__1000km', + } + }, + }, + } + self._test_suggesters_completion_context( + test_data, + self.addresses_suggest_context_url + ) + if __name__ == '__main__': unittest.main()