Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Search ignore is not working in some cases

Daniel655b6bc41884
diff --git a/kernel/model/block.go b/kernel/model/block.go
index 6ec2367184..c45595a67b 100644
--- a/kernel/model/block.go
+++ b/kernel/model/block.go
@@ -17,6 +17,7 @@
package model
import (
+ "bytes"
"errors"
"fmt"
"strconv"
@@ -298,7 +299,23 @@ func IsBlockFolded(id string) (isFolded, isRoot bool) {
func RecentUpdatedBlocks() (ret []*Block) {
ret = []*Block{}
- sqlBlocks := sql.QueryRecentUpdatedBlocks()
+ sqlStmt := "SELECT * FROM blocks WHERE type = 'p' AND length > 1"
+ if util.ContainerIOS == util.Container || util.ContainerAndroid == util.Container {
+ sqlStmt = "SELECT * FROM blocks WHERE type = 'd'"
+ }
+
+ if ignoreLines := getSearchIgnoreLines(); 0 < len(ignoreLines) {
+ // Support ignore search results https://github.com/siyuan-note/siyuan/issues/10089
+ buf := bytes.Buffer{}
+ for _, line := range ignoreLines {
+ buf.WriteString(" AND ")
+ buf.WriteString(line)
+ }
+ sqlStmt += buf.String()
+ }
+
+ sqlStmt += " ORDER BY updated DESC"
+ sqlBlocks := sql.SelectBlocksRawStmt(sqlStmt, 1, 16)
if 1 > len(sqlBlocks) {
return
}
diff --git a/kernel/sql/block_query.go b/kernel/sql/block_query.go
index d267395c55..e9843e8f7f 100644
--- a/kernel/sql/block_query.go
+++ b/kernel/sql/block_query.go
@@ -31,7 +31,6 @@ import (
sqlparser2 "github.com/rqlite/sql"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/treenode"
- "github.com/siyuan-note/siyuan/kernel/util"
)
func QueryEmptyContentEmbedBlocks() (ret []*Block) {
@@ -123,32 +122,6 @@ func queryBlockIDByParentID(parentID string) (ret []string) {
return
}
-func QueryRecentUpdatedBlocks() (ret []*Block) {
- sqlStmt := "SELECT * FROM blocks WHERE type = 'p' AND length > 1 ORDER BY updated DESC LIMIT 16"
- if util.ContainerIOS == util.Container || util.ContainerAndroid == util.Container {
- sqlStmt = "SELECT * FROM blocks WHERE type = 'd' ORDER BY updated DESC LIMIT 16"
- }
- rows, err := query(sqlStmt)
- if err != nil {
- logging.LogErrorf("sql query [%s] failed: %s", sqlStmt, err)
- return
- }
- defer rows.Close()
- for rows.Next() {
- if block := scanBlockRows(rows); nil != block {
- ret = append(ret, block)
- }
- }
- return
-}
-
-func QueryBlockByNameOrAlias(rootID, text string) (ret *Block) {
- sqlStmt := "SELECT * FROM blocks WHERE root_id = ? AND (alias LIKE ? OR name = ?)"
- row := queryRow(sqlStmt, rootID, "%"+text+"%", text)
- ret = scanBlockRow(row)
- return
-}
-
func QueryBlockAliases(rootID string) (ret []string) {
sqlStmt := "SELECT alias FROM blocks WHERE root_id = ? AND alias != ''"
rows, err := query(sqlStmt, rootID)