1
0
Fork 0

Limit full-text search indexation to first 500K characters

tsvector has a size limit of 1MB. See https://www.postgresql.org/docs/13/textsearch-limitations.html

Input text is now truncated to avoid this error:

"pq: string is too long for tsvector (1057834 bytes, max 1048575 bytes)"
This commit is contained in:
Frédéric Guillot 2021-02-06 14:01:41 -08:00 committed by fguillot
parent 89d17107af
commit 9a9a271b1f

View file

@ -89,7 +89,7 @@ func (s *Storage) UpdateEntryContent(entry *model.Entry) error {
UPDATE UPDATE
entries entries
SET SET
document_vectors = setweight(to_tsvector(substring(coalesce(title, '') for 1000000)), 'A') || setweight(to_tsvector(substring(coalesce(content, '') for 1000000)), 'B') document_vectors = setweight(to_tsvector(left(coalesce(title, ''), 500000)), 'A') || setweight(to_tsvector(left(coalesce(content, ''), 500000)), 'B')
WHERE WHERE
id=$1 AND user_id=$2 id=$1 AND user_id=$2
` `
@ -133,7 +133,7 @@ func (s *Storage) createEntry(tx *sql.Tx, entry *model.Entry) error {
$9, $9,
$10, $10,
now(), now(),
setweight(to_tsvector(substring(coalesce($1, '') for 1000000)), 'A') || setweight(to_tsvector(substring(coalesce($6, '') for 1000000)), 'B') setweight(to_tsvector(left(coalesce($1, ''), 500000)), 'A') || setweight(to_tsvector(left(coalesce($6, ''), 500000)), 'B')
) )
RETURNING RETURNING
id, status id, status
@ -182,7 +182,7 @@ func (s *Storage) updateEntry(tx *sql.Tx, entry *model.Entry) error {
content=$4, content=$4,
author=$5, author=$5,
reading_time=$6, reading_time=$6,
document_vectors = setweight(to_tsvector(substring(coalesce($1, '') for 1000000)), 'A') || setweight(to_tsvector(substring(coalesce($4, '') for 1000000)), 'B') document_vectors = setweight(to_tsvector(left(coalesce($1, ''), 500000)), 'A') || setweight(to_tsvector(left(coalesce($4, ''), 500000)), 'B')
WHERE WHERE
user_id=$7 AND feed_id=$8 AND hash=$9 user_id=$7 AND feed_id=$8 AND hash=$9
RETURNING RETURNING