feat: 支持拼音搜索
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m38s

- 使用pinyin-pro进行汉语拼音转换
- 调整搜索权重
This commit is contained in:
2025-11-10 15:39:47 +08:00
parent 4c8dfb5b56
commit 710a0cdc5b
6 changed files with 71 additions and 4 deletions

View File

@ -0,0 +1,17 @@
import { pinyin } from 'pinyin-pro';
/**
* 将汉语文本转换为拼音形式
*/
export function transliterateText(input: string): string {
if (!input) return '';
const text = input.normalize('NFKC').trim();
// 检测是否包含中文字符
if (/[\u4e00-\u9fa5]/.test(text)) {
return pinyin(text, { toneType: 'none', type: 'array' }).join('');
}
// 否则返回原文本
return text;
}