A django-haystack search filter for Django Rest Framework.
Project description
drf-haystack-search-filter
A django-haystack search filter for Django Rest Framework.
Installation
pip install drf-haystack-search-filter
Usage
Simply import the HaystackSearchFilter
and use it in your API views:
from drf_haystack_search_filter.filters import HaystackSearchFilter
...
class MyAPIView(...):
...
filter_backends = [HaystackSearchFilter, ...]
...
You can customize the search behavior by overriding the _search
method.
from typing import TypeVar
from drf_haystack_search_filter import HaystackSearchFilter
T = TypeVar("T")
class MyHaystackSearchFilter(HaystackSearchFilter):
def _search(self, request: Request, queryset: QuerySet[T], view: APIView, query: str) -> QuerySet[T]:
# Customize the search behavior here
return queryset.filter(
pk__in=(
SearchQuerySet()
.models(queryset.model)
.filter(content__startswith=query)
.values_list("pk", flat=True)
)
)
class MyAPIView(...):
...
filter_backends = [MyHaystackSearchFilter, ...]
...
Contributing
Contributions are welcome! To get started, please refer to our contribution guidelines.
Issues
If you encounter any problems while using this package, please open a new issue here.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file drf_haystack_search_filter-1.1.1.tar.gz
.
File metadata
- Download URL: drf_haystack_search_filter-1.1.1.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 521d8b0b6242a16cbf6895df61522a908d78efc51744661da85faaa76a4cf82e |
|
MD5 | d75deb9d92dffbf897a81909942dbe48 |
|
BLAKE2b-256 | f9c4da2b34b554196d0ead298361b32883fabc88b9407118dfa39ad276e76f3a |
File details
Details for the file drf_haystack_search_filter-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: drf_haystack_search_filter-1.1.1-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee2ff1e09b2ff43ff0ba56fa29a56b5b12029048e965359a6a9e801deb3f49b1 |
|
MD5 | c0ad6f2d9a33e402617df43481068607 |
|
BLAKE2b-256 | 39dcffe26955a2dc559e4e8d576514c8a9b9e0feefb9527792fbf6792db73a6a |