Easy FTS with Django and PostgreSQL
Project description
Django Searchable
==============
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 :code:`SearchableModel` class, and use the :code:`SearchableTextField` class to automatically setup full text search:
.. code-block:: python
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:
.. code-block:: python
# 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)
:code:`.search` adds a :code:`rank` annotation and automatically filters and sorts the resulting queryset.
By default, :code:`.search` will search through all :code:`SearchableTextField` fields on the model, but you can specify any subset:
.. code-block:: python
results = Blog.objects.search('who is venom', fields=['title'])
Contributing
--------------
.. code-block:: python
pipenv install --dev
createuser -s -P test_user # use 'password'
pipenv run ./manage.py test
==============
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 :code:`SearchableModel` class, and use the :code:`SearchableTextField` class to automatically setup full text search:
.. code-block:: python
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:
.. code-block:: python
# 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)
:code:`.search` adds a :code:`rank` annotation and automatically filters and sorts the resulting queryset.
By default, :code:`.search` will search through all :code:`SearchableTextField` fields on the model, but you can specify any subset:
.. code-block:: python
results = Blog.objects.search('who is venom', fields=['title'])
Contributing
--------------
.. code-block:: python
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
django_searchable-0.1.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for django_searchable-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07c7e9ad1a54c5781f344f24dde4ca7ac8701da17f128bec769e6dd5fb6184f8 |
|
MD5 | b678fb2320508dbe21df134514140414 |
|
BLAKE2b-256 | 5a77213779b266006cc5ebc933f006a3def4491dab6dce2de09d0225fc75650b |