A key word based queryset search for django
Project description
Django Fine Search
https://github.com/bellomusodiq/dj-fine-search
Django fine search is package that performs search based on keywords. It allows word flexibility for performing filter in a queryset. e.g. The native Model.object.filter(title__icontains='hello world') will return queryset of objects that contains substring "hello world", if the "world" comes before the "hello", the objects would not be found. Django fine search improves that, Django fine search will include all objects that has substring "hello world".
class MyModel(models.Model):
title = models.Charfield(max_length=200)
text = models.TextField()
...
perform_search takes in the model, search_text and fields
model: Model class, the model to perform filter on
search_text: string, the query that will be used for the filtering
fields: list or tuple of the fields of the models that the search will be performed on e.g. title and text above
perform_search function returns a list of model objects
from django_fine_search import perform_search
queryset = perform_search(model=MyModel, search_text='hello world', fields=["title", "text"])
assume we have the queryset below are result of MyModel.objects.all() queryset = [{"id": 1, "title": "some title", "text": "hello world, how are you"}, {"id": 2, "title": "some title2", "text": "the world is good"}, {"id": 3, "title": "some title3", "text": "world hello there, hello"}]
if we run perform_search on the MyModel with search_text='hello world' and fields=['title', 'fields']
it will return all the queries
Project details
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
Hashes for dj_fine_search-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18b9541999577a68fba998a7689a05928596983b5d7c9a569113ee963f559644 |
|
MD5 | ccaf278d6f07c6ab1cc483ca0ae54b69 |
|
BLAKE2b-256 | bb9a32e23c33f278f4f1cd11f8c441128021c869b4c01abe998cd7fee27becad |