Skip to content

Commit 85d96a1

Browse files
Merge branch 'master' of github.com:barseghyanartur/django-elasticsearch-dsl-drf
2 parents 4410186 + a75bb6f commit 85d96a1

File tree

8 files changed

+62
-3
lines changed

8 files changed

+62
-3
lines changed

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.16.1
19+
------
20+
2018-09-18
21+
22+
- Make it possible to control the size of the functional suggester queries.
23+
1824
0.16
1925
----
2026
2018-09-10

docs/advanced_usage_examples.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,10 @@ functionality). Thus, it might be written as short as:
19751975
FUNCTIONAL_SUGGESTER_COMPLETION_PREFIX,
19761976
],
19771977
'default_suggester': FUNCTIONAL_SUGGESTER_COMPLETION_PREFIX,
1978+
'options': {
1979+
'size': 25,
1980+
'from': 0,
1981+
}
19781982
},
19791983
'title_suggest_match': {
19801984
'field': 'title.edge_ngram_completion',
@@ -1983,6 +1987,12 @@ functionality). Thus, it might be written as short as:
19831987
}
19841988
}
19851989
1990+
.. note::
1991+
1992+
Note, that in ``functional_suggester_fields['title_suggest']['options']``
1993+
there are two params: ``size`` and ``from``. They control the query size
1994+
and the offset of the generated functional suggest query.
1995+
19861996
Highlighting
19871997
------------
19881998
Highlighters enable you to get highlighted snippets from one or more fields

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.16.1
19+
------
20+
2018-09-18
21+
22+
- Make it possible to control the size of the functional queries.
23+
1824
0.16
1925
----
2026
2018-09-10

docs_src/advanced_usage_examples.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,10 @@ functionality). Thus, it might be written as short as:
19751975
FUNCTIONAL_SUGGESTER_COMPLETION_PREFIX,
19761976
],
19771977
'default_suggester': FUNCTIONAL_SUGGESTER_COMPLETION_PREFIX,
1978+
'options': {
1979+
'size': 25,
1980+
'from': 0,
1981+
}
19781982
},
19791983
'title_suggest_match': {
19801984
'field': 'title.edge_ngram_completion',
@@ -1983,6 +1987,12 @@ functionality). Thus, it might be written as short as:
19831987
}
19841988
}
19851989
1990+
.. note::
1991+
1992+
Note, that in ``functional_suggester_fields['title_suggest']['options']``
1993+
there are two params: ``size`` and ``from``. They control the query size
1994+
and the offset of the generated functional suggest query.
1995+
19861996
Highlighting
19871997
------------
19881998
Highlighters enable you to get highlighted snippets from one or more fields

examples/simple/search_indexes/viewsets/book/functional_suggester.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class BookFunctionalSuggesterDocumentViewSet(BaseBookDocumentViewSet,
4747
FUNCTIONAL_SUGGESTER_COMPLETION_MATCH,
4848
],
4949
'default_suggester': FUNCTIONAL_SUGGESTER_COMPLETION_PREFIX,
50+
'options': {
51+
'size': 100,
52+
'from': 0,
53+
}
5054
# 'serializer_field': 'title',
5155
},
5256
'title_suggest_match': {

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'
5+
version = '0.16.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.16'
6+
__version__ = '0.16.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/filter_backends/suggester/functional.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class FunctionalSuggesterFilterBackend(BaseFilterBackend, FilterBackendMixin):
130130
>>> FunctionalSuggesterFilterBackend,
131131
>>> ]
132132
>>> # Suggester fields
133-
>>> suggester_fields = {
133+
>>> functional_suggester_fields = {
134134
>>> 'name_suggest': {
135135
>>> 'field': 'name.suggest',
136136
>>> 'suggesters': [
@@ -231,6 +231,21 @@ def prepare_suggester_fields(cls, view):
231231
# phrase={'field': options['field']}
232232
# )
233233

234+
@classmethod
235+
def apply_query_size(cls, queryset, options):
236+
"""Apply query size.
237+
238+
:param queryset:
239+
:param options:
240+
:return:
241+
"""
242+
if 'size' in options['options']:
243+
queryset = queryset.extra(
244+
from_=options['options'].get('from', 0),
245+
size=options['options']['size']
246+
)
247+
return queryset
248+
234249
@classmethod
235250
def apply_suggester_completion_prefix(cls,
236251
suggester_name,
@@ -256,6 +271,7 @@ def apply_suggester_completion_prefix(cls,
256271
'prefix',
257272
**{options['field']: value}
258273
)
274+
queryset = cls.apply_query_size(queryset, options)
259275
return queryset
260276

261277
@classmethod
@@ -283,6 +299,7 @@ def apply_suggester_completion_match(cls,
283299
'match',
284300
**{options['field']: value}
285301
)
302+
queryset = cls.apply_query_size(queryset, options)
286303
return queryset
287304

288305
def get_suggester_query_params(self, request, view):
@@ -313,13 +330,18 @@ def get_suggester_query_params(self, request, view):
313330

314331
valid_suggesters = suggester_fields[field_name]['suggesters']
315332

333+
suggester_options = {}
334+
316335
# If we have default suggester given use it as a default and
317336
# do not require further suffix specification.
318337
default_suggester = None
319338
if 'default_suggester' in suggester_fields[field_name]:
320339
default_suggester = \
321340
suggester_fields[field_name]['default_suggester']
322341

342+
if 'options' in suggester_fields[field_name]:
343+
suggester_options = suggester_fields[field_name]['options']
344+
323345
if suggester_param is None \
324346
or suggester_param in valid_suggesters:
325347

@@ -360,6 +382,7 @@ def get_suggester_query_params(self, request, view):
360382
),
361383
'type': view.mapping,
362384
'serializer_field': serializer_field,
385+
'options': suggester_options,
363386
}
364387
return suggester_query_params
365388

0 commit comments

Comments
 (0)