Skip to main content

Lucene search for DRF and elasticsearch-dsl

Project description

Lucene way search in django

("Django" AND "DRF") OR ("Elasticserach-DSL" AND "Django Rest Elasticsearch")


Only for Django with DRF:

pip install lucyfer

For Django with DRF and Elasticsearch-dsl with DRF:

pip install lucyfer[full]


lucyfer lucyfer[full]
lucyparser + +
Django + +
djangorestframework + +
django-rest-elasticsearch - +
elasticsearch-dsl - +

Usage Example

Create your search backend class:

from lucyfer.backend import LuceneSearchFilter, DjangoLuceneSearchFilterMixin, ElasticLuceneSearchFilterMixin

class SearchBackend(DjangoLuceneSearchFilterMixin, ElasticLuceneSearchFilterMixin, LuceneSearchFilter):

Copy reference to SearchBackend class and include it in DEFAULT_FILTER_BACKENDS in instead of default search backend:


Create file in your django-application and fill it:

from lucyfer.searchset import DjangoSearchSet
from lucyfer.searchset.fields.django import DjangoCharField

from .models import MyModel

class MyModelSearchSet(DjangoSearchSet):
    some_field = DjangoCharField(sources=["another_field__name"], exclude_sources_from_mapping=True)

    class Meta:
        model = MyModel

    fields_to_exclude_from_mapping = ['field_to_exclude_from_mapping', ]

Include searchset class in your ModelViewSet:

from rest_framework.viewsets import ModelViewSet

from .searchsets import MyModelSearchSet

class MyModelViewSet(ModelViewSet):
    search_class = MyModelSearchSet

You have to save search_fields in your ModelViewSet if you want to save custom search possibility.

Now you can use lucene-way syntax for your view.

Tests execution:

pytest tests/test_* -c tests/pytest.ini 

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.

Files for lucyfer, version 0.5.6
Filename, size File type Python version Upload date Hashes
Filename, size lucyfer-0.5.6-py3-none-any.whl (22.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size lucyfer-0.5.6.tar.gz (14.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page