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.1.191.tar.gz
(9.3 kB
view hashes)
Built Distribution
lucyfer-0.1.191-py3-none-any.whl
(23.0 kB
view hashes)
Close
Hashes for lucyfer-0.1.191-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53f9104c95e544fa9a9179e5194e2ac07fa1de193d802fdc0993ab79a56d7347 |
|
MD5 | 15dbe69e3b4fe0f3d8417d2de34008c2 |
|
BLAKE2b-256 | 765f09b63557cff7b21166df7d4eee0b98f010da54043fbffb0a37c1d13a27b7 |