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 lucyfer.searchset.searchhelper import DjangoSearchHelperMixin

from .models import MyModel


class MyModelSearchSet(DjangoSearchHelperMixin, 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.3.14.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

lucyfer-0.3.14-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lucyfer-0.3.14.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.1

File hashes

Hashes for lucyfer-0.3.14.tar.gz
Algorithm Hash digest
SHA256 d64fa1e0f97e1a491f93802c12e4c18ef10b77b1c7ebcb076f3bab2f800c4516
MD5 335a77224627d0d3e082d9690eb37dfe
BLAKE2b-256 ce2be6bd4f5c2b538fd38d37f31d0364b99bd1666ac55b3984227cf75012aebe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lucyfer-0.3.14-py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.1

File hashes

Hashes for lucyfer-0.3.14-py3-none-any.whl
Algorithm Hash digest
SHA256 5bb6d1749d5553c37b076673d1ac468f8ddc462d1e7ca434c5fafb5150e22c5c
MD5 a8f4c74a23738328612dd9bdb2f5358d
BLAKE2b-256 5563e05ff7649859920dfdbc346c6e9a3eca41a2c2395643ee3c8d1c797c6606

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