feat: 增强FAQ搜索功能,支持指定搜索字段(标准问题/相似问法/答案)
This commit is contained in:
@@ -80,6 +80,7 @@ func (r *chunkRepository) ListPagedChunksByKnowledgeID(
|
||||
chunkType []types.ChunkType,
|
||||
tagID string,
|
||||
keyword string,
|
||||
searchField string,
|
||||
sortOrder string,
|
||||
) ([]*types.Chunk, int64, error) {
|
||||
var chunks []*types.Chunk
|
||||
@@ -97,7 +98,20 @@ func (r *chunkRepository) ListPagedChunksByKnowledgeID(
|
||||
}
|
||||
if keyword != "" {
|
||||
like := "%" + keyword + "%"
|
||||
db = db.Where("(content LIKE ? OR metadata::text LIKE ?)", like, like)
|
||||
switch searchField {
|
||||
case "standard_question":
|
||||
// Search only in standard_question field of metadata
|
||||
db = db.Where("metadata->>'standard_question' ILIKE ?", like)
|
||||
case "similar_questions":
|
||||
// Search in similar_questions array of metadata
|
||||
db = db.Where("metadata->'similar_questions'::text ILIKE ?", like)
|
||||
case "answers":
|
||||
// Search in answers array of metadata
|
||||
db = db.Where("metadata->'answers'::text ILIKE ?", like)
|
||||
default:
|
||||
// Search in all fields (content and metadata)
|
||||
db = db.Where("(content ILIKE ? OR metadata::text ILIKE ?)", like, like)
|
||||
}
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
||||
@@ -337,7 +337,7 @@ func (s *agentService) getKnowledgeBaseInfos(ctx context.Context, kbIDs []string
|
||||
pageResult, err := s.knowledgeService.ListFAQEntries(ctx, kbID, &types.Pagination{
|
||||
Page: 1,
|
||||
PageSize: 10,
|
||||
}, "", "", "")
|
||||
}, "", "", "", "")
|
||||
if err == nil && pageResult != nil {
|
||||
docCount = int(pageResult.Total)
|
||||
if entries, ok := pageResult.Data.([]*types.FAQEntry); ok {
|
||||
|
||||
@@ -152,6 +152,7 @@ func (s *chunkService) ListPagedChunksByKnowledgeID(ctx context.Context,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
)
|
||||
if err != nil {
|
||||
logger.ErrorWithFields(ctx, err, map[string]interface{}{
|
||||
|
||||
@@ -2549,6 +2549,7 @@ func (s *knowledgeService) CloneChunk(ctx context.Context, src, dst *types.Knowl
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
)
|
||||
chunkPage++
|
||||
if err != nil {
|
||||
@@ -2643,7 +2644,7 @@ func (s *knowledgeService) CloneChunk(ctx context.Context, src, dst *types.Knowl
|
||||
|
||||
// ListFAQEntries lists FAQ entries under a FAQ knowledge base.
|
||||
func (s *knowledgeService) ListFAQEntries(ctx context.Context,
|
||||
kbID string, page *types.Pagination, tagID string, keyword string, sortOrder string,
|
||||
kbID string, page *types.Pagination, tagID string, keyword string, searchField string, sortOrder string,
|
||||
) (*types.PageResult, error) {
|
||||
if page == nil {
|
||||
page = &types.Pagination{}
|
||||
@@ -2663,7 +2664,7 @@ func (s *knowledgeService) ListFAQEntries(ctx context.Context,
|
||||
}
|
||||
chunkType := []types.ChunkType{types.ChunkTypeFAQ}
|
||||
chunks, total, err := s.chunkRepo.ListPagedChunksByKnowledgeID(
|
||||
ctx, tenantID, faqKnowledge.ID, page, chunkType, tagID, keyword, sortOrder,
|
||||
ctx, tenantID, faqKnowledge.ID, page, chunkType, tagID, keyword, searchField, sortOrder,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user