Lucene way search in django
("Django" AND "DRF") OR "Elasticserach-DSL"
Installation
Only for Django with DRF:
pip install lucyfer
For Django with DRF and Elasticsearch-dsl:
pip install lucyfer[full]
Dependencies
| lucyfer | lucyfer[full] | |
|---|---|---|
| lucyparser | + | + |
| Django | + | + |
| djangorestframework | + | + |
| 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 .models import MyModel
class MyModelSearchSet(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.
Tests execution:
pytest tests/test_* -c tests/pytest.ini
Release files for lucyfer 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lucyfer-0.7.0.tar.gz | 14.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lucyfer-0.7.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 36.4 kB
Release files / lucyfer-0.7.0.tar.gz
| Download URL | lucyfer-0.7.0.tar.gz |
|---|---|
| Size | 14.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9735ae0651ca39f04224a3c4eca1d1ccecb4e0db11ba9601a571736ba9c02175
|
|
BLAKE2b-256 checksum How to use checksums |
ad9f04659f7d056fbc03448611720bfb978ae59a6911f5e0ac72f6b6aa81eee2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.0
|
Release files / lucyfer-0.7.0-py3-none-any.whl
| Download URL | lucyfer-0.7.0-py3-none-any.whl |
|---|---|
| Size | 22.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d168736fd7a1777b1e0c6960bd15ff4475cee9cd45cd69593b32f756a83c348b
|
|
BLAKE2b-256 checksum How to use checksums |
da25be106cec11b35a4461d1287097fbf77e18e19ce5c0929dd3f9d64c1077d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.0
|