结构更新

This commit is contained in:
2025-08-12 17:06:48 +08:00
parent c383af752f
commit eb5a502d67
6 changed files with 21 additions and 20 deletions

View File

@@ -10,7 +10,7 @@ import (
// InsertDocument 插入单条文档到索引
func InsertDocument(c *gin.Context) {
// 检查索引是否初始化
if globalIndex == nil {
if GlobalIndex == nil {
c.JSON(500, gin.H{"error": "索引未初始化"})
return
}
@@ -23,15 +23,15 @@ func InsertDocument(c *gin.Context) {
}
// 验证文档必填字段
if doc.Title == "" && doc.Body == "" {
c.JSON(400, gin.H{"error": "文档ID不能为空且标题和内容不能同时为空"})
if doc.Title == "" && doc.Content == "" && doc.AuthorId == "" {
c.JSON(400, gin.H{"error": "用户ID不能为空且标题和内容不能同时为空"})
return
}
docID := uuid.New().String()
// 将文档插入索引
if err := globalIndex.Index(docID, doc); err != nil {
if err := GlobalIndex.Index(docID, doc); err != nil {
log.Printf("插入文档失败: %v", err)
c.JSON(500, gin.H{"error": "插入文档到索引失败: " + err.Error()})
return