Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
9b8d77dca7
3 changed files with 46 additions and 1 deletions
|
@ -145,6 +145,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
ginServer.Handle("POST", "/api/search/searchAsset", model.CheckAuth, searchAsset)
|
||||
ginServer.Handle("POST", "/api/search/findReplace", model.CheckAuth, model.CheckReadonly, findReplace)
|
||||
ginServer.Handle("POST", "/api/search/fullTextSearchAssetContent", model.CheckAuth, fullTextSearchAssetContent)
|
||||
ginServer.Handle("POST", "/api/search/getAssetContent", model.CheckAuth, getAssetContent)
|
||||
|
||||
ginServer.Handle("POST", "/api/block/getBlockInfo", model.CheckAuth, getBlockInfo)
|
||||
ginServer.Handle("POST", "/api/block/getBlockDOM", model.CheckAuth, getBlockDOM)
|
||||
|
|
|
@ -26,6 +26,25 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func getAssetContent(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
id := arg["id"].(string)
|
||||
query := arg["query"].(string)
|
||||
queryMethod := int(arg["queryMethod"].(float64))
|
||||
|
||||
ret.Data = map[string]interface{}{
|
||||
"assetContent": model.GetAssetContent(id, query, queryMethod),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func fullTextSearchAssetContent(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
@ -47,6 +47,31 @@ type AssetContent struct {
|
|||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
func GetAssetContent(id, query string, queryMethod int) (ret *AssetContent) {
|
||||
if "" != query && (0 == queryMethod || 1 == queryMethod) {
|
||||
if 0 == queryMethod {
|
||||
query = stringQuery(query)
|
||||
}
|
||||
}
|
||||
|
||||
table := "asset_contents_fts_case_insensitive"
|
||||
filter := " id = '" + id + "'"
|
||||
if "" != query {
|
||||
filter += " AND `" + table + "` MATCH '" + buildAssetContentColumnFilter() + ":(" + query + ")'"
|
||||
}
|
||||
|
||||
projections := "id, name, ext, path, size, updated, " +
|
||||
"highlight(" + table + ", 6, '<mark>', '</mark>') AS content"
|
||||
stmt := "SELECT " + projections + " FROM " + table + " WHERE " + filter
|
||||
assetContents := sql.SelectAssetContentsRawStmt(stmt, 1, 1)
|
||||
results := fromSQLAssetContents(&assetContents, 36)
|
||||
if 1 > len(results) {
|
||||
return
|
||||
}
|
||||
ret = results[0]
|
||||
return
|
||||
}
|
||||
|
||||
// FullTextSearchAssetContent 搜索资源文件内容。
|
||||
//
|
||||
// method:0:关键字,1:查询语法,2:SQL,3:正则表达式
|
||||
|
@ -128,7 +153,7 @@ func fullTextSearchAssetContentCountByRegexp(exp, typeFilter string) (matchedAss
|
|||
func fullTextSearchAssetContentByFTS(query, typeFilter, orderBy string, beforeLen, page, pageSize int) (ret []*AssetContent, matchedAssetCount int) {
|
||||
table := "asset_contents_fts_case_insensitive"
|
||||
projections := "id, name, ext, path, size, updated, " +
|
||||
"highlight(" + table + ", 6, '<mark>', '</mark>') AS content"
|
||||
"snippet(" + table + ", 6, '<mark>', '</mark>', '...', 64) AS content"
|
||||
stmt := "SELECT " + projections + " FROM " + table + " WHERE (`" + table + "` MATCH '" + buildAssetContentColumnFilter() + ":(" + query + ")'"
|
||||
stmt += ") AND ext IN " + typeFilter
|
||||
stmt += " " + orderBy
|
||||
|
|
Loading…
Add table
Reference in a new issue