feat: 支持拼音搜索
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m38s
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m38s
- 使用pinyin-pro进行汉语拼音转换 - 调整搜索权重
This commit is contained in:
17
app/utils/transliterateText.ts
Normal file
17
app/utils/transliterateText.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user