🎨 Return document blocks when the keyword search hits different block content https://github.com/siyuan-note/siyuan/issues/10584

This commit is contained in:
Daniel 2024-10-27 10:59:20 +08:00
parent 6021603966
commit 4e407b0ef8
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
15 changed files with 31 additions and 10 deletions

View file

@ -531,6 +531,7 @@
"syncConfGuide5": "Wenn die Datenmenge groß ist, wird die erste Synchronisation langsam sein. Bitte haben Sie Geduld<br>Wechseln Sie nicht zwischen Apps und halten Sie den Bildschirm während der Synchronisation des iOS/iPad hell.",
"copyPlainText": "Reinen Text kopieren",
"findInDoc": "Übereinstimmungen ${y} Blöcke in ${x} Dokumenten",
"matchDoc": "${x} Dokumente gefunden",
"jumpToParentNext": "Springen Sie zum nächsten Block des übergeordneten Blocks",
"jumpToParentPrev": "Springen Sie zum vorherigen Block des übergeordneten Blocks",
"jumpToParent": "Springe zu übergeordnetem Block",

View file

@ -531,6 +531,7 @@
"syncConfGuide5": "If the amount of data is large, the first sync will be slow, please wait patiently<br>Do not switch apps and keep the screen bright while the iOS/iPad is syncing",
"copyPlainText": "Copy plain text",
"findInDoc": "Matches ${y} blocks in ${x} documents",
"matchDoc": "Matched ${x} documents",
"jumpToParentNext": "Jump to the next block of the parent block",
"jumpToParentPrev": "Jump to the previous block of the parent block",
"jumpToParent": "Jump to parent block",

View file

@ -531,6 +531,7 @@
"syncConfGuide5": "Si la cantidad de datos es grande, la primera sincronización será lenta, espere pacientemente<br>No cambie de aplicación y mantenga la pantalla brillante mientras iOS/iPad se sincroniza",
"copyPlainText": "Copiar texto sin formato",
"findInDoc": "Coincide con bloques ${y} en documentos ${x}",
"matchDoc": "Se encontraron ${x} documentos",
"jumpToParentNext": "Saltar al siguiente bloque del bloque principal",
"jumpToParentPrev": "Saltar al bloque anterior del bloque principal",
"jumpToParent": "Saltar al bloque principal",

View file

@ -531,6 +531,7 @@
"syncConfGuide5": "Si la quantité de données est importante, la première synchronisation sera lente, veuillez patienter<br> Ne changez pas d'application et gardez l'écran lumineux pendant la synchronisation de l'iOS/iPad",
"copyPlainText": "Copier du texte brut",
"findInDoc": "Correspond à ${y} blocs dans ${x} documents",
"matchDoc": "${x} documents trouvés",
"jumpToParentNext": "Sauter au bloc suivant du bloc parent",
"jumpToParentPrev": "Sauter au bloc précédent du bloc parent",
"jumpToParent": "Sauter au bloc parent",

View file

@ -531,6 +531,7 @@
"syncConfGuide5": "אם הכמות של הנתונים גבוהה, הסנכרון הראשון יתקשח, אנא חכה בסבלנות<br>אל תחליף אפליקציות ושמור על המסך מואר בזמן שמכשירי iOS/iPad בתהליך סנכרון",
"copyPlainText": "העתק טקסט פשוט",
"findInDoc": "התאמות ${y} בלוקים ב${x} מסמכים",
"matchDoc": "נמצאו ${x} מסמכים",
"jumpToParentNext": "קפוץ לבלוק הבא של הבלוק ההורה",
"jumpToParentPrev": "קפוץ לבלוק הקודם של הבלוק ההורה",
"jumpToParent": "קפוץ לבלוק ההורה",

View file

@ -531,6 +531,7 @@
"syncConfGuide5": "Se la quantità di dati è grande, la prima sincronizzazione sarà lenta, si prega di aspettare con pazienza<br>Non passare ad altre app e mantieni lo schermo acceso mentre si sincronizza su iOS/iPad",
"copyPlainText": "Copia testo semplice",
"findInDoc": "Corrispondenze ${y} blocchi in ${x} documenti",
"matchDoc": "Trovati ${x} documenti",
"jumpToParentNext": "Salta al blocco successivo del blocco genitore",
"jumpToParentPrev": "Salta al blocco precedente del blocco genitore",
"jumpToParent": "Salta al blocco genitore",

View file

@ -531,6 +531,7 @@
"syncConfGuide5": "データ量が多い場合は最初の同期が遅くなる場合がありますのでしばらくお待ちください。<br>iOS/iPad で同期している間はアプリを切り替えず画面を明るく保ってください",
"copyPlainText": "プレーンテキストとしてコピー",
"findInDoc": "${x} 個のドキュメントの ${y} ブロックと一致します",
"matchDoc": "${x} 件のドキュメントが見つかりました",
"jumpToParentNext": "次の親ブロックへ移動",
"jumpToParentPrev": "前の親ブロックへ移動",
"jumpToParent": "親ブロックへ移動",

View file

@ -531,6 +531,7 @@
"syncConfGuide5": "Jeśli ilość danych jest duża, pierwsza synchronizacja będzie wolna, proszę czekać cierpliwie<br>Nie przełączaj aplikacji i utrzymuj ekran włączony, podczas synchronizacji iOS/iPad",
"copyPlainText": "Kopiuj tekst zwykły",
"findInDoc": "Zgadza się ${y} bloków w ${x} dokumentach",
"matchDoc": "Znaleziono ${x} dokumentów",
"jumpToParentNext": "Przejdź do następnego bloku rodzica",
"jumpToParentPrev": "Przejdź do poprzedniego bloku rodzica",
"jumpToParent": "Przejdź do bloku rodzica",

View file

@ -531,6 +531,7 @@
"syncConfGuide5": "Если объем данных большой, первая синхронизация будет медленной, пожалуйста, ожидайте терпеливо<br>Не переключайте приложения и поддерживайте экран ярким, пока iOS/iPad синхронизирует",
"copyPlainText": "Скопировать обычный текст",
"findInDoc": "Соответствует ${y} блокам в ${x} документах",
"matchDoc": "Найдено ${x} документов",
"jumpToParentNext": "Перейти к следующему блоку родительского блока",
"jumpToParentPrev": "Перейти к предыдущему блоку родительского блока",
"jumpToParent": "Перейти к родительскому блоку",

View file

@ -531,6 +531,7 @@
"syncConfGuide5": "如果資料量較大,第一次同步會比較慢,請耐心等待<br>iOS/iPad 端在同步時請勿切換應用並保持螢幕恆亮",
"copyPlainText": "複製純文字",
"findInDoc": "${x} 個文件中符合 ${y} 個塊",
"matchDoc": "匹配到 ${x} 個文檔",
"jumpToParentNext": "跳到父塊的下一個塊",
"jumpToParentPrev": "跳到父塊的上一個塊",
"jumpToParent": "跳到父塊",

View file

@ -531,6 +531,7 @@
"syncConfGuide5": "如果数据量较大,第一次同步会比较慢,请耐心等待<br>iOS/iPad 端在同步时请勿切换应用并保持亮屏",
"copyPlainText": "复制纯文本",
"findInDoc": "${x} 个文档中匹配 ${y} 个块",
"matchDoc": "匹配到 ${x} 个文档",
"jumpToParentNext": "跳转到父块的下一个块",
"jumpToParentPrev": "跳转到父块的上一个块",
"jumpToParent": "跳转到父块",

View file

@ -204,7 +204,11 @@ ${unicode2Emoji(childItem.ial.icon, "b3-list-item__graphic", true)}
listElement.scrollTop = 0;
let countHTML = "";
if (response) {
countHTML = `<span class="fn__flex-center">${window.siyuan.languages.findInDoc.replace("${x}", response.data.matchedRootCount).replace("${y}", response.data.matchedBlockCount)}</span>
let text = window.siyuan.languages.findInDoc.replace("${x}", response.data.matchedRootCount).replace("${y}", response.data.matchedBlockCount);
if (response.data.docMode) {
text = window.siyuan.languages.matchDoc.replace("${x}", response.data.matchedRootCount);
}
countHTML = `<span class="fn__flex-center">${text}</span>
<span class="fn__flex-1"></span>
<span class="fn__flex-center">${config.page}/${response.data.pageCount || 1}</span>`;
}

View file

@ -1367,8 +1367,12 @@ export const inputEvent = (element: Element, config: Config.IUILayoutTabSearchCo
nextElement.setAttribute("disabled", "disabled");
}
onSearch(response.data.blocks, edit, element, config);
let text = window.siyuan.languages.findInDoc.replace("${x}", response.data.matchedRootCount).replace("${y}", response.data.matchedBlockCount);
if (response.data.docMode) {
text = window.siyuan.languages.matchDoc.replace("${x}", response.data.matchedRootCount);
}
searchResultElement.innerHTML = `${config.page}/${response.data.pageCount || 1}<span class="fn__space"></span>
<span class="ft__on-surface">${window.siyuan.languages.findInDoc.replace("${x}", response.data.matchedRootCount).replace("${y}", response.data.matchedBlockCount)}</span>`;
<span class="ft__on-surface">${text}</span>`;
loadingElement.classList.add("fn__none");
searchResultElement.setAttribute("data-pagecount", response.data.pageCount || 1);
});

View file

@ -369,12 +369,13 @@ func fullTextSearchBlock(c *gin.Context) {
}
page, pageSize, query, paths, boxes, types, method, orderBy, groupBy := parseSearchBlockArgs(arg)
blocks, matchedBlockCount, matchedRootCount, pageCount := model.FullTextSearchBlock(query, boxes, paths, types, method, orderBy, groupBy, page, pageSize)
blocks, matchedBlockCount, matchedRootCount, pageCount, docMode := model.FullTextSearchBlock(query, boxes, paths, types, method, orderBy, groupBy, page, pageSize)
ret.Data = map[string]interface{}{
"blocks": blocks,
"matchedBlockCount": matchedBlockCount,
"matchedRootCount": matchedRootCount,
"pageCount": pageCount,
"docMode": docMode,
}
}

View file

@ -476,7 +476,7 @@ func FindReplace(keyword, replacement string, replaceTypes map[string]bool, ids
if 1 > len(ids) {
// `Replace All` is no longer affected by pagination https://github.com/siyuan-note/siyuan/issues/8265
blocks, _, _, _ := FullTextSearchBlock(keyword, boxes, paths, types, method, orderBy, groupBy, 1, math.MaxInt)
blocks, _, _, _, _ := FullTextSearchBlock(keyword, boxes, paths, types, method, orderBy, groupBy, 1, math.MaxInt)
for _, block := range blocks {
ids = append(ids, block.ID)
}
@ -903,7 +903,7 @@ func replaceNodeTokens(n *ast.Node, method int, keyword string, replacement stri
// method0关键字1查询语法2SQL3正则表达式
// orderBy: 0按块类型默认1按创建时间升序2按创建时间降序3按更新时间升序4按更新时间降序5按内容顺序仅在按文档分组时6按相关度升序7按相关度降序
// groupBy0不分组1按文档分组
func FullTextSearchBlock(query string, boxes, paths []string, types map[string]bool, method, orderBy, groupBy, page, pageSize int) (ret []*Block, matchedBlockCount, matchedRootCount, pageCount int) {
func FullTextSearchBlock(query string, boxes, paths []string, types map[string]bool, method, orderBy, groupBy, page, pageSize int) (ret []*Block, matchedBlockCount, matchedRootCount, pageCount int, docMode bool) {
ret = []*Block{}
if "" == query {
return
@ -945,7 +945,12 @@ func FullTextSearchBlock(query string, boxes, paths []string, types map[string]b
typeFilter := buildTypeFilter(types)
boxFilter := buildBoxesFilter(boxes)
pathFilter := buildPathsFilter(paths)
blocks, matchedBlockCount, matchedRootCount = fullTextSearchByKeyword(query, boxFilter, pathFilter, typeFilter, ignoreFilter, orderByClause, beforeLen, page, pageSize)
if 2 > len(strings.Split(query, " ")) {
blocks, matchedBlockCount, matchedRootCount = fullTextSearchByQuerySyntax(query, boxFilter, pathFilter, typeFilter, ignoreFilter, orderByClause, beforeLen, page, pageSize)
} else {
docMode = true // 文档全文搜索模式 https://github.com/siyuan-note/siyuan/issues/10584
blocks, matchedBlockCount, matchedRootCount = fullTextSearchByKeyword(query, boxFilter, pathFilter, typeFilter, ignoreFilter, orderByClause, beforeLen, page, pageSize)
}
}
pageCount = (matchedBlockCount + pageSize - 1) / pageSize
@ -1290,10 +1295,6 @@ func fullTextSearchByKeyword(query, boxFilter, pathFilter, typeFilter, ignoreFil
ret, matchedBlockCount, matchedRootCount = searchBySQL("SELECT * FROM `blocks` WHERE `id` = '"+query+"'", beforeLen, page, pageSize)
return
}
if 2 > len(strings.Split(query, " ")) {
return fullTextSearchByFTS(query, boxFilter, pathFilter, typeFilter, ignoreFilter, orderBy, beforeLen, page, pageSize)
}
return fullTextSearchByFTSWithRoot(query, boxFilter, pathFilter, typeFilter, ignoreFilter, orderBy, beforeLen, page, pageSize)
}