fix(faq): correct PostgreSQL cast precedence in FAQ search

`metadata->'similar_questions'::text` parses as
`metadata -> ('similar_questions'::text)` because `::` binds tighter
than `->`, so the expression yields jsonb instead of text. ILIKE on
jsonb then fails with "operator does not exist: jsonb ~~* unknown",
returning 1007 Internal server error for `search_field=similar_questions`
and `search_field=answers`. The `standard_question` branch was unaffected
because it uses `->>` (text) directly.

Wrap the json access in parens so the cast applies to the extracted
value: `(metadata->'similar_questions')::text ILIKE ?`. The MySQL
branch uses JSON_EXTRACT and is unchanged.

Fixes #1264
This commit is contained in:
nullkey
2026-05-12 16:42:21 +08:00
committed by lyingbug
parent d199628701
commit 4ed7b90eac
+2 -2
View File
@@ -193,14 +193,14 @@ func (r *chunkRepository) ListPagedChunksByKnowledgeID(
case "similar_questions":
// Search in similar_questions array of metadata
if isPostgres {
db = db.Where("metadata->'similar_questions'::text ILIKE ?", like)
db = db.Where("(metadata->'similar_questions')::text ILIKE ?", like)
} else {
db = db.Where("JSON_EXTRACT(metadata, '$.similar_questions') LIKE ?", like)
}
case "answers":
// Search in answers array of metadata
if isPostgres {
db = db.Where("metadata->'answers'::text ILIKE ?", like)
db = db.Where("(metadata->'answers')::text ILIKE ?", like)
} else {
db = db.Where("JSON_EXTRACT(metadata, '$.answers') LIKE ?", like)
}