From 08e9df21938c327ff6bffcd18abd6954d74ec20f Mon Sep 17 00:00:00 2001 From: wwei-github <418047394@qq.com> Date: Tue, 17 Oct 2023 15:28:57 +0800 Subject: [PATCH 1/2] fix: about search charity error --- src/app.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app.service.ts b/src/app.service.ts index 38f7a8f..0b8b08d 100644 --- a/src/app.service.ts +++ b/src/app.service.ts @@ -81,7 +81,6 @@ export class AppService { async search(content: string) { const result = {}; - // eip match if (this.isNumeric(content)) { const eipRecords = await this.connection.query( @@ -93,15 +92,16 @@ export class AppService { } else { // title match const titleRecords = await this.connection.query( - `SELECT eip, type, category, ts_headline(title, q), rank FROM (SELECT eip, type, category, title, q, ts_rank_cd(title_ts, q) AS rank FROM "EIPs", phraseto_tsquery('${content}') q WHERE title_ts @@ q ORDER BY rank DESC LIMIT 20) AS foo;`, + `SELECT eip, type, category, ts_headline(title, q), rank FROM (SELECT eip, type, category, title, q, ts_rank_cd(title_ts, q) AS rank FROM "EIPs", phraseto_tsquery('english','${content}') q WHERE title_ts @@ q ORDER BY rank DESC LIMIT 20) AS foo;`, ); + if (titleRecords && titleRecords.length > 0) { result['title_list'] = titleRecords; } // content match const contentRecords = await this.connection.query( - `SELECT eip, type, category, title, ts_headline(content, q), rank FROM (SELECT eip, type, category, title, content, q, ts_rank_cd(content_ts, q) AS rank FROM "EIPs", phraseto_tsquery('${content}') q WHERE content_ts @@ q ORDER BY rank DESC LIMIT 20) AS foo;`, + `SELECT eip, type, category, title, ts_headline(content, q), rank FROM (SELECT eip, type, category, title, content, q, ts_rank_cd(content_ts, q) AS rank FROM "EIPs", phraseto_tsquery('english','${content}') q WHERE content_ts @@ q ORDER BY rank DESC LIMIT 20) AS foo;`, ); if (contentRecords && contentRecords.length > 0) { result['content_list'] = contentRecords; From d2bb622e9f35064f65c4e07f36e9924f725d4439 Mon Sep 17 00:00:00 2001 From: wwei-github <418047394@qq.com> Date: Tue, 17 Oct 2023 16:02:31 +0800 Subject: [PATCH 2/2] fix: ts_headline add 'english' param --- src/app.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app.service.ts b/src/app.service.ts index 0b8b08d..3389c00 100644 --- a/src/app.service.ts +++ b/src/app.service.ts @@ -92,7 +92,7 @@ export class AppService { } else { // title match const titleRecords = await this.connection.query( - `SELECT eip, type, category, ts_headline(title, q), rank FROM (SELECT eip, type, category, title, q, ts_rank_cd(title_ts, q) AS rank FROM "EIPs", phraseto_tsquery('english','${content}') q WHERE title_ts @@ q ORDER BY rank DESC LIMIT 20) AS foo;`, + `SELECT eip, type, category, ts_headline('english',title, q), rank FROM (SELECT eip, type, category, title, q, ts_rank_cd(title_ts, q) AS rank FROM "EIPs", phraseto_tsquery('english','${content}') q WHERE title_ts @@ q ORDER BY rank DESC LIMIT 20) AS foo;`, ); if (titleRecords && titleRecords.length > 0) { @@ -101,7 +101,7 @@ export class AppService { // content match const contentRecords = await this.connection.query( - `SELECT eip, type, category, title, ts_headline(content, q), rank FROM (SELECT eip, type, category, title, content, q, ts_rank_cd(content_ts, q) AS rank FROM "EIPs", phraseto_tsquery('english','${content}') q WHERE content_ts @@ q ORDER BY rank DESC LIMIT 20) AS foo;`, + `SELECT eip, type, category, title, ts_headline('english',content, q), rank FROM (SELECT eip, type, category, title, content, q, ts_rank_cd(content_ts, q) AS rank FROM "EIPs", phraseto_tsquery('english','${content}') q WHERE content_ts @@ q ORDER BY rank DESC LIMIT 20) AS foo;`, ); if (contentRecords && contentRecords.length > 0) { result['content_list'] = contentRecords;