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 --frozen --group=development
uv run --frozen pre-commit install --install-hooks
uv run --frozen 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.3.0.tar.gz (12.6 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.3.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for drf_haystack_search_filter-1.3.0.tar.gz
Algorithm Hash digest
SHA256 9e99e436c9ad08f65f63815864995b5408bded280aa6951b5e4c098269c94d2d
MD5 27acde6e560b2d332bc2d3de7a19297f
BLAKE2b-256 a8510e3824d32ec58aef7a4d5508f128d7c8cbe7ddfb812d96d46ca1fd4225df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for drf_haystack_search_filter-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 76a182660750f2ae8b01ce5ea8cb1303e661f7360c851044380e8d7db14a0f26
MD5 df26caa1bc7269cf204da92760cb619a
BLAKE2b-256 7a4d7edac38b64e1c6af96fa4f4eda298a36ed9edca18359a449b24bad0bb981

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