diff --git a/package.json b/package.json index 1db7dba..d1f033b 100644 --- a/package.json +++ b/package.json @@ -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": {}, diff --git a/src/query.ts b/src/query.ts index 1db901c..b06dad5 100644 --- a/src/query.ts +++ b/src/query.ts @@ -482,15 +482,23 @@ function WithWhere>(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; }