This commit is contained in:
Daniel 2025-08-26 22:13:22 +08:00
parent d684bb41b1
commit dcefed26eb
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -1263,7 +1263,12 @@ func SearchAttributeView(keyword string, excludeAvIDs []string) (ret []*AvSearch
logging.LogErrorf("read directory [%s] failed: %s", avDir, err) logging.LogErrorf("read directory [%s] failed: %s", avDir, err)
return return
} }
avBlockRels := av.GetBlockRels() avBlockRels := av.GetBlockRels()
if 1 > len(avBlockRels) {
return
}
for _, entry := range entries { for _, entry := range entries {
if entry.IsDir() { if entry.IsDir() {
continue continue
@ -1322,48 +1327,29 @@ func SearchAttributeView(keyword string, excludeAvIDs []string) (ret []*AvSearch
if 12 <= len(avSearchTmpResults) { if 12 <= len(avSearchTmpResults) {
avSearchTmpResults = avSearchTmpResults[:12] avSearchTmpResults = avSearchTmpResults[:12]
} }
var avIDs []string
for _, a := range avSearchTmpResults {
avIDs = append(avIDs, a.AvID)
}
var blockIDs []string for _, tmpResult := range avSearchTmpResults {
for _, bIDs := range avBlockRels { bIDs := avBlockRels[tmpResult.AvID]
blockIDs = append(blockIDs, bIDs...) var node *ast.Node
} for _, bID := range bIDs {
blockIDs = gulu.Str.RemoveDuplicatedElem(blockIDs) tree, _ := LoadTreeByBlockID(bID)
trees := filesys.LoadTrees(blockIDs)
hitAttrViews := map[string]bool{}
for _, blockID := range blockIDs {
tree := trees[blockID]
if nil == tree { if nil == tree {
continue continue
} }
node := treenode.GetNodeInTree(tree, blockID) node = treenode.GetNodeInTree(tree, bID)
if nil == node || "" == node.AttributeViewID { if nil == node || "" == node.AttributeViewID {
continue continue
} }
avID := node.AttributeViewID
var existAv *AvSearchTempResult
for _, tmpResult := range avSearchTmpResults {
if tmpResult.AvID == avID {
existAv = tmpResult
break break
} }
}
if nil == existAv || gulu.Str.Contains(avID, excludeAvIDs) { if nil == node {
continue continue
} }
if hitAttrViews[avID] { attrView, _ := av.ParseAttributeView(tmpResult.AvID)
continue
}
hitAttrViews[avID] = true
attrView, _ := av.ParseAttributeView(avID)
if nil == attrView { if nil == attrView {
continue continue
} }
@ -1378,27 +1364,27 @@ func SearchAttributeView(keyword string, excludeAvIDs []string) (ret []*AvSearch
hPath = box.Name + hPath hPath = box.Name + hPath
} }
name := existAv.AvName name := tmpResult.AvName
if "" == name { if "" == name {
name = Conf.language(267) name = Conf.language(267)
} }
parent := &AvSearchResult{ parent := &AvSearchResult{
AvID: avID, AvID: tmpResult.AvID,
AvName: existAv.AvName, AvName: tmpResult.AvName,
BlockID: blockID, BlockID: node.ID,
HPath: hPath, HPath: hPath,
} }
ret = append(ret, parent) ret = append(ret, parent)
for _, view := range attrView.Views { for _, view := range attrView.Views {
child := &AvSearchResult{ child := &AvSearchResult{
AvID: avID, AvID: tmpResult.AvID,
AvName: existAv.AvName, AvName: tmpResult.AvName,
ViewName: view.Name, ViewName: view.Name,
ViewID: view.ID, ViewID: view.ID,
ViewLayout: view.LayoutType, ViewLayout: view.LayoutType,
BlockID: blockID, BlockID: node.ID,
HPath: hPath, HPath: hPath,
} }
parent.Children = append(parent.Children, child) parent.Children = append(parent.Children, child)