import { useState } from 'react' import type { SearchParams } from '@/types' import { COMMON_FILE_TYPES } from '@/types' import { useTranslation } from '@/i18n' import { CollapsibleSection } from './CollapsibleSection' import { TagInput } from './TagInput' interface SearchFormProps { searchParams: SearchParams onSearchParamsChange: (params: SearchParams) => void } export function SearchForm({ searchParams, onSearchParamsChange }: SearchFormProps) { const [showAdvanced, setShowAdvanced] = useState(false) const { t } = useTranslation() // 更新搜索参数 - 支持所有类型 const updateParam = (key: K, value: SearchParams[K]) => { const newParams = { ...searchParams, [key]: value } onSearchParamsChange(newParams) } // 切换高级选项 const toggleAdvanced = () => { setShowAdvanced(!showAdvanced) } return (
{/* 关键词输入 */}
updateParam('keyword', e.target.value)} placeholder={t('searchForm.keywordPlaceholder')} className="input" autoFocus />
{/* 搜索引擎选择 */}
{/* 高级选项切换按钮 */} {/* 高级选项 - 分组折叠 */} {showAdvanced && (
{/* 📍 位置限定组 */} {/* 网站内搜索 */}
updateParam('site', e.target.value)} placeholder="例如: github.com" className="input" />

限制搜索结果仅来自指定网站

{/* 文件类型 */}

搜索特定格式的文档

{/* 标题搜索 */}
updateParam('inTitle', e.target.value)} placeholder="例如: 教程" className="input" />

搜索标题中包含指定关键词的网页

{/* URL搜索 */}
updateParam('inUrl', e.target.value)} placeholder="例如: blog" className="input" />

搜索URL中包含指定关键词的网页

{/* 正文搜索 */}
updateParam('inText', e.target.value)} placeholder="例如: 使用方法" className="input" />

搜索正文中包含指定关键词 (Bing使用inbody)

{/* 🎯 匹配精度组 */} {/* 精确匹配 */}
updateParam('exactMatch', e.target.value)} placeholder="例如: React Hooks 完整指南" className="input" />

搜索包含完整短语的结果

{/* 通配符查询 */}
updateParam('wildcardQuery', e.target.value)} placeholder='例如: "React is * framework"' className="input" />

使用 * 代替未知词汇

{/* 所有关键词在标题 */}
updateParam('allInTitle', e.target.value)} placeholder="例如: Python 机器学习 教程" className="input" />

标题中包含所有指定关键词 (Bing自动降级)

{/* 🔀 逻辑运算组 */} {/* OR关键词 */}
updateParam('orKeywords', tags)} placeholder="输入关键词后按回车" maxTags={5} />

搜索包含任一关键词的结果 (OR)

{/* 排除关键词 */}
updateParam('excludeWords', tags)} placeholder="输入要排除的词后按回车" maxTags={10} />

从搜索结果中排除包含这些词的页面

{/* 📅 范围过滤组 */} {/* 日期范围 */}
updateParam('dateRange', { from: e.target.value, to: searchParams.dateRange?.to || '' }) } className="input" placeholder="开始日期" />

开始日期

updateParam('dateRange', { from: searchParams.dateRange?.from || '', to: e.target.value }) } className="input" placeholder="结束日期" />

结束日期

限制搜索结果的发布日期范围

{/* 数字范围 */}
updateParam('numberRange', { min: e.target.value ? Number(e.target.value) : undefined, max: searchParams.numberRange?.max } as any) } className="input" placeholder="最小值" />

最小值

updateParam('numberRange', { min: searchParams.numberRange?.min, max: e.target.value ? Number(e.target.value) : undefined } as any) } className="input" placeholder="最大值" />

最大值

搜索包含指定数字范围的结果 (如价格、年份)

{/* 🔧 特殊功能组 */} {/* 相关网站 */}
updateParam('relatedSite', e.target.value)} placeholder="例如: github.com" className="input" />

查找与指定网站相关的其他网站 (Google/Bing)

{/* 网页缓存 */}
updateParam('cacheSite', e.target.value)} placeholder="例如: https://example.com" className="input" />

查看搜索引擎保存的网页快照 (百度/Google)

)}
) }