Skip to content

Commit ceb00ee

Browse files
bobodayeliubo-0801
andauthored
Fix global search edit err branch (#1034)
* 在函数开头添加输入元素检测,当焦点在输入框、textarea、select 或可编辑元素中时,直接返回不执行快捷键操作 * feat: 支持 Cherry Markdown 阅读页目录滚动功能 - 为 Cherry 编辑器阅读模式的目录添加最大高度限制 - 当目录过长时支持垂直滚动查看后续条目 - 使用 calc(100vh - 180px) 动态计算合适的滚动容器高度 - 启用 webkit 平滑滚动以改善移动端体验 * feat: 重构倒排索引搜索流程并新增全量重建命令 1. 搜索流程重构:倒排索引搜索改为先取候选、统一加权排序后再分页,避免高相关结果被提前截断 2. 排序算法优化:重构 TF-IDF 计算并加入标题命中、正文精确匹配和查询词覆盖率 boost,提升搜索准确度 3. 性能与权限优化:搜索结果改为批量回表加载并统一过滤项目权限,减少逐条查询开销 4. 索引构建与维护改进:统一按“标题 + 正文”建立索引,补充空内容占位索引,并新增 `mindoc reindex` 全量重建命令 5. 其他搜索优化:传统 SQL 搜索增加标题相关性排序,分词器增加停用词/术语过滤,并为索引查询补充表名校验 * fix(document): preserve edit target from read view and prioritize explicit selection in editor init * fix(search): whitelist technical terms to avoid filtering Linux/command keywords in search * 优化文档阅读页面易用性 - Ctrl+F 不再被拦截,放行浏览器原生页面内搜索 - ESC 关闭搜索面板在输入框焦点状态下也生效 --------- Co-authored-by: 11187243 <bo61.liu@tcl.com>
1 parent 6137987 commit ceb00ee

18 files changed

+950
-236
lines changed

commands/command.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,23 @@ func RegisterCommand() {
237237
} else if len(os.Args) >= 2 && os.Args[1] == "update" {
238238
Update()
239239
os.Exit(0)
240+
} else if len(os.Args) >= 2 && os.Args[1] == "reindex" {
241+
ResolveCommand(os.Args[2:])
242+
fmt.Println("开始全量重建倒排索引...")
243+
if err := models.RebuildAllIndexes(); err != nil {
244+
fmt.Println("倒排索引重建失败,索引表可能处于部分重建状态,请重新执行 reindex:", err)
245+
os.Exit(1)
246+
}
247+
fmt.Println("倒排索引重建完成")
248+
os.Exit(0)
240249
}
241250

242251
}
243252

253+
func shouldInitializeMissingIndexes() bool {
254+
return !(len(os.Args) >= 2 && os.Args[1] == "reindex")
255+
}
256+
244257
// 注册模板函数
245258
func RegisterFunction() {
246259
err := web.AddFuncMap("config", models.GetOptionValue)
@@ -425,7 +438,9 @@ func ResolveCommand(args []string) {
425438
RegisterCache()
426439
RegisterModel()
427440
RegisterLogger(conf.LogFile)
428-
models.InitializeMissingIndexes()
441+
if shouldInitializeMissingIndexes() {
442+
models.InitializeMissingIndexes()
443+
}
429444

430445
ModifyPassword()
431446
}

controllers/DocumentController.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,33 @@ func Flatten(list []*models.DocumentTree, flattened *[]DocumentTreeFlatten) {
324324
return
325325
}
326326

327+
func (c *DocumentController) resolveEditDocument(bookId int, id string) (*models.Document, error) {
328+
id = strings.TrimSpace(id)
329+
if id == "" {
330+
return nil, nil
331+
}
332+
333+
doc := models.NewDocument()
334+
if docId, err := strconv.Atoi(id); err == nil {
335+
doc, err = doc.FromCacheById(docId)
336+
if err != nil {
337+
return nil, err
338+
}
339+
} else {
340+
var err error
341+
doc, err = doc.FromCacheByIdentify(id, bookId)
342+
if err != nil {
343+
return nil, err
344+
}
345+
}
346+
347+
if doc == nil || doc.DocumentId <= 0 || doc.BookId != bookId {
348+
return nil, orm.ErrNoRows
349+
}
350+
351+
return doc, nil
352+
}
353+
327354
// 编辑文档
328355
func (c *DocumentController) Edit() {
329356
c.Prepare()
@@ -396,6 +423,21 @@ func (c *DocumentController) Edit() {
396423
} else {
397424
c.Data["UploadFileSize"] = "undefined"
398425
}
426+
427+
selectedDocId := 0
428+
if doc, err := c.resolveEditDocument(bookResult.BookId, c.Ctx.Input.Param(":id")); err != nil {
429+
if err == orm.ErrNoRows || err == models.ErrDataNotExist {
430+
c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.doc_not_exist"))
431+
} else {
432+
logs.Error("resolveEditDocument => ", err)
433+
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.system_error"))
434+
}
435+
return
436+
} else if doc != nil {
437+
selectedDocId = doc.DocumentId
438+
}
439+
440+
c.Data["SelectedDocId"] = selectedDocId
399441
}
400442

401443
// 创建一个文档

0 commit comments

Comments
 (0)