Skip to content

Commit a43bcfb

Browse files
add default filter lookup option; more on correcting the docs regarding the separators change
1 parent 68549fa commit a43bcfb

File tree

17 files changed

+300
-786
lines changed

17 files changed

+300
-786
lines changed

CHANGELOG.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ yyyy-mm-dd (not released yet)
2828
Do not keep things as they were in your own fork, since new search backends
2929
will use the `|` and `:` symbols differently.
3030

31+
**Shortcuts**
32+
33+
.. code-block:: text
34+
35+
36+
37+
3138
- `SEPARATOR_LOOKUP_VALUE` has been removed. Use
3239
`SEPARATOR_LOOKUP_COMPLEX_VALUE` and
3340
`SEPARATOR_LOOKUP_COMPLEX_MULTIPLE_VALUE` instead.
34-
# TODO: Name a couple of usage examples.
3541
- `SEPARATOR_LOOKUP_NAME` has been added.
36-
# TODO: Name a couple of usage examples.
3742
- The method `split_lookup_complex_value` has been removed. Use
3843
`split_lookup_complex_value` instead.
3944

advanced_usage_examples.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,11 @@ Search in all fields (``title``, ``description`` and ``summary``) for word
517517
**Search a single term on specific field**
518518

519519
In order to search in specific field (``title``) for term "education", add
520-
the field name separated with ``|`` to the search term.
520+
the field name separated with ``:`` to the search term.
521521

522522
.. code-block:: text
523523
524-
http://127.0.0.1:8080/search/books/?search=title|education
524+
http://127.0.0.1:8080/search/books/?search=title:education
525525
526526
**Search for multiple terms**
527527

@@ -536,11 +536,11 @@ multiple ``search`` query params.
536536

537537
In order to search for multiple terms "education", "technology" in specific
538538
fields add multiple ``search`` query params and field names separated with
539-
``|`` to each of the search terms.
539+
``:`` to each of the search terms.
540540

541541
.. code-block:: text
542542
543-
http://127.0.0.1:8080/search/books/?search=title|education&search=summary|technology
543+
http://127.0.0.1:8080/search/books/?search=title:education&search=summary:technology
544544
545545
**Search with boosting**
546546

@@ -590,7 +590,7 @@ Filter documents by field (``states``) "published" and "in_progress".
590590

591591
.. code-block:: text
592592
593-
http://127.0.0.1:8080/search/books/?state__in=published|in_progress
593+
http://127.0.0.1:8080/search/books/?state__in=published__in_progress
594594
595595
**Filter document by a single field**
596596

@@ -607,7 +607,7 @@ with use of functional ``in`` query filter.
607607

608608
.. code-block:: text
609609
610-
http://127.0.0.1:8080/search/books/?tags__in=education|economy
610+
http://127.0.0.1:8080/search/books/?tags__in=education__economy
611611
612612
You can achieve the same effect by specifying multiple fields (``tags``)
613613
"education" and "economy". Note, that in this case multiple filter terms are
@@ -644,15 +644,15 @@ Order documents by field ``price`` (ascending).
644644

645645
.. code-block:: text
646646
647-
http://127.0.0.1:8080/search/books/?search=title|lorem&ordering=price
647+
http://127.0.0.1:8080/search/books/?search=title:lorem&ordering=price
648648
649649
**Order documents by field (descending)**
650650

651651
Order documents by field ``price`` (descending).
652652

653653
.. code-block:: text
654654
655-
http://127.0.0.1:8080/search/books/?search=title|lorem&ordering=-price
655+
http://127.0.0.1:8080/search/books/?search=title:lorem&ordering=-price
656656
657657
**Order documents by multiple fields**
658658

@@ -662,15 +662,15 @@ the example below, documents would be ordered first by field
662662

663663
.. code-block:: text
664664
665-
http://127.0.0.1:8080/search/books/?search=title|lorem&ordering=-publication_date&ordering=price
665+
http://127.0.0.1:8080/search/books/?search=title:lorem&ordering=-publication_date&ordering=price
666666
667667
Ids filter
668668
----------
669669
Filters documents that only have the provided ids.
670670

671671
.. code-block:: text
672672
673-
http://127.0.0.1:8000/api/articles/?ids=68|64|58
673+
http://127.0.0.1:8000/api/articles/?ids=68__64__58
674674
675675
Or, alternatively:
676676

@@ -881,7 +881,7 @@ Filter documents by field (``states``) "published" and "in_progress".
881881

882882
.. code-block:: text
883883
884-
http://127.0.0.1:8080/search/books/?state_pf__in=published|in_progress
884+
http://127.0.0.1:8080/search/books/?state_pf__in=published__in_progress
885885
886886
Geo-spatial features
887887
--------------------
@@ -900,23 +900,23 @@ Filter documents by radius of 100000km from the given location.
900900

901901
.. code-block:: text
902902
903-
http://localhost:8000/search/publishers/?location__geo_distance=100000km|12.04|-63.93
903+
http://localhost:8000/search/publishers/?location__geo_distance=100000km__12.04__-63.93
904904
905905
**Geo-polygon filtering**
906906

907907
Filter documents that are located in the given polygon.
908908

909909
.. code-block:: text
910910
911-
http://localhost:8000/search/publishers/?location__geo_polygon=40,-70|30,-80|20,-90
911+
http://localhost:8000/search/publishers/?location__geo_polygon=40,-70__30,-80__20,-90
912912
913913
**Geo-bounding-box filtering**
914914

915915
Filter documents that are located in the given bounding box.
916916

917917
.. code-block:: text
918918
919-
http://localhost:8000/search/publishers/?location__geo_bounding_box=44.87,40.07|43.87,41.11
919+
http://localhost:8000/search/publishers/?location__geo_bounding_box=44.87,40.07__43.87,41.11
920920
921921
Ordering
922922
~~~~~~~~
@@ -925,7 +925,7 @@ Ordering
925925

926926
.. code-block:: text
927927
928-
http://localhost:8000/search/publishers/?ordering=location|48.85|2.30|km|plane
928+
http://localhost:8000/search/publishers/?ordering=location__48.85__2.30__km__plane
929929
930930
Suggestions
931931
-----------

examples/simple/search_indexes/urls.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
BookOrderingByScoreDocumentViewSet,
88
BookFunctionalSuggesterDocumentViewSet,
99
BookMoreLikeThisDocumentViewSet,
10+
BookDefaultFilterLookupDocumentViewSet,
1011
CityDocumentViewSet,
1112
PublisherDocumentViewSet,
1213
)
@@ -51,6 +52,12 @@
5152
base_name='bookdocument_more_like_this'
5253
)
5354

55+
books_default_filter_lookup = router.register(
56+
r'books-default-filter-lookup',
57+
BookDefaultFilterLookupDocumentViewSet,
58+
base_name='bookdocument_default_filter_lookup'
59+
)
60+
5461
cities = router.register(
5562
r'cities',
5663
CityDocumentViewSet,

examples/simple/search_indexes/viewsets/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
BookOrderingByScoreDocumentViewSet,
66
BookFunctionalSuggesterDocumentViewSet,
77
BookMoreLikeThisDocumentViewSet,
8+
BookDefaultFilterLookupDocumentViewSet,
89
)
910
from .city import CityDocumentViewSet
1011
from .publisher import PublisherDocumentViewSet
@@ -15,6 +16,7 @@
1516
'BookDocumentViewSet',
1617
'BookFunctionalSuggesterDocumentViewSet',
1718
'BookMoreLikeThisDocumentViewSet',
19+
'BookDefaultFilterLookupDocumentViewSet',
1820
'BookOrderingByScoreDocumentViewSet',
1921
'CityDocumentViewSet',
2022
'PublisherDocumentViewSet',

examples/simple/search_indexes/viewsets/book.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
FUNCTIONAL_SUGGESTER_COMPLETION_PREFIX,
44
LOOKUP_FILTER_PREFIX,
55
LOOKUP_FILTER_RANGE,
6+
LOOKUP_FILTER_TERM,
67
LOOKUP_FILTER_TERMS,
78
LOOKUP_FILTER_WILDCARD,
89
LOOKUP_QUERY_EXCLUDE,
@@ -45,6 +46,7 @@
4546
'BookOrderingByScoreDocumentViewSet',
4647
'BookFunctionalSuggesterDocumentViewSet',
4748
'BookMoreLikeThisDocumentViewSet',
49+
'BookDefaultFilterLookupDocumentViewSet',
4850
)
4951

5052

@@ -295,6 +297,33 @@ class BookOrderingByScoreDocumentViewSet(BookDocumentViewSet):
295297
ordering = ('_score', 'id', 'title', 'price',)
296298

297299

300+
class BookDefaultFilterLookupDocumentViewSet(BookDocumentViewSet):
301+
"""Same as parent, but with default filter lookups & no default facets."""
302+
303+
filter_fields = {
304+
'authors': {
305+
'field': 'authors.raw',
306+
'lookups': [
307+
LOOKUP_FILTER_TERM,
308+
LOOKUP_FILTER_TERMS,
309+
LOOKUP_FILTER_PREFIX,
310+
LOOKUP_FILTER_WILDCARD,
311+
LOOKUP_QUERY_IN,
312+
LOOKUP_QUERY_EXCLUDE,
313+
],
314+
'default_lookup': LOOKUP_FILTER_TERM,
315+
},
316+
}
317+
318+
faceted_search_fields = {
319+
'state': 'state.raw',
320+
'publisher': {
321+
'field': 'publisher.raw',
322+
'enabled': False,
323+
},
324+
}
325+
326+
298327
class BookMoreLikeThisDocumentViewSet(BaseDocumentViewSet,
299328
MoreLikeThisMixin):
300329
"""Same as BookDocumentViewSet, with more-like-this and no facets."""

filtering_usage_examples.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ Search a single term on specific field
3333
--------------------------------------
3434

3535
In order to search in specific field (``name``) for term "reilly", add
36-
the field name separated with ``|`` to the search term.
36+
the field name separated with ``:`` to the search term.
3737

3838
.. code-block:: text
3939
40-
http://127.0.0.1:8080/search/publisher/?search=name|reilly
40+
http://127.0.0.1:8080/search/publisher/?search=name:reilly
4141
4242
Search for multiple terms
4343
-------------------------
@@ -54,11 +54,11 @@ Search for multiple terms in specific fields
5454

5555
In order to search for multiple terms "reilly", "bloomsbury" in specific
5656
fields add multiple ``search`` query params and field names separated with
57-
``|`` to each of the search terms.
57+
``:`` to each of the search terms.
5858

5959
.. code-block:: text
6060
61-
http://127.0.0.1:8080/search/publisher/?search=name|reilly&search=city|london
61+
http://127.0.0.1:8080/search/publisher/?search=name:reilly&search=city:london
6262
6363
Filtering
6464
=========
@@ -98,7 +98,7 @@ specified.
9898
.. code-block:: text
9999
100100
http://localhost:8000/api/articles/?id=1&id=2&id=3
101-
http://localhost:8000/api/articles/?id__terms=1;2;3
101+
http://localhost:8000/api/articles/?id__terms=1__2__3
102102
103103
range
104104
^^^^^
@@ -109,15 +109,15 @@ strings) in the range specified.
109109

110110
.. code-block:: text
111111
112-
http://localhost:8000/api/users/?age__range=16;67
112+
http://localhost:8000/api/users/?age__range=16__67
113113
114114
.. code-block:: text
115115
116116
**From, to, boost**
117117

118118
.. code-block:: text
119119
120-
http://localhost:8000/api/users/?age__range=16;67;2.0
120+
http://localhost:8000/api/users/?age__range=16__67__2.0
121121
122122
exists
123123
^^^^^^
@@ -152,7 +152,7 @@ Find documents with the specified type and IDs.
152152

153153
.. code-block:: text
154154
155-
http://localhost:8000/api/articles/?ids=68;64;58
155+
http://localhost:8000/api/articles/?ids=68__64__58
156156
http://localhost:8000/api/articles/?ids=68&ids=64&ids=58
157157
158158
Functional
@@ -182,7 +182,7 @@ In a given list.
182182

183183
.. code-block:: text
184184
185-
http://localhost:8000/api/articles/?id__in=1;2;3
185+
http://localhost:8000/api/articles/?id__in=1__2__3
186186
187187
gt
188188
^^
@@ -254,6 +254,7 @@ lookup parameters.
254254
.. code-block:: text
255255
256256
http://localhost:8000/api/articles/?tags__exclude=children
257+
http://localhost:8000/api/articles/?tags__exclude=children__python
257258
258259
Usage examples
259260
==============

0 commit comments

Comments
 (0)