Skip to content

feat(search): FTS + trigram GIN indexes for global search#15220

Open
blakeaowens wants to merge 3 commits into
bugfixfrom
feat/global-search
Open

feat(search): FTS + trigram GIN indexes for global search#15220
blakeaowens wants to merge 3 commits into
bugfixfrom
feat/global-search

Conversation

@blakeaowens

@blakeaowens blakeaowens commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Adds the Postgres full-text-search and fuzzy-match GIN indexes that DefectDojo Pro's new global search relies on, so the index scaffolding lives in OSS (built from the ORM) rather than in a Pro-side raw-SQL migration.

What it adds (0278_global_search_fts_trigram_indexes)

  • The pg_trgm extension (TrigramExtension).
  • A weighted tsvector GIN index (title/name weight A, description weight B) on each of the ten searchable models: finding, product, product_type, engagement, test, endpoint, location, finding_template, app_analysis, vulnerability_id.
  • A gin_trgm_ops index on each model's short display column for word-similarity (%> / __trigram_word_similar) fuzzy matching.

Why this shape

  • Built from SearchVector/OpClass ORM objects, not raw SQL, so the index expression tracks the query's compiled SQL across Django upgrades and can't silently drift into a sequential scan.
  • Database-only (SeparateDatabaseAndState with no state operations): these are pure search-performance indexes, not part of any model's public schema, so they stay out of every model's Meta.indexes. makemigrations --check stays clean.
  • atomic = False because CREATE INDEX CONCURRENTLY / CREATE EXTENSION cannot run inside a transaction.
  • Three trigram index names are abbreviated (locval / findtmpl / vuln_id) to fit the 30-char index-name limit.

Adds a weighted tsvector GIN index and a gin_trgm_ops index on the short
display column of the ten models the Pro global search queries (finding,
product, product_type, engagement, test, endpoint, location,
finding_template, app_analysis, vulnerability_id), plus the pg_trgm
extension.

The indexes are built from SearchVector/OpClass ORM objects so the index
expression tracks the query's compiled SQL across Django upgrades, and are
database-only (SeparateDatabaseAndState with no state operations) since
they are search-performance indexes, not part of any model's public
schema. atomic=False because CONCURRENTLY / CREATE EXTENSION cannot run in
a transaction.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added the New Migration Adding a new migration file. Take care when merging. label Jul 10, 2026
blakeaowens and others added 2 commits July 10, 2026 17:46
The 0278 trigram GIN indexes used a django.contrib.postgres OpClass
expression, which renders to invalid SQL ("syntax error at or near
gin_trgm_ops") unless django.contrib.postgres is in INSTALLED_APPS, and it
is not in the OSS standalone settings. Switch to the base Index opclasses
option, which renders the identical `USING gin (col gin_trgm_ops)` SQL
without requiring that app. The tsvector indexes are unaffected
(SearchVector renders without the app).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Move the global-search GIN indexes from a database-only migration into each
model's Meta.indexes (house style, matching the other functional-index
migrations), and register django.contrib.postgres in INSTALLED_APPS so the
SearchVector index expressions and trigram lookups are supported. 0278
becomes a plain AddIndexConcurrently migration matching model state.

Indexes: weighted tsvector FTS + gin_trgm_ops trigram on finding, product,
product_type, engagement, test, endpoint, location, finding_template,
app_analysis, vulnerability_id.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added the settings_changes Needs changes to settings.py based on changes in settings.dist.py included in this PR label Jul 10, 2026
@blakeaowens blakeaowens added this to the 3.1.100 milestone Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

New Migration Adding a new migration file. Take care when merging. settings_changes Needs changes to settings.py based on changes in settings.dist.py included in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant