镜像自地址
https://github.com/lhly/search-syntax-pro.git
已同步 2026-10-21 06:41:51 +08:00
新增CollapsibleSection和TagInput组件用于组织高级搜索选项 扩展SearchParams类型以支持14种高级搜索语法 更新百度、Google和Bing适配器以处理新增语法 添加测试页面和文档说明功能实现情况 重构SearchForm组件使用折叠面板分组展示高级选项
312 行
11 KiB
HTML
312 行
11 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>高级搜索语法测试</title>
|
|
<style>
|
|
body {
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
background: #f5f5f5;
|
|
}
|
|
h1 {
|
|
color: #333;
|
|
border-bottom: 3px solid #4CAF50;
|
|
padding-bottom: 10px;
|
|
}
|
|
.test-section {
|
|
background: white;
|
|
padding: 20px;
|
|
margin: 20px 0;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
}
|
|
.test-case {
|
|
margin: 15px 0;
|
|
padding: 15px;
|
|
background: #f9f9f9;
|
|
border-left: 4px solid #2196F3;
|
|
border-radius: 4px;
|
|
}
|
|
.test-title {
|
|
font-weight: bold;
|
|
color: #2196F3;
|
|
margin-bottom: 10px;
|
|
}
|
|
.test-params {
|
|
background: #fff;
|
|
padding: 10px;
|
|
margin: 10px 0;
|
|
border-radius: 4px;
|
|
font-family: 'Courier New', monospace;
|
|
font-size: 12px;
|
|
}
|
|
.test-result {
|
|
margin-top: 10px;
|
|
padding: 10px;
|
|
background: #e8f5e9;
|
|
border-radius: 4px;
|
|
word-break: break-all;
|
|
}
|
|
.engine-badge {
|
|
display: inline-block;
|
|
padding: 3px 8px;
|
|
margin-right: 5px;
|
|
border-radius: 3px;
|
|
font-size: 11px;
|
|
font-weight: bold;
|
|
}
|
|
.baidu { background: #4285f4; color: white; }
|
|
.google { background: #ea4335; color: white; }
|
|
.bing { background: #008272; color: white; }
|
|
.success {
|
|
color: #4CAF50;
|
|
font-weight: bold;
|
|
}
|
|
.status {
|
|
margin: 20px 0;
|
|
padding: 15px;
|
|
background: #fff3cd;
|
|
border-left: 4px solid #ffc107;
|
|
border-radius: 4px;
|
|
}
|
|
button {
|
|
background: #4CAF50;
|
|
color: white;
|
|
border: none;
|
|
padding: 10px 20px;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
margin: 10px 5px;
|
|
font-size: 14px;
|
|
}
|
|
button:hover {
|
|
background: #45a049;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>🔍 SearchSyntax Pro - 高级语法测试</h1>
|
|
|
|
<div class="status">
|
|
<strong>测试状态:</strong> <span id="testStatus">准备就绪</span>
|
|
</div>
|
|
|
|
<button onclick="runAllTests()">运行所有测试</button>
|
|
<button onclick="clearResults()">清除结果</button>
|
|
|
|
<div id="testResults"></div>
|
|
|
|
<script type="module">
|
|
import { BaiduAdapter } from '../src/services/adapters/baidu.ts';
|
|
import { GoogleAdapter } from '../src/services/adapters/google.ts';
|
|
import { BingAdapter } from '../src/services/adapters/bing.ts';
|
|
|
|
window.BaiduAdapter = BaiduAdapter;
|
|
window.GoogleAdapter = GoogleAdapter;
|
|
window.BingAdapter = BingAdapter;
|
|
|
|
const testCases = [
|
|
{
|
|
name: '基础语法组合测试',
|
|
description: '测试 site + filetype + exact',
|
|
params: {
|
|
keyword: 'React',
|
|
engine: 'baidu',
|
|
site: 'github.com',
|
|
fileType: 'pdf',
|
|
exactMatch: 'React Hooks'
|
|
}
|
|
},
|
|
{
|
|
name: 'intitle 标题搜索',
|
|
description: '测试标题搜索功能',
|
|
params: {
|
|
keyword: 'JavaScript',
|
|
engine: 'google',
|
|
inTitle: 'tutorial'
|
|
}
|
|
},
|
|
{
|
|
name: 'inurl URL搜索',
|
|
description: '测试URL搜索功能',
|
|
params: {
|
|
keyword: 'Python',
|
|
engine: 'baidu',
|
|
inUrl: 'docs'
|
|
}
|
|
},
|
|
{
|
|
name: '排除关键词测试',
|
|
description: '测试负号排除功能',
|
|
params: {
|
|
keyword: '手机',
|
|
engine: 'bing',
|
|
excludeWords: ['二手', '广告', '培训']
|
|
}
|
|
},
|
|
{
|
|
name: 'OR逻辑测试',
|
|
description: '测试OR逻辑运算',
|
|
params: {
|
|
keyword: '编程',
|
|
engine: 'google',
|
|
orKeywords: ['JavaScript', 'Python', 'Java']
|
|
}
|
|
},
|
|
{
|
|
name: 'intext/inbody 正文搜索',
|
|
description: '测试正文搜索(百度/Google用intext, Bing用inbody)',
|
|
params: {
|
|
keyword: 'API',
|
|
engine: 'baidu',
|
|
inText: '接口文档'
|
|
}
|
|
},
|
|
{
|
|
name: '数字范围测试',
|
|
description: '测试数字范围语法',
|
|
params: {
|
|
keyword: '笔记本',
|
|
engine: 'google',
|
|
numberRange: { min: 5000, max: 10000 }
|
|
}
|
|
},
|
|
{
|
|
name: '通配符测试',
|
|
description: '测试星号通配符',
|
|
params: {
|
|
keyword: '',
|
|
engine: 'baidu',
|
|
wildcardQuery: 'React is * framework'
|
|
}
|
|
},
|
|
{
|
|
name: 'allintitle 所有关键词在标题',
|
|
description: '测试所有关键词都在标题中',
|
|
params: {
|
|
keyword: '',
|
|
engine: 'google',
|
|
allInTitle: 'Python 机器学习 教程'
|
|
}
|
|
},
|
|
{
|
|
name: 'related 相关网站 (Google/Bing)',
|
|
description: '测试相关网站功能',
|
|
params: {
|
|
keyword: '',
|
|
engine: 'google',
|
|
relatedSite: 'github.com'
|
|
}
|
|
},
|
|
{
|
|
name: 'cache 网页缓存 (百度/Google)',
|
|
description: '测试网页缓存功能',
|
|
params: {
|
|
keyword: '',
|
|
engine: 'google',
|
|
cacheSite: 'https://www.example.com'
|
|
}
|
|
},
|
|
{
|
|
name: '复杂组合测试',
|
|
description: '测试多个高级语法组合',
|
|
params: {
|
|
keyword: 'AI',
|
|
engine: 'google',
|
|
exactMatch: '人工智能',
|
|
site: 'edu.cn',
|
|
inTitle: '论文',
|
|
excludeWords: ['培训'],
|
|
dateRange: { from: '2024-01-01', to: '2024-12-31' }
|
|
}
|
|
}
|
|
];
|
|
|
|
function runAllTests() {
|
|
const resultsDiv = document.getElementById('testResults');
|
|
const statusDiv = document.getElementById('testStatus');
|
|
resultsDiv.innerHTML = '';
|
|
statusDiv.textContent = '测试运行中...';
|
|
|
|
const adapters = {
|
|
baidu: new window.BaiduAdapter(),
|
|
google: new window.GoogleAdapter(),
|
|
bing: new window.BingAdapter()
|
|
};
|
|
|
|
testCases.forEach((testCase, index) => {
|
|
const section = document.createElement('div');
|
|
section.className = 'test-section';
|
|
|
|
const title = document.createElement('h3');
|
|
title.textContent = `测试 ${index + 1}: ${testCase.name}`;
|
|
section.appendChild(title);
|
|
|
|
const desc = document.createElement('div');
|
|
desc.className = 'test-case';
|
|
desc.innerHTML = `<div class="test-title">📋 ${testCase.description}</div>`;
|
|
|
|
const paramsDiv = document.createElement('div');
|
|
paramsDiv.className = 'test-params';
|
|
paramsDiv.textContent = JSON.stringify(testCase.params, null, 2);
|
|
desc.appendChild(paramsDiv);
|
|
|
|
// 测试所有引擎
|
|
['baidu', 'google', 'bing'].forEach(engineName => {
|
|
const params = { ...testCase.params, engine: engineName };
|
|
const adapter = adapters[engineName];
|
|
|
|
try {
|
|
const query = adapter.buildQuery(params);
|
|
const validation = adapter.validateParams(params);
|
|
|
|
const resultDiv = document.createElement('div');
|
|
resultDiv.className = 'test-result';
|
|
resultDiv.innerHTML = `
|
|
<span class="engine-badge ${engineName}">${adapter.getName()}</span>
|
|
<strong>生成URL:</strong><br>
|
|
<a href="${query}" target="_blank">${query}</a><br>
|
|
<strong>验证状态:</strong> ${validation.isValid ? '<span class="success">✓ 通过</span>' : '✗ 失败'}<br>
|
|
${validation.errors.length > 0 ? `<strong>错误:</strong> ${validation.errors.join(', ')}<br>` : ''}
|
|
${validation.warnings.length > 0 ? `<strong>警告:</strong> ${validation.warnings.join(', ')}` : ''}
|
|
`;
|
|
desc.appendChild(resultDiv);
|
|
} catch (error) {
|
|
const errorDiv = document.createElement('div');
|
|
errorDiv.className = 'test-result';
|
|
errorDiv.style.background = '#ffebee';
|
|
errorDiv.innerHTML = `
|
|
<span class="engine-badge ${engineName}">${engineName}</span>
|
|
<strong>错误:</strong> ${error.message}
|
|
`;
|
|
desc.appendChild(errorDiv);
|
|
}
|
|
});
|
|
|
|
section.appendChild(desc);
|
|
resultsDiv.appendChild(section);
|
|
});
|
|
|
|
statusDiv.innerHTML = '<span class="success">✓ 测试完成!</span>';
|
|
}
|
|
|
|
function clearResults() {
|
|
document.getElementById('testResults').innerHTML = '';
|
|
document.getElementById('testStatus').textContent = '准备就绪';
|
|
}
|
|
|
|
window.runAllTests = runAllTests;
|
|
window.clearResults = clearResults;
|
|
|
|
// 页面加载时自动运行测试
|
|
window.addEventListener('load', () => {
|
|
setTimeout(runAllTests, 500);
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|