修复ts-query搜索时关键字中含有特殊符号的问题

This commit is contained in:
2024-12-11 18:17:22 +08:00
parent 45919defc6
commit 7755b3926b
2 changed files with 13 additions and 5 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@yizhi/postgres",
"version": "1.0.12",
"version": "1.0.13",
"main": "dist/index.js",
"types": "typing/index.d.ts",
"scripts": {},

View File

@ -482,15 +482,23 @@ function WithWhere<E extends BasicEntity, B extends Constructor<E>>(Base: B) {
switch (type) {
case "tsquery": {
const opt = option as ISearchOptionMap["tsquery"];
let keywords: string[];
let keywords: string[] = [];
let method: "or" | "and" = "or";
let absolute = false;
const resolveKeyword = (kw: string) => {
for (const s of kw.matchAll(/([a-zA-Z0-9\u4e00-\u9fa5]+)/g)) {
if (keywords.includes(s[1])) continue;
keywords.push(s[1]);
}
}
//处理选项
if (typeof opt === "string") keywords = opt.split(/\s+/).map(s => s.trim()).filter(s => s.length);
if (typeof opt === "string") resolveKeyword(opt);// keywords = opt.split(/\s+/).map(s => s.trim()).filter(s => s.length);
else if (opt instanceof Array) keywords = opt;
else {
if (typeof opt.keywords === "string") keywords = opt.keywords.split(/\s+/).map(s => s.trim()).filter(s => s.length);
else keywords = opt.keywords;
if (typeof opt.keywords === "string") resolveKeyword(opt.keywords) //keywords = opt.keywords.split(/\s+/).map(s => s.trim()).filter(s => s.length);
else opt.keywords.forEach(kw => resolveKeyword(kw));
if (opt.method) method = opt.method;
if (typeof opt.absolute == "boolean") absolute = opt.absolute;
}