Debian Codegraph @

docs/06_term_boost.rst

raw
1 .. _term-boost-label:
2
3 Term Boost
4 ==========
5
6 .. warning::
7
8 **BIG FAT WARNING**
9
10 As far as I can see, the term boost functionality is implemented by the specs in the
11 `Haystack documentation <https://django-haystack.readthedocs.io/en/v2.4.0/boost.html#term-boost>`_,
12 however it does not really work as it should!
13
14 When applying term boost, results are discarded from the search result, and not re-ordered by
15 boost weight as they should.
16 These are known problems and there exists open issues for them:
17
18 - https://github.com/inonit/drf-haystack/issues/21
19 - https://github.com/django-haystack/django-haystack/issues/1235
20 - https://github.com/django-haystack/django-haystack/issues/508
21
22 **Please do not use this unless you really know what you are doing!**
23
24 (And please let me know if you know how to fix it!)
25
26
27 Term boost is achieved on the SearchQuerySet level by calling ``SearchQuerySet().boost()``. It is
28 implemented as a :class:`drf_haystack.filters.HaystackBoostFilter` filter backend.
29 The ``HaystackBoostFilter`` does not perform any filtering by itself, and should therefore be combined with
30 some other filter that does, for example the :class:`drf_haystack.filters.HaystackFilter`.
31
32 .. code-block:: python
33
34 from drf_haystack.filters import HaystackBoostFilter
35
36 class SearchViewSet(HaystackViewSet):
37 ...
38 filter_backends = [HaystackFilter, HaystackBoostFilter]
39
40
41 The filter expects the query string to contain a ``boost`` parameter, which is a comma separated string
42 of the term to boost and the boost value. The boost value must be either an integer or float value.
43
44 **Example query**
45
46 .. code-block:: none
47
48 /api/v1/search/?firstname=robin&boost=hood,1.1
49
50 The query above will first filter on ``firstname=robin`` and next apply a slight boost on any document containing
51 the word ``hood``.
52
53 .. note::
54
55 Term boost are only applied on terms existing in the ``document field``.