Skip to content

Commit

Permalink
全文搜索适配
Browse files Browse the repository at this point in the history
  • Loading branch information
tangly1024 committed Oct 18, 2022
1 parent d708c7c commit 47a349d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions lib/cache/cache_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
return null
}
const dataFromCache = await api.getCache(key)
if (JSON.stringify(dataFromCache) === '[]') {
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
}
return api.getCache(key)
}

export async function setDataToCache(key, data) {
if (!BLOG.ENABLE_CACHE || !data) {
if (!data) {
return
}
await api.setCache(key, data)
Expand Down
4 changes: 2 additions & 2 deletions pages/search/[keyword].js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit 47a349d

Please sign in to comment.