Skip to main content

A PostgreSQL Full Text Seach Backend for Haystack

Project description

postgres-fts-backend

A Django Haystack backend that uses PostgreSQL's built-in full-text search. No external search service required.

Requirements

  • Python >= 3.12
  • Django >= 5.0
  • django-haystack >= 2.8.0
  • PostgreSQL

Installation

pip install postgres-fts-backend

Add to INSTALLED_APPS:

INSTALLED_APPS = [
    "django.contrib.postgres",
    "haystack",
    "postgres_fts_backend",
    # ...
]

Set a migration module so the generated search index migrations live in your project rather than inside the installed package:

MIGRATION_MODULES = {
    "postgres_fts_backend": "myapp.search_migrations",
}

Configure Haystack:

HAYSTACK_CONNECTIONS = {
    "default": {
        "ENGINE": "postgres_fts_backend.PostgresFTSEngine",
    },
}

To use a search configuration other than "english":

HAYSTACK_CONNECTIONS = {
    "default": {
        "ENGINE": "postgres_fts_backend.PostgresFTSEngine",
        "SEARCH_CONFIG": "spanish",
    },
}

Other Peculiarities of this backend

Build indexes through models and migrations

python manage.py build_postgres_schema
python manage.py migrate postgres_fts_backend

Run these two commands again whenever you change a SearchIndex definition.

Fuzzy search

Fuzzy queries use PostgreSQL's trigram similarity matching (pg_trgm):

results = SearchQuerySet().filter(author__fuzzy="Janee")

The similarity threshold is controlled by PostgreSQL's pg_trgm.similarity_threshold setting (default 0.3). To adjust it:

ALTER DATABASE mydb SET pg_trgm.similarity_threshold = 0.5;

more_like_this not implemented

PostgreSQL FTS doesn't provide any facilities for this. It could be done, but I just need to think more about it.

spelling_suggestions are not supported

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

postgres_fts_backend-0.0.9.tar.gz (39.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

postgres_fts_backend-0.0.9-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file postgres_fts_backend-0.0.9.tar.gz.

File metadata

  • Download URL: postgres_fts_backend-0.0.9.tar.gz
  • Upload date:
  • Size: 39.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for postgres_fts_backend-0.0.9.tar.gz
Algorithm Hash digest
SHA256 d734930bbedfe05b2b09c0e6c79f8ae3ae1783a17d1596ebf9f9ccc4ada06d5c
MD5 6b016231b1429ab1e0c4543da7ad19ca
BLAKE2b-256 5249aa17a21bc635458c2aeb1fa0f7ba63ba6a0eeab5cb406d1a55c628b8f069

See more details on using hashes here.

Provenance

The following attestation bundles were made for postgres_fts_backend-0.0.9.tar.gz:

Publisher: release.yml on fgregg/postgres-fts-backend

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file postgres_fts_backend-0.0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for postgres_fts_backend-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 c22fc7b8d07e85756dda044686e15aebf600aca82e6f2c1d8ffe7d3ee7c8ce02
MD5 ecfcaef3ff8aecc4fd5b7f555177eeed
BLAKE2b-256 b13623529bce0fdaf05e576c6713ca69a0c2131e3ca7d3c3f9a0a22c51c4ceb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for postgres_fts_backend-0.0.9-py3-none-any.whl:

Publisher: release.yml on fgregg/postgres-fts-backend

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page