fix: search by tags (#171)

This commit is contained in:
bayang 2023-06-26 16:41:07 +02:00 committed by GitHub
parent bda59556a2
commit 7df3ef0d1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -128,7 +128,7 @@
}) })
posts.forEach((p, idx) => { posts.forEach((p, idx) => {
contentIndex.add({ contentIndex.add({
id: idx, title: p.title, content: p.content, //Change to removeHTML id: idx, title: p.title, content: p.content, tags: p.tags //Change to removeHTML
}) })
}); });
return contentIndex; return contentIndex;
@ -333,7 +333,7 @@
function offlineSearch(searchQuery) { function offlineSearch(searchQuery) {
let data = window.docs; let data = window.docs;
let isTagSearch = search[0] === "#" && search.length > 1; let isTagSearch = searchQuery[0] === "#" && searchQuery.length > 1;
let searchResults = isTagSearch let searchResults = isTagSearch
? index.search(searchQuery.substring(1), [ ? index.search(searchQuery.substring(1), [
@ -361,7 +361,8 @@
} }
const allIds = new Set([ const allIds = new Set([
...getByField("title"), ...getByField("title"),
...getByField("content") ...getByField("content"),
...getByField("tags")
]) ])
const dataIds = [...allIds]; const dataIds = [...allIds];
const finalResults = dataIds.map((id) => { const finalResults = dataIds.map((id) => {