Search for Django and PostgreSQL.
Requirements
Django >= 1.1
django-stringfield >= 0.1.5
django-cerial >= 0.0.2
Installation
First install the package from pypi using pip:
pip install django-pgindex
Then make pgindex an app in your INSTALLED_APPS:
INSTALLED_APPS = (
...
'pgindex',
...
)
Sync your database:
python manage.py syncdb
Done.
Usage
Create and Index class and register it to your model, much like registering an admin class to your model. Example:
# models.py
from django.db import models
from .index import ItemIndex
from pgindex import register
class Item(models.Model):
title = models.CharField(max_length=100)
content = models.TextField()
def get_absolute_url(self):
return '/item/'
register(Item, ItemIndex)
# index.py
from pgindex import IndexBase, Vector
class ItemIndex(IndexBase):
def get_title(self):
return self.obj.title
def get_description(self):
return self.obj.content
def get_vectors(self):
return (
Vector(self.obj.title, weight='A'),
Vector(self.obj.content, weight='B'),
)
To search simply use the pgindex.search method which returns a queryset from the pgindex.models.Index model:
from pgindex import search
index_queryset = search('foo')
See tests for examples.
pgindex.IndexBase methods
get_title()
This should return the title of the indexed object.
get_description()
This should return the description of the indexed object.
get_url()
This should return the url of the indexed object.
get_data()
You can return additional data that will be stored in the index field here, this value will be pickled and depickled.
get_publish()
If this returns False and index will not be created
get_start_publish()
Can return a datetime.datetime which is the time when the index will be used. Returning None means that it will always be used.
get_end_publish()
Can return a datetime.datetime which is the time for the index expiration. Returning None means that it will never expire.
get_vectors()
This method needs to return a list or tuple of pgindex.Vector instances. This in turn is the base for the text search column.
Metadata
Release files for django-pgindex 0.8.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-pgindex-0.8.2.tar.gz | 7.0 kB | Without provenance | Details |
Release files / django-pgindex-0.8.2.tar.gz
| Download URL | django-pgindex-0.8.2.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
77ea16c55deaf07e3ef53b8577b824b53cecd4fa90bc41dc8ac078d5faad58df
|
|
BLAKE2b-256 checksum How to use checksums |
9ae07534fbdc6d51e6ba67026c543860e88ad88fc08017eb49d29a38563b16ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-pgindex 0.8.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.