Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drf_haystack_search_filter-1.1.1.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file drf_haystack_search_filter-1.1.1.tar.gz.

File metadata

File hashes

Hashes for drf_haystack_search_filter-1.1.1.tar.gz
Algorithm Hash digest
SHA256 521d8b0b6242a16cbf6895df61522a908d78efc51744661da85faaa76a4cf82e
MD5 d75deb9d92dffbf897a81909942dbe48
BLAKE2b-256 f9c4da2b34b554196d0ead298361b32883fabc88b9407118dfa39ad276e76f3a

See more details on using hashes here.

File details

Details for the file drf_haystack_search_filter-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for drf_haystack_search_filter-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ee2ff1e09b2ff43ff0ba56fa29a56b5b12029048e965359a6a9e801deb3f49b1
MD5 c0ad6f2d9a33e402617df43481068607
BLAKE2b-256 39dcffe26955a2dc559e4e8d576514c8a9b9e0feefb9527792fbf6792db73a6a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page