修复ts-query搜索时关键字中含有特殊符号的问题
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@yizhi/postgres",
|
"name": "@yizhi/postgres",
|
||||||
"version": "1.0.12",
|
"version": "1.0.13",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "typing/index.d.ts",
|
"types": "typing/index.d.ts",
|
||||||
"scripts": {},
|
"scripts": {},
|
||||||
|
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) {
|
switch (type) {
|
||||||
case "tsquery": {
|
case "tsquery": {
|
||||||
const opt = option as ISearchOptionMap["tsquery"];
|
const opt = option as ISearchOptionMap["tsquery"];
|
||||||
let keywords: string[];
|
let keywords: string[] = [];
|
||||||
let method: "or" | "and" = "or";
|
let method: "or" | "and" = "or";
|
||||||
let absolute = false;
|
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 (opt instanceof Array) keywords = opt;
|
||||||
else {
|
else {
|
||||||
if (typeof opt.keywords === "string") keywords = opt.keywords.split(/\s+/).map(s => s.trim()).filter(s => s.length);
|
if (typeof opt.keywords === "string") resolveKeyword(opt.keywords) //keywords = opt.keywords.split(/\s+/).map(s => s.trim()).filter(s => s.length);
|
||||||
else keywords = opt.keywords;
|
else opt.keywords.forEach(kw => resolveKeyword(kw));
|
||||||
if (opt.method) method = opt.method;
|
if (opt.method) method = opt.method;
|
||||||
if (typeof opt.absolute == "boolean") absolute = opt.absolute;
|
if (typeof opt.absolute == "boolean") absolute = opt.absolute;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user