A simple package to implement a django-haystack search filter in Django Rest Framework
Project description
drf-haystack-search-filter
A simple package to implement a django-haystack search filter in 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
Close
Hashes for drf_haystack_search_filter-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02596699833956a61ca4f193815b4331682924fbfc7c1c0d5453b16e4f04c7f1 |
|
MD5 | 78952b07eda684012706f101d6818557 |
|
BLAKE2b-256 | a6e0f9e9fdcec37f88393f551530e7c132c7ece588aa74333a37cd2a8b7f1fa8 |
Close
Hashes for drf_haystack_search_filter-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22cadbbf01ba949883ce127909d87c9af55f9f63dcc6b55c746406ecbdb70859 |
|
MD5 | c1833d11f211ff214110f47a9e7c8041 |
|
BLAKE2b-256 | 4289fafa246696f1423f179e2fa69c1f8e7bddd419f8ac6ef7ca5d13f73e1ff8 |