From 7755b3926b4beec202bc646355eafb2c07443669 Mon Sep 17 00:00:00 2001 From: yizhi <946185759@qq.com> Date: Wed, 11 Dec 2024 18:17:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dts-query=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=97=B6=E5=85=B3=E9=94=AE=E5=AD=97=E4=B8=AD=E5=90=AB=E6=9C=89?= =?UTF-8?q?=E7=89=B9=E6=AE=8A=E7=AC=A6=E5=8F=B7=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/query.ts | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) 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; }