From 069ff4aa9af1283f5d8309eef911786a06f712b9 Mon Sep 17 00:00:00 2001 From: Sacha Al Himdani Date: Tue, 10 Jun 2025 10:43:05 -0700 Subject: [PATCH] Fix search queries Signed-off-by: Sacha Al Himdani --- pkg/coredata/control_filter.go | 7 ++++++- pkg/coredata/document.go | 1 + pkg/coredata/document_filter.go | 7 ++++++- pkg/coredata/measure.go | 1 + pkg/coredata/measure_filter.go | 7 ++++++- pkg/coredata/risk.go | 1 + pkg/coredata/risk_filter.go | 7 ++++++- 7 files changed, 27 insertions(+), 4 deletions(-) diff --git a/pkg/coredata/control_filter.go b/pkg/coredata/control_filter.go index 5d0ed2eeb..66f91287a 100644 --- a/pkg/coredata/control_filter.go +++ b/pkg/coredata/control_filter.go @@ -41,5 +41,10 @@ func (f *ControlFilter) SQLFragment() string { return "TRUE" } - return "search_vector @@ websearch_to_tsquery('simple', @query)" + return ` + search_vector @@ ( + SELECT to_tsquery('simple', string_agg(lexeme || ':*', ' & ')) + FROM unnest(regexp_split_to_array(trim(@query), '\s+')) AS lexeme + ) + ` } diff --git a/pkg/coredata/document.go b/pkg/coredata/document.go index 193006df3..52c589735 100644 --- a/pkg/coredata/document.go +++ b/pkg/coredata/document.go @@ -333,6 +333,7 @@ WITH plcs AS ( SELECT p.id, p.tenant_id, + p.search_vector, p.organization_id, p.owner_id, p.title, diff --git a/pkg/coredata/document_filter.go b/pkg/coredata/document_filter.go index 6e4eb6715..569534670 100644 --- a/pkg/coredata/document_filter.go +++ b/pkg/coredata/document_filter.go @@ -41,5 +41,10 @@ func (f *DocumentFilter) SQLFragment() string { return "TRUE" } - return "search_vector @@ websearch_to_tsquery('simple', @query)" + return ` + search_vector @@ ( + SELECT to_tsquery('simple', string_agg(lexeme || ':*', ' & ')) + FROM unnest(regexp_split_to_array(trim(@query), '\s+')) AS lexeme + ) + ` } diff --git a/pkg/coredata/measure.go b/pkg/coredata/measure.go index bd477b889..26b925a44 100644 --- a/pkg/coredata/measure.go +++ b/pkg/coredata/measure.go @@ -219,6 +219,7 @@ WITH mtgtns AS ( m.description, m.state, m.reference_id, + m.search_vector, m.created_at, m.updated_at FROM diff --git a/pkg/coredata/measure_filter.go b/pkg/coredata/measure_filter.go index 7a5741518..fa6e0cce9 100644 --- a/pkg/coredata/measure_filter.go +++ b/pkg/coredata/measure_filter.go @@ -41,5 +41,10 @@ func (f *MeasureFilter) SQLFragment() string { return "TRUE" } - return "search_vector @@ websearch_to_tsquery('simple', @query)" + return ` + search_vector @@ ( + SELECT to_tsquery('simple', string_agg(lexeme || ':*', ' & ')) + FROM unnest(regexp_split_to_array(trim(@query), '\s+')) AS lexeme + ) + ` } diff --git a/pkg/coredata/risk.go b/pkg/coredata/risk.go index d58d01ecd..112d7bb1e 100644 --- a/pkg/coredata/risk.go +++ b/pkg/coredata/risk.go @@ -135,6 +135,7 @@ WITH rsks AS ( r.residual_likelihood, r.residual_impact, r.residual_risk_score, + r.search_vector, r.created_at, r.updated_at FROM diff --git a/pkg/coredata/risk_filter.go b/pkg/coredata/risk_filter.go index 35c8b1787..0017b7266 100644 --- a/pkg/coredata/risk_filter.go +++ b/pkg/coredata/risk_filter.go @@ -41,5 +41,10 @@ func (f *RiskFilter) SQLFragment() string { return "TRUE" } - return "search_vector @@ websearch_to_tsquery('simple', @query)" + return ` + search_vector @@ ( + SELECT to_tsquery('simple', string_agg(lexeme || ':*', ' & ')) + FROM unnest(regexp_split_to_array(trim(@query), '\s+')) AS lexeme + ) + ` }