|
@@ -17,7 +17,6 @@
|
|
package model
|
|
package model
|
|
|
|
|
|
import (
|
|
import (
|
|
- "bytes"
|
|
|
|
"errors"
|
|
"errors"
|
|
"fmt"
|
|
"fmt"
|
|
"io/fs"
|
|
"io/fs"
|
|
@@ -442,163 +441,6 @@ func ListDocTree(boxID, listPath string, sortMode int, flashcard, showHidden boo
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-func ContentStat(content string) (ret *util.BlockStatResult) {
|
|
|
|
- luteEngine := util.NewLute()
|
|
|
|
- return contentStat(content, luteEngine)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func contentStat(content string, luteEngine *lute.Lute) (ret *util.BlockStatResult) {
|
|
|
|
- tree := luteEngine.BlockDOM2Tree(content)
|
|
|
|
- runeCnt, wordCnt, linkCnt, imgCnt, refCnt := tree.Root.Stat()
|
|
|
|
- return &util.BlockStatResult{
|
|
|
|
- RuneCount: runeCnt,
|
|
|
|
- WordCount: wordCnt,
|
|
|
|
- LinkCount: linkCnt,
|
|
|
|
- ImageCount: imgCnt,
|
|
|
|
- RefCount: refCnt,
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func BlocksWordCount(ids []string) (ret *util.BlockStatResult) {
|
|
|
|
- ret = &util.BlockStatResult{}
|
|
|
|
- trees := filesys.LoadTrees(ids)
|
|
|
|
- for _, id := range ids {
|
|
|
|
- tree := trees[id]
|
|
|
|
- if nil == tree {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- node := treenode.GetNodeInTree(tree, id)
|
|
|
|
- if nil == node {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- runeCnt, wordCnt, linkCnt, imgCnt, refCnt := node.Stat()
|
|
|
|
- ret.RuneCount += runeCnt
|
|
|
|
- ret.WordCount += wordCnt
|
|
|
|
- ret.LinkCount += linkCnt
|
|
|
|
- ret.ImageCount += imgCnt
|
|
|
|
- ret.RefCount += refCnt
|
|
|
|
- }
|
|
|
|
- ret.BlockCount = len(ids)
|
|
|
|
- return
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func StatTree(id string) (ret *util.BlockStatResult) {
|
|
|
|
- FlushTxQueue()
|
|
|
|
-
|
|
|
|
- tree, _ := LoadTreeByBlockID(id)
|
|
|
|
- if nil == tree {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- blockCount := 0
|
|
|
|
- var databaseBlockNodes []*ast.Node
|
|
|
|
- ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
|
|
|
- if !entering {
|
|
|
|
- return ast.WalkContinue
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if n.IsBlock() {
|
|
|
|
- blockCount++
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if ast.NodeAttributeView != n.Type {
|
|
|
|
- return ast.WalkContinue
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- databaseBlockNodes = append(databaseBlockNodes, n)
|
|
|
|
- return ast.WalkContinue
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- luteEngine := util.NewLute()
|
|
|
|
- var dbRuneCnt, dbWordCnt, dbLinkCnt, dbImgCnt, dbRefCnt int
|
|
|
|
- for _, n := range databaseBlockNodes {
|
|
|
|
- if "" == n.AttributeViewID {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- attrView, _ := av.ParseAttributeView(n.AttributeViewID)
|
|
|
|
- if nil == attrView {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- content := bytes.Buffer{}
|
|
|
|
- for _, kValues := range attrView.KeyValues {
|
|
|
|
- for _, v := range kValues.Values {
|
|
|
|
- switch kValues.Key.Type {
|
|
|
|
- case av.KeyTypeURL:
|
|
|
|
- if v.IsEmpty() {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- dbLinkCnt++
|
|
|
|
- content.WriteString(v.URL.Content)
|
|
|
|
- case av.KeyTypeMAsset:
|
|
|
|
- if v.IsEmpty() {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for _, asset := range v.MAsset {
|
|
|
|
- if av.AssetTypeImage == asset.Type {
|
|
|
|
- dbImgCnt++
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- case av.KeyTypeBlock:
|
|
|
|
- if v.IsEmpty() {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if !v.IsDetached {
|
|
|
|
- dbRefCnt++
|
|
|
|
- }
|
|
|
|
- content.WriteString(v.Block.Content)
|
|
|
|
- case av.KeyTypeText:
|
|
|
|
- if v.IsEmpty() {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- content.WriteString(v.Text.Content)
|
|
|
|
- case av.KeyTypeNumber:
|
|
|
|
- if v.IsEmpty() {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- v.Number.FormatNumber()
|
|
|
|
- content.WriteString(v.Number.FormattedContent)
|
|
|
|
- case av.KeyTypeEmail:
|
|
|
|
- if v.IsEmpty() {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- content.WriteString(v.Email.Content)
|
|
|
|
- case av.KeyTypePhone:
|
|
|
|
- if v.IsEmpty() {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- content.WriteString(v.Phone.Content)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- dbStat := contentStat(content.String(), luteEngine)
|
|
|
|
- dbRuneCnt += dbStat.RuneCount
|
|
|
|
- dbWordCnt += dbStat.WordCount
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- runeCnt, wordCnt, linkCnt, imgCnt, refCnt := tree.Root.Stat()
|
|
|
|
- runeCnt += dbRuneCnt
|
|
|
|
- wordCnt += dbWordCnt
|
|
|
|
- linkCnt += dbLinkCnt
|
|
|
|
- imgCnt += dbImgCnt
|
|
|
|
- refCnt += dbRefCnt
|
|
|
|
- return &util.BlockStatResult{
|
|
|
|
- RuneCount: runeCnt,
|
|
|
|
- WordCount: wordCnt,
|
|
|
|
- LinkCount: linkCnt,
|
|
|
|
- ImageCount: imgCnt,
|
|
|
|
- RefCount: refCnt,
|
|
|
|
- BlockCount: blockCount,
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
func GetDoc(startID, endID, id string, index int, query string, queryTypes map[string]bool, queryMethod, mode int, size int, isBacklink, highlight bool) (
|
|
func GetDoc(startID, endID, id string, index int, query string, queryTypes map[string]bool, queryMethod, mode int, size int, isBacklink, highlight bool) (
|
|
blockCount int, dom, parentID, parent2ID, rootID, typ string, eof, scroll bool, boxID, docPath string, isBacklinkExpand bool, keywords []string, err error) {
|
|
blockCount int, dom, parentID, parent2ID, rootID, typ string, eof, scroll bool, boxID, docPath string, isBacklinkExpand bool, keywords []string, err error) {
|
|
//os.MkdirAll("pprof", 0755)
|
|
//os.MkdirAll("pprof", 0755)
|