Skip to content

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

:art: Database filtering follows search case sensitive settings https://github.com/siyuan-note/siyuan/issues/16585

Daniele1ebb1f151cb
diff --git a/kernel/av/filter.go b/kernel/av/filter.go
index 960d40b364..68c8a2addc 100644
--- a/kernel/av/filter.go
+++ b/kernel/av/filter.go
@@ -749,32 +749,50 @@ func filterTextContent(operator FilterOperator, valueContent, otherValueContent
if "" == strings.TrimSpace(otherValueContent) {
return true
}
- return valueContent == otherValueContent
+ if util.SearchCaseSensitive {
+ return valueContent == otherValueContent
+ }
+ return strings.EqualFold(valueContent, otherValueContent)
case FilterOperatorIsNotEqual:
if "" == strings.TrimSpace(otherValueContent) {
return true
}
- return valueContent != otherValueContent
+ if util.SearchCaseSensitive {
+ return valueContent != otherValueContent
+ }
+ return !strings.EqualFold(valueContent, otherValueContent)
case FilterOperatorContains:
if "" == strings.TrimSpace(otherValueContent) {
return true
}
- return strings.Contains(valueContent, otherValueContent)
+ if util.SearchCaseSensitive {
+ return strings.Contains(valueContent, otherValueContent)
+ }
+ return strings.Contains(strings.ToLower(valueContent), strings.ToLower(otherValueContent))
case FilterOperatorDoesNotContain:
if "" == strings.TrimSpace(otherValueContent) {
return true
}
- return !strings.Contains(valueContent, otherValueContent)
+ if util.SearchCaseSensitive {
+ return !strings.Contains(valueContent, otherValueContent)
+ }
+ return !strings.Contains(strings.ToLower(valueContent), strings.ToLower(otherValueContent))
case FilterOperatorStartsWith:
if "" == strings.TrimSpace(otherValueContent) {
return true
}
- return strings.HasPrefix(valueContent, otherValueContent)
+ if util.SearchCaseSensitive {
+ return strings.HasPrefix(valueContent, otherValueContent)
+ }
+ return strings.HasPrefix(strings.ToLower(valueContent), strings.ToLower(otherValueContent))
case FilterOperatorEndsWith:
if "" == strings.TrimSpace(otherValueContent) {
return true
}
- return strings.HasSuffix(valueContent, otherValueContent)
+ if util.SearchCaseSensitive {
+ return strings.HasSuffix(valueContent, otherValueContent)
+ }
+ return strings.HasSuffix(strings.ToLower(valueContent), strings.ToLower(otherValueContent))
case FilterOperatorIsEmpty:
return "" == strings.TrimSpace(valueContent)
case FilterOperatorIsNotEmpty:
diff --git a/kernel/sql/av.go b/kernel/sql/av.go
index dc8a5d93a8..54eef8f4fc 100644
--- a/kernel/sql/av.go
+++ b/kernel/sql/av.go
@@ -846,9 +846,16 @@ func filterByQuery(query string, collection av.Collection) {
for _, cell := range item.GetValues() {
allKeywordsHit := true
for _, keyword := range keywords {
- if !strings.Contains(strings.ToLower(cell.String(true)), strings.ToLower(keyword)) {
- allKeywordsHit = false
- break
+ if !util.SearchCaseSensitive {
+ if !strings.Contains(strings.ToLower(cell.String(true)), strings.ToLower(keyword)) {
+ allKeywordsHit = false
+ break
+ }
+ } else {
+ if !strings.Contains(cell.String(true), keyword) {
+ allKeywordsHit = false
+ break
+ }
}
}
if allKeywordsHit {
diff --git a/kernel/sql/database.go b/kernel/sql/database.go
index 07e7ca33a4..4ca364b8f8 100644
--- a/kernel/sql/database.go
+++ b/kernel/sql/database.go
@@ -376,6 +376,8 @@ func SetCaseSensitive(b bool) {
} else {
db.Exec("PRAGMA case_sensitive_like = OFF;")
}
+
+ util.SearchCaseSensitive = b
}
func SetIndexAssetPath(b bool) {
diff --git a/kernel/util/runtime.go b/kernel/util/runtime.go
index 54939259f5..2a08115ad2 100644
--- a/kernel/util/runtime.go
+++ b/kernel/util/runtime.go
@@ -479,3 +479,5 @@ const (
EvtSQLHistoryRebuild = "sql.history.rebuild"
EvtSQLAssetContentRebuild = "sql.assetContent.rebuild"
)
+
+var SearchCaseSensitive bool