|
10 | 10 | from dateutil.parser import parse as datetutilsparse |
11 | 11 | from dateutil.relativedelta import relativedelta |
12 | 12 | from django.conf import settings |
| 13 | +from django.contrib.postgres.indexes import GinIndex |
| 14 | +from django.contrib.postgres.search import SearchVector |
13 | 15 | from django.core.validators import MaxValueValidator, MinValueValidator |
14 | 16 | from django.db import models |
15 | 17 | from django.urls import reverse |
@@ -441,6 +443,14 @@ class Finding(BaseModel): |
441 | 443 | class Meta: |
442 | 444 | ordering = ("numerical_severity", "-date", "title", "epss_score", "epss_percentile") |
443 | 445 | indexes = [ |
| 446 | + # Global search (pro/search/): weighted tsvector FTS + trigram fuzzy match. |
| 447 | + GinIndex( |
| 448 | + SearchVector("title", weight="A", config="english") |
| 449 | + + SearchVector("description", weight="B", config="english"), |
| 450 | + name="dojo_finding_fts_gin", |
| 451 | + ), |
| 452 | + GinIndex(fields=["title"], opclasses=["gin_trgm_ops"], name="dojo_finding_title_trgm"), |
| 453 | + |
444 | 454 | models.Index(fields=["test", "active", "verified"]), |
445 | 455 |
|
446 | 456 | models.Index(fields=["test", "is_mitigated"]), |
@@ -1367,6 +1377,16 @@ class Vulnerability_Id(models.Model): |
1367 | 1377 | finding = models.ForeignKey("dojo.Finding", editable=False, on_delete=models.CASCADE) |
1368 | 1378 | vulnerability_id = models.TextField(max_length=50, blank=False, null=False) |
1369 | 1379 |
|
| 1380 | + class Meta: |
| 1381 | + indexes = [ |
| 1382 | + # Global search (pro/search/): weighted tsvector FTS + trigram fuzzy match. |
| 1383 | + GinIndex( |
| 1384 | + SearchVector("vulnerability_id", weight="A", config="english"), |
| 1385 | + name="dojo_vulnerability_id_fts_gin", |
| 1386 | + ), |
| 1387 | + GinIndex(fields=["vulnerability_id"], opclasses=["gin_trgm_ops"], name="dojo_vuln_id_trgm"), |
| 1388 | + ] |
| 1389 | + |
1370 | 1390 | def __str__(self): |
1371 | 1391 | return self.vulnerability_id |
1372 | 1392 |
|
@@ -1506,6 +1526,15 @@ class Finding_Template(models.Model): |
1506 | 1526 |
|
1507 | 1527 | class Meta: |
1508 | 1528 | ordering = ["-cwe"] |
| 1529 | + indexes = [ |
| 1530 | + # Global search (pro/search/): weighted tsvector FTS + trigram fuzzy match. |
| 1531 | + GinIndex( |
| 1532 | + SearchVector("title", weight="A", config="english") |
| 1533 | + + SearchVector("description", weight="B", config="english"), |
| 1534 | + name="dojo_finding_template_fts_gin", |
| 1535 | + ), |
| 1536 | + GinIndex(fields=["title"], opclasses=["gin_trgm_ops"], name="dojo_findtmpl_title_trgm"), |
| 1537 | + ] |
1509 | 1538 |
|
1510 | 1539 | def __str__(self): |
1511 | 1540 | return self.title |
|
0 commit comments