Refacto document filter

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-08-05 10:48:55 +02:00
parent 7e59504462
commit 036970afdd

View File

@@ -39,40 +39,28 @@ func NewDocumentTrustCenterFilter() *DocumentFilter {
} }
func (f *DocumentFilter) SQLArguments() pgx.StrictNamedArgs { func (f *DocumentFilter) SQLArguments() pgx.StrictNamedArgs {
args := pgx.StrictNamedArgs{} return pgx.StrictNamedArgs{
"query": f.query,
if f.query != nil { "show_on_trust_center": f.showOnTrustCenter,
args["query"] = *f.query
} else {
args["query"] = (*string)(nil)
} }
if f.showOnTrustCenter != nil {
args["show_on_trust_center"] = *f.showOnTrustCenter
} else {
args["show_on_trust_center"] = (*bool)(nil)
}
return args
} }
func (f *DocumentFilter) SQLFragment() string { func (f *DocumentFilter) SQLFragment() string {
sql := `( return `
CASE (
WHEN @query::text IS NOT NULL AND @query::text != '' THEN CASE
search_vector @@ ( WHEN @query::text IS NOT NULL AND @query::text != '' THEN
SELECT to_tsquery('simple', string_agg(lexeme || ':*', ' & ')) search_vector @@ (
FROM unnest(regexp_split_to_array(trim(@query::text), '\s+')) AS lexeme SELECT to_tsquery('simple', string_agg(lexeme || ':*', ' & '))
) FROM unnest(regexp_split_to_array(trim(@query::text), '\s+')) AS lexeme
ELSE TRUE )
END ELSE TRUE
AND END
CASE AND
WHEN @show_on_trust_center::boolean IS NOT NULL THEN CASE
show_on_trust_center = @show_on_trust_center::boolean WHEN @show_on_trust_center::boolean IS NOT NULL THEN
ELSE TRUE show_on_trust_center = @show_on_trust_center::boolean
END ELSE TRUE
)` END
)`
return sql
} }