修复ts-query搜索时关键字中含有特殊符号的问题
This commit is contained in:
16
src/query.ts
16
src/query.ts
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user