全文搜索适配

This commit is contained in:
tangly
2022-10-18 16:55:57 +08:00
parent d708c7c638
commit 47a349dd18
2 changed files with 11 additions and 10 deletions

View File

@@ -17,19 +17,20 @@ if (process.env.MONGO_DB_URL && process.env.MONGO_DB_NAME) {
* @param {*} key
* @returns
*/
export async function getDataFromCache(key) {
if (!BLOG.ENABLE_CACHE) {
export async function getDataFromCache(key, force) {
if (BLOG.ENABLE_CACHE || force) {
const dataFromCache = await api.getCache(key)
if (JSON.stringify(dataFromCache) === '[]') {
return null
}
return api.getCache(key)
} else {
return null
}
const dataFromCache = await api.getCache(key)
if (JSON.stringify(dataFromCache) === '[]') {
return null
}
return api.getCache(key)
}
export async function setDataToCache(key, data) {
if (!BLOG.ENABLE_CACHE || !data) {
if (!data) {
return
}
await api.setCache(key, data)

View File

@@ -109,7 +109,7 @@ async function filterByMemCache(allPosts, keyword) {
}
for (const post of allPosts) {
const cacheKey = 'page_block_' + post.id
const page = await getDataFromCache(cacheKey)
const page = await getDataFromCache(cacheKey, true)
const tagContent = post.tags && Array.isArray(post.tags) ? post.tags.join(' ') : ''
const categoryContent = post.category && Array.isArray(post.category) ? post.category.join(' ') : ''
const articleInfo = post.title + post.summary + tagContent + categoryContent
@@ -123,7 +123,7 @@ async function filterByMemCache(allPosts, keyword) {
indexContent = appendText(indexContent, properties, 'caption')
})
}
console.log('全文搜索缓存', cacheKey, page != null)
// console.log('全文搜索缓存', cacheKey, page != null)
post.results = []
let hitCount = 0
for (const i in indexContent) {