新增搜索结果缓存功能
- 新增 search_cache 数据库表存储搜索缓存 - 搜索前优先查询缓存,命中则直接返回 - 缓存默认有效期7天,可配置 - 前端支持'使用缓存'开关选项 - 显示缓存状态提示 - 支持自动清理过期缓存
This commit is contained in:
+11
-2
@@ -23,6 +23,7 @@ async function doSearch() {
|
||||
const keyword = document.getElementById('search-keyword').value.trim();
|
||||
const maxResults = parseInt(document.getElementById('search-count').value) || 10;
|
||||
const engine = document.getElementById('search-engine').value;
|
||||
const useCache = document.getElementById('use-cache').checked;
|
||||
const autoFetch = document.getElementById('auto-fetch').checked;
|
||||
const autoSave = document.getElementById('auto-save').checked;
|
||||
|
||||
@@ -51,7 +52,7 @@ async function doSearch() {
|
||||
const response = await fetch(`${API_BASE}/api/articles/internet-search`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ keyword, max_results: maxResults, engine })
|
||||
body: JSON.stringify({ keyword, max_results: maxResults, engine, use_cache: useCache })
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
@@ -65,7 +66,15 @@ async function doSearch() {
|
||||
}));
|
||||
|
||||
displayResults();
|
||||
updateStatus('success', `找到 ${searchResults.length} 条结果`);
|
||||
|
||||
// 显示缓存状态
|
||||
if (data.cached) {
|
||||
updateStatus('success', `找到 ${searchResults.length} 条结果(使用缓存)`);
|
||||
showToast('使用缓存结果', 'success');
|
||||
} else {
|
||||
updateStatus('success', `找到 ${searchResults.length} 条结果`);
|
||||
}
|
||||
|
||||
document.getElementById('results-count').textContent = `${searchResults.length} 条结果`;
|
||||
document.getElementById('save-all-btn').disabled = searchResults.length === 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user