Move document search_vector from documents to document_versions
Now that title lives on document_versions, the full-text search vector belongs there too. Drop the generated column and GIN index from documents, recreate them on document_versions, and update the document filter to query the latest version's search_vector. Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -131,7 +131,13 @@ func (f *DocumentFilter) SQLFragment() string {
|
|||||||
(
|
(
|
||||||
CASE
|
CASE
|
||||||
WHEN @query::text IS NOT NULL AND @query::text != '' THEN
|
WHEN @query::text IS NOT NULL AND @query::text != '' THEN
|
||||||
search_vector @@ (
|
(
|
||||||
|
SELECT dv.search_vector
|
||||||
|
FROM document_versions dv
|
||||||
|
WHERE dv.document_id = documents.id
|
||||||
|
ORDER BY dv.major DESC, dv.minor DESC
|
||||||
|
LIMIT 1
|
||||||
|
) @@ (
|
||||||
SELECT to_tsquery('simple', string_agg(lexeme || ':*', ' & '))
|
SELECT to_tsquery('simple', string_agg(lexeme || ':*', ' & '))
|
||||||
FROM unnest(regexp_split_to_array(trim(@query::text), '\s+')) AS lexeme
|
FROM unnest(regexp_split_to_array(trim(@query::text), '\s+')) AS lexeme
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -16,3 +16,14 @@
|
|||||||
ALTER TABLE documents ALTER COLUMN title DROP NOT NULL;
|
ALTER TABLE documents ALTER COLUMN title DROP NOT NULL;
|
||||||
|
|
||||||
ALTER TABLE documents DROP COLUMN description;
|
ALTER TABLE documents DROP COLUMN description;
|
||||||
|
|
||||||
|
-- Move search_vector from documents to document_versions.
|
||||||
|
DROP INDEX documents_search_idx;
|
||||||
|
ALTER TABLE documents DROP COLUMN search_vector;
|
||||||
|
|
||||||
|
ALTER TABLE document_versions ADD COLUMN search_vector tsvector
|
||||||
|
GENERATED ALWAYS AS (
|
||||||
|
to_tsvector('simple', COALESCE(title, ''))
|
||||||
|
) STORED;
|
||||||
|
|
||||||
|
CREATE INDEX document_versions_search_idx ON document_versions USING gin(search_vector);
|
||||||
|
|||||||
Reference in New Issue
Block a user