Skip to content

Commit

Permalink
prepare 0.17
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Dec 11, 2018
1 parent 2078624 commit 03a3aa7
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 4 deletions.
1 change: 1 addition & 0 deletions .hgignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ syntax: regexp
^vagrant/\.vagrant
^\.pytest_cache/
node_modules/
yarn-error\.log

^MANIFEST\.in~
^tmp/
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/whythawk>`_.

- Added support for context suggesters (`category` and `geo`).
- Added support for `size` attribute on suggesters.

0.16.3
------
2018-10-31
Expand Down
6 changes: 6 additions & 0 deletions docs/advanced_usage_examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand Down
11 changes: 11 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/whythawk>`_.

- Added support for context suggesters (`category` and `geo`).
- Added support for `size` attribute on suggesters.

0.16.3
------
2018-10-31
Expand Down
6 changes: 6 additions & 0 deletions docs_src/advanced_usage_examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand Down
11 changes: 9 additions & 2 deletions examples/simple/search_indexes/viewsets/address/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -130,8 +135,10 @@ class FrontAddressDocumentViewSet(DocumentViewSet):
'geo_filters': {
'title_suggest_loc': 'loc',
},
},
'options': {
'size': 10,
}
},
},
'city_suggest': {
'field': 'city.name.suggest',
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import find_packages, setup

version = '0.16.3'
version = '0.17'

DOCS_TRANSFORMATIONS = (
(
Expand Down
2 changes: 1 addition & 1 deletion src/django_elasticsearch_dsl_drf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

__title__ = 'django-elasticsearch-dsl-drf'
__version__ = '0.16.3'
__version__ = '0.17'
__author__ = 'Artur Barseghyan <[email protected]>'
__copyright__ = '2017-2018 Artur Barseghyan'
__license__ = 'GPL 2.0/LGPL 2.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
87 changes: 87 additions & 0 deletions src/django_elasticsearch_dsl_drf/tests/test_suggesters.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ class TestContextSuggesters(BaseRestFrameworkTestCase, AddressesMixin):
@classmethod
def setUpClass(cls):
"""Set up class."""
# Books
cls.books = []
cls.books.append(
factories.BookFactory(
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()

0 comments on commit 03a3aa7

Please sign in to comment.