Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2022-06-08 10:25:53 +08:00
commit 1695ca82f8
10 changed files with 56 additions and 44 deletions

View file

@ -526,7 +526,7 @@
"md35": "Virtual Reference keyword exclusion list",
"md36": "Use the English comma <code>,</code> to separate, the comma itself can be escaped by <code>\\,</code>",
"md37": "The maximum length of block ref dynamic anchor text",
"md38": "The maximum length of the anchor text that is automatically rendered when the block ref anchor text is not customized, the default is <code>64</code> characters",
"md38": "The maximum length of the anchor text that is automatically rendered when the block ref anchor text is not customized, the default is <code>96</code> characters",
"md39": "PlantUML Serve Address",
"md40": "Leave blank to restore default <code>https://www.plantuml.com/plantuml/svg/~1</code>",
"fileTree2": "The doc tree will automatically select the current document when the editor tab is switched",

View file

@ -526,7 +526,7 @@
"md35": "Liste d'exclusion des mots-clés de la référence virtuelle",
"md36": "Utiliser la virgule anglaise <code>,</code> pour séparer, la virgule elle-même peut être échappée par <code>\\,</code>",
"md37": "La longueur maximale du texte d'ancrage dynamique de référence de bloc",
"md38": "La longueur maximale du texte d'ancrage qui est automatiquement rendu lorsque le texte d'ancrage de la référence de bloc n'est pas personnalisé, la valeur par défaut est de <code>64</code> caractères",
"md38": "La longueur maximale du texte d'ancrage qui est automatiquement rendu lorsque le texte d'ancrage de la référence de bloc n'est pas personnalisé, la valeur par défaut est de <code>96</code> caractères",
"md39": "Adresse Servo PlantUML",
"md40": "Laissez vide pour restaurer <code>https://www.plantuml.com/plantuml/svg/~1/code> par défaut",
"fileTree2": "L'arbre des Docs sélectionne automatiquement le document en cours lorsque l'on change d'onglet d'édition",

View file

@ -526,7 +526,7 @@
"md35": "虛擬引用關鍵字排除列表",
"md36": "使用英文狀態下的逗號 <code>,</code> 進行分隔,逗號自身可通過 <code>\\,</code> 轉義",
"md37": "塊引動態錨文本最大長度",
"md38": "不自訂塊引錨文本時自動渲染錨文本的最大長度,預設為 <code>64</code> 個字元",
"md38": "不自訂塊引錨文本時自動渲染錨文本的最大長度,預設為 <code>96</code> 個字元",
"md39": "PlantUML 伺服地址",
"md40": "留空將恢復默認值 <code>https://www.plantuml.com/plantuml/svg/~1</code>",
"fileTree2": "在編輯器切換分頁時文檔樹會自動選中當前的文檔",

View file

@ -527,7 +527,7 @@
"md35": "虚拟引用关键字排除列表",
"md36": "使用英文状态下的逗号 <code>,</code> 进行分隔,逗号自身可通过 <code>\\,</code> 转义",
"md37": "块引动态锚文本最大长度",
"md38": "不自定义块引锚文本时自动渲染锚文本的最大长度,默认为 <code>64</code> 个字符",
"md38": "不自定义块引锚文本时自动渲染锚文本的最大长度,默认为 <code>96</code> 个字符",
"md39": "PlantUML 伺服地址",
"md40": "留空将恢复默认值 <code>https://www.plantuml.com/plantuml/svg/~1</code>",
"fileTree2": "在编辑器页签切换时文档树会自动选中当前的文档",

View file

@ -47,7 +47,7 @@ func NewEditor() *Editor {
HistoryRetentionDays: 30,
Emoji: []string{},
VirtualBlockRef: false,
BlockRefDynamicAnchorTextMaxLen: 64,
BlockRefDynamicAnchorTextMaxLen: 96,
PlantUMLServePath: "https://www.plantuml.com/plantuml/svg/~1",
}
}

View file

@ -93,7 +93,6 @@ func recoverFrom(confPath string) (data []byte, err error) {
// 尝试从临时文件恢复
tmp := util.LatestTmpFile(confPath)
if "" == tmp {
util.LogErrorf("read data conf [%s] failed: %s", confPath, err)
return
}

View file

@ -29,8 +29,8 @@ require (
github.com/gin-contrib/cors v1.3.1
github.com/gin-contrib/gzip v0.0.5
github.com/gin-contrib/sessions v0.0.5
github.com/gin-gonic/gin v1.7.7
github.com/imroc/req/v3 v3.11.3
github.com/gin-gonic/gin v1.8.1
github.com/imroc/req/v3 v3.12.0
github.com/jinzhu/copier v0.3.5
github.com/mattn/go-sqlite3 v2.0.3+incompatible
github.com/mattn/go-zglob v0.0.3
@ -43,7 +43,7 @@ require (
github.com/siyuan-note/encryption v0.0.0-20210811062758-4d08f2d31e37
github.com/vmihailenco/msgpack/v5 v5.3.5
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9
golang.org/x/image v0.0.0-20220601225756-64ec528b34cd
golang.org/x/mobile v0.0.0-20220307220422-55113b94f09c
golang.org/x/text v0.3.7
)
@ -61,8 +61,8 @@ require (
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.11.0 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/gorilla/context v1.1.1 // indirect
@ -84,6 +84,7 @@ require (
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
@ -91,8 +92,8 @@ require (
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/mod v0.5.1 // indirect
golang.org/x/net v0.0.0-20220524220425-1d687d428aca // indirect
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect
golang.org/x/net v0.0.0-20220607020251-c690dde0001d // indirect
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/tools v0.1.8 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect

View file

@ -151,8 +151,8 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do=
github.com/gin-gonic/gin v1.7.4/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs=
github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U=
github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8=
github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk=
github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
@ -171,6 +171,8 @@ github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn
github.com/go-playground/validator/v10 v10.8.0/go.mod h1:9JhgTzTaE31GZDpH/HSvHiRJrJ3iKAgqqH0Bl/Ocjdk=
github.com/go-playground/validator/v10 v10.11.0 h1:0W+xRM511GY47Yy3bZUbJVitCNg2BOGlCyvTqsp/xIw=
github.com/go-playground/validator/v10 v10.11.0/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM=
github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
@ -204,7 +206,6 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
@ -296,8 +297,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/imroc/req/v3 v3.11.3 h1:3KmVX29c2fdF9XcRZ95/7fymisG/EXcUE7IwE6u4sNk=
github.com/imroc/req/v3 v3.11.3/go.mod h1:G6fkq27P+JcTcgRVxecxY+amHN1xFl8W81eLCfJ151M=
github.com/imroc/req/v3 v3.12.0 h1:uYva3QKn/fCFXCQJSgRdbycOye517NqqYcADfWGtRq8=
github.com/imroc/req/v3 v3.12.0/go.mod h1:G6fkq27P+JcTcgRVxecxY+amHN1xFl8W81eLCfJ151M=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jinzhu/copier v0.3.5 h1:GlvfUwHk62RokgqVNvYsku0TATCF7bAHVwEXoBh3iJg=
github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
@ -376,6 +377,8 @@ github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FI
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pelletier/go-toml/v2 v2.0.1 h1:8e3L2cCQzLFi2CR4g7vGFuFxX7Jl1kKX8gW+iV0GUKU=
github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@ -432,6 +435,7 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
@ -491,8 +495,8 @@ golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMk
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20190823064033-3a9bac650e44/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 h1:LRtI4W37N+KFebI/qV0OFiLUv4GLOWeEW5hn/KEJvxE=
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/image v0.0.0-20220601225756-64ec528b34cd h1:9NbNcTg//wfC5JskFW4Z3sqwVnjmJKHxLAol1bW2qgw=
golang.org/x/image v0.0.0-20220601225756-64ec528b34cd/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
@ -561,8 +565,8 @@ golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220111093109-d55c255bac03/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220524220425-1d687d428aca h1:xTaFYiPROfpPhqrfTIDXj0ri1SpfueYT951s4bAuDO8=
golang.org/x/net v0.0.0-20220524220425-1d687d428aca/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220607020251-c690dde0001d h1:4SFsTMi4UahlKoloni7L4eYzhFRifURQLw+yv0QDCx8=
golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@ -586,8 +590,8 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 h1:w8s32wxx3sY+OjLlv9qltkLU5yvJzxjjgiHWLjdIcw4=
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f h1:Ax0t5p6N38Ga0dThY21weqDEyz2oklo4IvDkpigvkD8=
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

View file

@ -26,7 +26,6 @@ import (
"github.com/88250/gulu"
"github.com/88250/lute/ast"
"github.com/88250/lute/html"
"github.com/88250/lute/parse"
"github.com/jinzhu/copier"
"github.com/siyuan-note/siyuan/kernel/conf"
@ -183,10 +182,10 @@ func FindReplace(keyword, replacement string, ids []string) (err error) {
func FullTextSearchBlock(query, box, path string, types map[string]bool, querySyntax bool) (ret []*Block) {
query = strings.TrimSpace(query)
if queryStrLower := strings.ToLower(query); strings.Contains(queryStrLower, "select ") && strings.Contains(queryStrLower, " * ") && strings.Contains(queryStrLower, " from ") {
ret = searchBySQL(query, 12)
ret = searchBySQL(query, 36)
} else {
filter := searchFilter(types)
ret = fullTextSearch(query, box, path, filter, 12, querySyntax)
ret = fullTextSearch(query, box, path, filter, 36, querySyntax)
}
return
}
@ -238,7 +237,7 @@ func fullTextSearchRefBlock(keyword string, beforeLen int) (ret []*Block) {
keyword = util.RemoveInvisible(keyword)
if util.IsIDPattern(keyword) {
ret = searchBySQL("SELECT * FROM `blocks` WHERE `id` = '"+keyword+"'", 12)
ret = searchBySQL("SELECT * FROM `blocks` WHERE `id` = '"+keyword+"'", 36)
return
}
@ -249,12 +248,12 @@ func fullTextSearchRefBlock(keyword string, beforeLen int) (ret []*Block) {
}
projections := "id, parent_id, root_id, hash, box, path, " +
"highlight(" + table + ", 6, '__@mark__', '__mark@__') AS hpath, " +
"highlight(" + table + ", 7, '__@mark__', '__mark@__') AS name, " +
"highlight(" + table + ", 8, '__@mark__', '__mark@__') AS alias, " +
"highlight(" + table + ", 9, '__@mark__', '__mark@__') AS memo, " +
"snippet(" + table + ", 6, '<mark>__r', '</mark>', '...', 64) AS hpath, " +
"snippet(" + table + ", 7, '<mark>__r', '</mark>', '...', 64) AS name, " +
"snippet(" + table + ", 8, '<mark>__r', '</mark>', '...', 64) AS alias, " +
"snippet(" + table + ", 9, '<mark>__r', '</mark>', '...', 64) AS memo, " +
"tag, " +
"highlight(" + table + ", 11, '__@mark__', '__mark@__') AS content, " +
"snippet(" + table + ", 11, '<mark>__r', '</mark>', '...', 64) AS content, " +
"fcontent, markdown, length, type, subtype, ial, sort, created, updated"
stmt := "SELECT " + projections + " FROM " + table + " WHERE " + table + " MATCH '" + columnFilter() + ":(" + quotedKeyword + ")' AND type IN " + Conf.Search.TypeFilter()
orderBy := ` order by case
@ -383,19 +382,28 @@ func query2Stmt(queryStr string) (ret string) {
return
}
func markSearch(text string, keyword string, beforeLen int) (pos int, marked string, score float64) {
func markSearch(text string, keyword string, beforeLen int) (marked string, score float64) {
if 0 == len(keyword) {
marked = text
if maxLen := 5120; maxLen < utf8.RuneCountInString(marked) {
marked = gulu.Str.SubStr(marked, maxLen) + "..."
}
marked = html.EscapeString(marked)
marked = strings.ReplaceAll(marked, "__@mark__", "<mark>")
marked = strings.ReplaceAll(marked, "__mark@__", "</mark>")
if strings.Contains(marked, "<mark>__r") { // 使用 FTS snippet() 处理过高亮片段,这里简单替换后就返回
marked = strings.ReplaceAll(marked, "<mark>__r", "<mark>")
return
}
keywords := util.SubstringsBetween(marked, "__@mark__", "__mark@__")
keywords = util.RemoveDuplicatedElem(keywords)
keyword = strings.Join(keywords, search.TermSep)
marked = strings.ReplaceAll(marked, "__@mark__", "")
marked = strings.ReplaceAll(marked, "__mark@__", "")
_, marked = search.MarkText(marked, keyword, beforeLen, Conf.Search.CaseSensitive)
return
}
pos, marked = search.MarkText(text, keyword, beforeLen, Conf.Search.CaseSensitive)
pos, marked := search.MarkText(text, keyword, beforeLen, Conf.Search.CaseSensitive)
if -1 < pos {
if 0 == pos {
score = 1
@ -424,7 +432,7 @@ func fromSQLBlock(sqlBlock *sql.Block, terms string, beforeLen int) (block *Bloc
content := sqlBlock.Content
p := sqlBlock.Path
_, content, _ = markSearch(content, terms, beforeLen)
content, _ = markSearch(content, terms, beforeLen)
markdown := maxContent(sqlBlock.Markdown, 5120)
content = maxContent(content, 5120)
@ -454,20 +462,20 @@ func fromSQLBlock(sqlBlock *sql.Block, terms string, beforeLen int) (block *Bloc
}
}
_, hPath, _ := markSearch(sqlBlock.HPath, terms, 18)
hPath, _ := markSearch(sqlBlock.HPath, terms, 18)
if !strings.HasPrefix(hPath, "/") {
hPath = "/" + hPath
}
block.HPath = hPath
if "" != block.Name {
_, block.Name, _ = markSearch(block.Name, terms, 256)
block.Name, _ = markSearch(block.Name, terms, 256)
}
if "" != block.Alias {
_, block.Alias, _ = markSearch(block.Alias, terms, 256)
block.Alias, _ = markSearch(block.Alias, terms, 256)
}
if "" != block.Memo {
_, block.Memo, _ = markSearch(block.Memo, terms, 256)
block.Memo, _ = markSearch(block.Memo, terms, 256)
}
return
}
@ -500,6 +508,7 @@ func columnFilter() string {
func stringQuery(query string) string {
query = strings.ReplaceAll(query, "\"", "\"\"")
query = strings.ReplaceAll(query, "'", "''")
buf := bytes.Buffer{}
parts := strings.Split(query, " ")

View file

@ -340,9 +340,8 @@ func SyncData(boot, exit, byHand bool) {
Conf.Sync.Stat = msg
util.PushErrMsg(msg, 7000)
metaPath := filepath.Join(Conf.Sync.GetSaveDir(), pathJSON)
indexPath := filepath.Join(util.TempDir, "sync", "index.json")
_, err = syncDirUpsertWorkspaceData(metaPath, indexPath, downloadedFiles)
_, err = syncDirUpsertWorkspaceData(tmpPathJSON, indexPath, downloadedFiles)
if nil != err {
util.LogErrorf("upsert partially downloaded files to workspace data failed: %s", err)
}