Lucene search for DRF and elasticsearch-dsl
Project description
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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lucyfer-0.7.0.tar.gz.
File metadata
- Download URL: lucyfer-0.7.0.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9735ae0651ca39f04224a3c4eca1d1ccecb4e0db11ba9601a571736ba9c02175
|
|
| MD5 |
f5b5d77cec9dd92d710049d0a2ddcfb9
|
|
| BLAKE2b-256 |
ad9f04659f7d056fbc03448611720bfb978ae59a6911f5e0ac72f6b6aa81eee2
|
File details
Details for the file lucyfer-0.7.0-py3-none-any.whl.
File metadata
- Download URL: lucyfer-0.7.0-py3-none-any.whl
- Upload date:
- Size: 22.0 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d168736fd7a1777b1e0c6960bd15ff4475cee9cd45cd69593b32f756a83c348b
|
|
| MD5 |
fed3121243838d07d444698ac95f6270
|
|
| BLAKE2b-256 |
da25be106cec11b35a4461d1287097fbf77e18e19ce5c0929dd3f9d64c1077d8
|