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:
@@ -5,6 +5,7 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/application/service/retriever"
|
||||
@@ -107,7 +108,9 @@ func (s *chunkService) GetChunkByID(ctx context.Context, id string) (*types.Chun
|
||||
func (s *chunkService) GetChunkByIDOnly(ctx context.Context, id string) (*types.Chunk, error) {
|
||||
chunk, err := s.chunkRepository.GetChunkByIDOnly(ctx, id)
|
||||
if err != nil {
|
||||
if err != nil && err.Error() == "chunk not found" {
|
||||
// errors.Is (not string equality) so the sentinel survives wrapping.
|
||||
// ErrChunkNotFound aliases the repo sentinel, so this matches directly.
|
||||
if errors.Is(err, ErrChunkNotFound) {
|
||||
return nil, ErrChunkNotFound
|
||||
}
|
||||
logger.ErrorWithFields(ctx, err, map[string]interface{}{"chunk_id": id})
|
||||
|
||||
@@ -26,8 +26,11 @@ var (
|
||||
ErrInvalidFileType = errors.New("unsupported file type")
|
||||
// ErrInvalidURL is returned when an invalid URL is provided
|
||||
ErrInvalidURL = errors.New("invalid URL")
|
||||
// ErrChunkNotFound is returned when a requested chunk cannot be found
|
||||
ErrChunkNotFound = errors.New("chunk not found")
|
||||
// ErrChunkNotFound is returned when a requested chunk cannot be found.
|
||||
// Aliases the repository sentinel so a chunk-not-found from the repo
|
||||
// errors.Is-matches at the service and middleware layers (a single
|
||||
// identity instead of two string-equal-but-distinct errors).
|
||||
ErrChunkNotFound = repository.ErrChunkNotFound
|
||||
// ErrDuplicateFile is returned when trying to add a file that already exists
|
||||
ErrDuplicateFile = errors.New("file already exists")
|
||||
// ErrDuplicateURL is returned when trying to add a URL that already exists
|
||||
|
||||
Reference in New Issue
Block a user