|
@@ -782,6 +782,35 @@ func fullTextSearchByFTS(query, boxFilter, pathFilter, typeFilter, orderBy strin
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+func highlightByQuery(query, typeFilter, id string) (ret []string) {
|
|
|
+ const limit = 256
|
|
|
+ table := "blocks_fts"
|
|
|
+ if !Conf.Search.CaseSensitive {
|
|
|
+ table = "blocks_fts_case_insensitive"
|
|
|
+ }
|
|
|
+ projections := "id, parent_id, root_id, hash, box, path, " +
|
|
|
+ "highlight(" + table + ", 6, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "') AS hpath, " +
|
|
|
+ "highlight(" + table + ", 7, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "') AS name, " +
|
|
|
+ "highlight(" + table + ", 8, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "') AS alias, " +
|
|
|
+ "highlight(" + table + ", 9, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "') AS memo, " +
|
|
|
+ "tag, " +
|
|
|
+ "highlight(" + table + ", 11, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "') AS content, " +
|
|
|
+ "fcontent, markdown, length, type, subtype, ial, sort, created, updated"
|
|
|
+ stmt := "SELECT " + projections + " FROM " + table + " WHERE (`" + table + "` MATCH '" + columnFilter() + ":(" + query + ")'"
|
|
|
+ stmt += ") AND type IN " + typeFilter
|
|
|
+ stmt += " AND root_id = '" + id + "'"
|
|
|
+ stmt += " LIMIT " + strconv.Itoa(limit)
|
|
|
+ sqlBlocks := sql.SelectBlocksRawStmt(stmt, 1, limit)
|
|
|
+ for _, block := range sqlBlocks {
|
|
|
+ keyword := gulu.Str.SubstringsBetween(block.Content, search.SearchMarkLeft, search.SearchMarkRight)
|
|
|
+ if 0 < len(keyword) {
|
|
|
+ ret = append(ret, keyword...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ret = gulu.Str.RemoveDuplicatedElem(ret)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
func fullTextSearchCount(query, boxFilter, pathFilter, typeFilter string) (matchedBlockCount, matchedRootCount int) {
|
|
|
query = gulu.Str.RemoveInvisible(query)
|
|
|
if ast.IsNodeIDPattern(query) {
|
|
@@ -1017,6 +1046,7 @@ func markReplaceSpan(n *ast.Node, unlinks *[]*ast.Node, keywords []string, markS
|
|
|
}
|
|
|
} else if ast.NodeTextMark == n.Type {
|
|
|
// 搜索结果高亮支持大部分行级元素 https://github.com/siyuan-note/siyuan/issues/6745
|
|
|
+
|
|
|
if n.IsTextMarkType("inline-math") || n.IsTextMarkType("inline-memo") {
|
|
|
return false
|
|
|
}
|