fix(search): fix parameter type error for single-word queries

Only allocate per-term SQL parameters when there are multiple search
terms. For single-word queries, the phrase parameter already covers
the search — unused term params caused PostgreSQL error
"could not determine data type of parameter $3".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jiayuan Zhang
2026-04-10 02:32:45 +08:00
parent fff3a397c9
commit 1086bc78b9

View File

@@ -242,14 +242,14 @@ func buildSearchQuery(phrase string, terms []string, queryNum int, hasNum bool,
wsParam := nextArg(nil) // $2 — workspace_id, will be filled by caller position
// Build per-term ILIKE conditions for multi-word search.
// Each term must match somewhere in title, description, or comments.
var escapedTerms []string
// Build per-term ILIKE conditions only for multi-word search.
// For single-word queries, the phrase parameter already covers the term.
var termParams []string
for _, t := range terms {
et := escapeLike(t)
escapedTerms = append(escapedTerms, et)
termParams = append(termParams, nextArg(et))
if len(terms) > 1 {
for _, t := range terms {
et := escapeLike(t)
termParams = append(termParams, nextArg(et))
}
}
// --- WHERE clause ---