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.

This package uses uv for project management. To get started, ensure that uv is installed on your machine and updated to the 0.5.6 version. Detailed installation instructions for uv can be found here.

Installation

uv add 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, ...]
    ...

Development

uv sync --group=development
uv run pre-commit install --install-hooks
uv run pre-commit install --hook-type=commit-msg

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.2.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drf_haystack_search_filter-1.2.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for drf_haystack_search_filter-1.2.0.tar.gz
Algorithm Hash digest
SHA256 6457e7586fd48247b2836471a76a4969e37896a57e0e9da8f7894e3c41ee8f9d
MD5 29de6f7e696c7c99a4ef8e228d488d11
BLAKE2b-256 9d48c1b4e7f1dd638bdaced6ae111947211de1000afd100550b4f3e2388fee6e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for drf_haystack_search_filter-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 295e4cea0223f8a884d49eb000615de0297e9d671ff211ba16b40c1983e49e2f
MD5 54d70a02c7239b2f7dc843bfca2b2ef0
BLAKE2b-256 4887eb3a6a22b1a455e4fc09aafaa9a1c3c26d4988f621afe6f22ba55f522bfb

See more details on using hashes here.

Supported by

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