fix(server): case-insensitive doc keyword search + not-found classification

Make document keyword search case-insensitive (LOWER(...) LIKE LOWER(?)) in the
list filter and SearchKnowledge / SearchKnowledgeInScopes paths so a query and
its differently-cased variant return the same results.

Classify not-found consistently as HTTP 404 (not 500) so clients read a
permanent resource.not_found instead of a retryable 5xx: map the document /
chunk not-found sentinels in the KB-access middleware (typed ErrChunkNotFound
via errors.Is), and return 404 for a missing message on the continue-stream and
message-delete endpoints.
This commit is contained in:
nullkey
2026-06-26 20:40:59 +08:00
committed by lyingbug
parent 8f36ea2229
commit 445a4330fa
8 changed files with 77 additions and 20 deletions
+6 -3
View File
@@ -3,7 +3,6 @@ package middleware
import (
"context"
stderrors "errors"
"strings"
apprepo "github.com/Tencent/WeKnora/internal/application/repository"
"github.com/Tencent/WeKnora/internal/config"
@@ -190,9 +189,13 @@ func KBIDFromChunkIDParam(param string, chunkService ChunkLookup) KBIDResolver {
// from forcing every service to standardise on a single error type
// before this refactor is useful.
func isResourceNotFound(err error) bool {
// ErrChunkNotFound is defined in the repository layer and aliased by the
// service; match the canonical repo sentinel so this predicate depends
// only on the repository package (KB / Knowledge / Chunk are all here).
return stderrors.Is(err, apprepo.ErrKnowledgeBaseNotFound) ||
stderrors.Is(err, ErrResourceNotFound) ||
strings.TrimSpace(err.Error()) == "chunk not found"
stderrors.Is(err, apprepo.ErrKnowledgeNotFound) ||
stderrors.Is(err, apprepo.ErrChunkNotFound) ||
stderrors.Is(err, ErrResourceNotFound)
}
// RequireKBAccess returns a gin.HandlerFunc that resolves KB access