Easy FTS with Django and PostgreSQL
Project description
Easy full text search with Django and PostgreSQL. Sane defaults + auto creation of vector fields, indexes, and database triggers.
Example
Extend your model with the SearchableModel
class, and use the SearchableTextField
class to automatically setup full text search:
from django.db.models import TextField
from django_searchable.models import SearchableModel, SearchableTextField
class Blog(SearchableModel):
author_name = TextField() # will NOT have FTS setup automatically
title = SearchableTextField() # will have FTS setup automatically
text = SearchableTextField() # will have FTS setup automatically
Then search away via the Blog manager:
# takes a string of space separated terms
results = Blog.objects.search('spiderman suits')
# or a list of terms
results = Blog.objects.search(['water', 'baskets', 'leaking'])
# or a SearchQuery object
from django.contrib.postgres.search import SearchQuery
query = ~SearchQuery('superman') & SearchQuery('batman')
results = Blog.objects.search(query)
.search
adds a rank
annotation and automatically filters and sorts the resulting queryset.
By default, .search
will search through all SearchableTextField
fields on the model, but you can specify any subset:
results = Blog.objects.search('who is venom', fields=['title'])
Contributing
pipenv install --dev
createuser -s -P test_user # use 'password'
pipenv run ./manage.py test
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
Close
Hashes for django_searchable-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2d4c1943fe31a48761eeacd7f4df002c5b11a6613764b9d66dff9e67d12a805 |
|
MD5 | b93a729eb79aebcfc40fcfc1dbf857f2 |
|
BLAKE2b-256 | 68af45847a4c660ffe814ad5466ff77fc55aa996daa0b5eaee13de5d0dae506a |