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")


Installation

Only for Django with DRF:

pip install lucyfer

For Django with DRF and Elasticsearch-dsl with DRF:

pip install lucyfer[full]

Dependencies

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):
    pass

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

REST_FRAMEWORK = {
    'DEFAULT_FILTER_BACKENDS': ('path.to.SearchBackend',)
}

Create searchsets.py 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.

Source Distribution

lucyfer-0.5.1.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

lucyfer-0.5.1-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file lucyfer-0.5.1.tar.gz.

File metadata

  • Download URL: lucyfer-0.5.1.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.0

File hashes

Hashes for lucyfer-0.5.1.tar.gz
Algorithm Hash digest
SHA256 ff8d754e8b1a1ae64b81b3eb307cf47033898720464b47fd90e710fefdbbe2a2
MD5 ba735b200adcad74e51a1c6273e09f2f
BLAKE2b-256 05c0f043a7a6f7ea8e0bd51799c35a1a73928fa0df6c36d918268af286823473

See more details on using hashes here.

File details

Details for the file lucyfer-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: lucyfer-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.0

File hashes

Hashes for lucyfer-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ad4bc76aa7625206ae0f7ef686bf7ac092f2d89377f6720e6c77544608e2974f
MD5 9e77892b40aa08ef53530db174ad8d38
BLAKE2b-256 be726998d02a6aae50144af97b938bf83879aa0fe3e5f163490ec4c1e5d0f10a

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