mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-09-19 02:18:25 +08:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user