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

Uploaded Source

Built Distribution

lucyfer-0.2.8-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lucyfer-0.2.8.tar.gz
  • Upload date:
  • Size: 9.3 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.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.0a2

File hashes

Hashes for lucyfer-0.2.8.tar.gz
Algorithm Hash digest
SHA256 1e5b8b3276542e86f07be72af1c120d4d9d0673409a571a31370bd9df72cd582
MD5 eae61a380fbfdecc6a0f605c06856565
BLAKE2b-256 ae791c1fedc76e608c63c89858cc8ae44ff02850d04722fa16790dbd24e1d967

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lucyfer-0.2.8-py3-none-any.whl
  • Upload date:
  • Size: 17.3 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.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.0a2

File hashes

Hashes for lucyfer-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 b929da7b7b39e0209ddbbdd2e5da32d63ad49bf3bc8a6f22dd761e39a49ddf06
MD5 0c1dfda27bd4188491bb389851fc0c49
BLAKE2b-256 4d16e58dd5230c9be70c2f8a4d191ea911589ce89f6e9f348f13da8c92bdeb87

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