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.

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

Uploaded Source

Built Distribution

lucyfer-0.2.6-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lucyfer-0.2.6.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.6.8

File hashes

Hashes for lucyfer-0.2.6.tar.gz
Algorithm Hash digest
SHA256 77bc40cc4d7e4cc12d2a6f46a9f59b8685b0a48d4562c810b25cc84373de73af
MD5 7d4048c7f5cd8ade57e1b8e2ca809f2d
BLAKE2b-256 7423b30cb7b1644e8e039b6a7f3a29869cf5dc71fe8290d3ce537e0b338ca3bb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lucyfer-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.6.8

File hashes

Hashes for lucyfer-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 daf804661e975a8edd0e7cb7d6bb734649cfa2335771683e2ff4ebae2c2e4baa
MD5 02f23cd47e120a2da6214ddcd51d301f
BLAKE2b-256 a98f3fd84a463203bbbbb31c6751d47cbbaf1cb8e51d2c0c012d866c26a43a5f

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