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
Built Distribution
File details
Details for the file lucyfer-0.1.4.tar.gz
.
File metadata
- Download URL: lucyfer-0.1.4.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | beb89bce0ce32d3bc655ce37eeebe048efe6ecebbee026559615611a30b5f891 |
|
MD5 | 0fe3cae97cce6e205f8e227f02fa4fe9 |
|
BLAKE2b-256 | afd61037fd36ba83c4a7a74814fc22b820c0110b42e9da84a561fab9dee348cf |
File details
Details for the file lucyfer-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: lucyfer-0.1.4-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 230b649905b378d493ac7a277a7fa5c82511c80de9c5ac805a0588379b8d9711 |
|
MD5 | da872fb8eaee0eedec4d261521f577e6 |
|
BLAKE2b-256 | ac0dd08c63578971cf3f6dfeb8b74b8fa001ceff91db657091323e16a75e4da6 |