From b6c2c829b172e4936be48bb2df1298371e7fcbd0 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 6 Mar 2024 16:30:58 +0800 Subject: [PATCH] :art: Database table view in-table search https://github.com/siyuan-note/siyuan/issues/10419 --- kernel/api/av.go | 4 ++-- kernel/model/attribute_view.go | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/kernel/api/av.go b/kernel/api/av.go index 7a14b903f..6d05bc824 100644 --- a/kernel/api/av.go +++ b/kernel/api/av.go @@ -37,8 +37,8 @@ func searchTableView(c *gin.Context) { avID := arg["avID"].(string) viewID := arg["viewID"].(string) - keyword := arg["keyword"].(string) - view, attrView, err := model.SearchTableView(avID, viewID, keyword) + query := arg["query"].(string) + view, attrView, err := model.SearchTableView(avID, viewID, query) if nil != err { ret.Code = -1 ret.Msg = err.Error() diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 6a8daecb6..85353af7f 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -39,7 +39,7 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) -func SearchTableView(avID, viewID, keyword string) (viewable av.Viewable, attrView *av.AttributeView, err error) { +func SearchTableView(avID, viewID, query string) (viewable av.Viewable, attrView *av.AttributeView, err error) { if avJSONPath := av.GetAttributeViewDataPath(avID); !filelock.IsExist(avJSONPath) { attrView = av.NewAttributeView(avID) if err = av.SaveAttributeView(attrView); nil != err { @@ -54,7 +54,28 @@ func SearchTableView(avID, viewID, keyword string) (viewable av.Viewable, attrVi return } + keywords := strings.Split(query, " ") viewable, err = renderAttributeView(attrView, viewID, 1, -1) + var rows []*av.TableRow + switch viewable.GetType() { + case av.LayoutTypeTable: + table := viewable.(*av.Table) + for _, row := range table.Rows { + hit := false + for _, cell := range row.Cells { + for _, keyword := range keywords { + if strings.Contains(strings.ToLower(cell.Value.String()), strings.ToLower(keyword)) { + hit = true + break + } + } + } + if hit { + rows = append(rows, row) + } + } + table.Rows = rows + } return }