diff --git a/package.json b/package.json index c516c87..b813e4d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@yizhi/postgres", - "version": "1.0.7", + "version": "1.0.8", "main": "dist/index.js", "types": "typing/index.d.ts", "scripts": {}, diff --git a/src/type/tsvector.ts b/src/type/tsvector.ts index 04dc112..7e0e7f2 100644 --- a/src/type/tsvector.ts +++ b/src/type/tsvector.ts @@ -84,7 +84,7 @@ export class TSVector { } //处理关键词 - keywords = keywords.map(s => s.trim()).filter(s => !!s); + keywords = this.#resolveKeywords(keywords);// keywords.map(s => s.trim()).filter(s => !!s); //屏蔽纯字母数字的关键字 keywords = keywords.filter(kw => { @@ -121,6 +121,24 @@ export class TSVector { //完成 return new this(items.map(s => s.replaceAll("'", ""))); } + + //处理关键字 + static #resolveKeywords(keywords: string[]): string[] { + let result: string[] = []; + for (const kw of keywords) { + for (const s of kw.matchAll(/([a-zA-Z0-9\u4e00-\u9fa5]+)/g)) { + if (result.includes(s[1])) continue; + result.push(s[1]); + } + } + //排序 + result = result.sort((a, b) => b.length - a.length); + + //长度处理: 如果存在长度大于1的,则只保留长度大于1的关键字 + if (result.length > 1) result = result.filter(s => s.length > 1); + + return result; + } }