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 lusya

For Django with DRF and Elasticsearch-dsl with DRF:

pip install lucyfer

Dependencies

lucyfer lusya
lucyparser + +
Django + +
djangorestframework + +
django-rest-elasticsearch + -
elasticsearch-dsl + -

Usage Example

All examples illustrates lucyfer library usage. In lusya case anything is the same except of base classes.


Create your search backend class:

from lucyfer.base.backend import LuceneSearchFilter
from lucyfer.django.backend import DjangoLuceneSearchFilterMixin
from lucyfer.elastic.backend import 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.django.searchhelper import DjangoSearchHelperMixin
from lucyfer.django.searchset import DjangoSearchSet
from lucyfer.django.fields import CharField

from .models import MyModel


class MyModelSearchSet(DjangoSearchHelperMixin, DjangoSearchSet):
    some_field = CharField(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.1.6.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

lucyfer-0.1.6-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lucyfer-0.1.6.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

File hashes

Hashes for lucyfer-0.1.6.tar.gz
Algorithm Hash digest
SHA256 6429a4e7a6f460d6cdf85e9d7b1a605e542079359fd48b20569df4c244348a09
MD5 21da7ba3d5786b12b74c8e22269c553e
BLAKE2b-256 7dcb3fe98c387b039e329b1d8f1d7230e0a8c08fcb552fe2ba50edf71fa5912d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lucyfer-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

File hashes

Hashes for lucyfer-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 8075c893ee6d771b6da9e80cf472d68755165c8b0f8e0d472f77c4d419768b7a
MD5 9feb1a68b6da0cc3024bfb9dd5442cbe
BLAKE2b-256 a9795d80b483d92c00125b9c0554e5a28ff51a5ee66fba598fc1d5c37ec5777e

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