fix(makecode): Search 文本字段只走模糊匹配,避免等值叠加导致空结果
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -104,6 +104,46 @@ var AdminDepartmentTest = ProjTest{
|
||||
return nil
|
||||
}).
|
||||
Get("showall加showself含自身与子孙", 0, rowSample)
|
||||
|
||||
// ======== 修复回归:文本字段部分关键词模糊匹配 + 非文本字段等值筛选不受影响 ========
|
||||
// 背景 bug(code/makecode.go Search):文本类字段(如 name)曾同时生成等值条件
|
||||
// name=值 与模糊条件 name[~]=值,二者在 where 中以 AND 叠加;前端筛选框传入
|
||||
// 部分关键词时等值条件必不命中,AND 之后查询恒为空。
|
||||
// 修复后:文本字段只走模糊匹配;非文本字段(如 state,规则覆盖为 select 类型)维持等值匹配现状。
|
||||
textId := a.DB().Insert("department", Map{
|
||||
"name": "综合行政部", "state": 5, "parent_id": nodeX,
|
||||
"create_time[#]": "NOW()", "modify_time[#]": "NOW()",
|
||||
})
|
||||
a.DB().Update("department", Map{"parent_ids": "," + ObjToStr(rootId) + "," + ObjToStr(nodeX) + "," + ObjToStr(textId) + ","}, Map{"id": textId})
|
||||
|
||||
a.WithSession(session).
|
||||
Note("修复前:name 等值(综合行政部≠行政)与模糊[~]同时AND叠加,传部分关键词恒查不到;修复后应命中模糊匹配").
|
||||
Query(Map{"parent_id": rootId, "showself": "1", "showall": "1", "pageSize": "50", "name": "行政"}).
|
||||
Verify(func(a *Api) error {
|
||||
ids := resultIds(a)
|
||||
if !ids[textId] {
|
||||
return fmt.Errorf("文本字段部分关键词模糊查询应命中 id=%d, 实际: %v", textId, ids)
|
||||
}
|
||||
return nil
|
||||
}).
|
||||
Get("文本字段部分关键词命中模糊匹配", 0, rowSample)
|
||||
|
||||
a.WithSession(session).
|
||||
Note("state 规则覆盖为 select 类型(非text),应维持等值匹配现状,只精确命中 state=5 的记录").
|
||||
Query(Map{"parent_id": rootId, "showself": "1", "showall": "1", "pageSize": "50", "state": "5"}).
|
||||
Verify(func(a *Api) error {
|
||||
ids := resultIds(a)
|
||||
if !ids[textId] {
|
||||
return fmt.Errorf("非文本字段等值筛选应命中 id=%d, 实际: %v", textId, ids)
|
||||
}
|
||||
for id := range ids {
|
||||
if id != textId {
|
||||
return fmt.Errorf("非文本字段等值筛选不应包含其它 state 的记录,实际额外命中: id=%d", id)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}).
|
||||
Get("非文本字段等值筛选行为不变", 0, rowSample)
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user