From b736f0c621dc9ab2c824f676c2202ca6cec02eff Mon Sep 17 00:00:00 2001 From: Neal <1107554021@qq.com> Date: Tue, 21 Jan 2025 18:21:16 +0800 Subject: [PATCH] fix: search results --- src/app.service.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app.service.ts b/src/app.service.ts index e83bc0a..57435fd 100644 --- a/src/app.service.ts +++ b/src/app.service.ts @@ -65,7 +65,7 @@ export class AppService { }); const list = await this.connection.query( - `SELECT id, eip, title, author, status, type, category FROM "EIPs" ${condition} order by eip LIMIT ${take} OFFSET ${skip}`, + `SELECT id, eip, title, author, status, type, category FROM "EIPs" ${condition} order by (substring("eip", '^[0-9]+'))::int LIMIT ${take} OFFSET ${skip}`, ); return { @@ -92,7 +92,7 @@ export class AppService { numbers.forEach((item) => { if (Number(item) < 10000) { // eip number don't overt 10000 - eips.push(`eip::text LIKE '%${item}%'`); + eips.push(`eip LIKE '%${item}%'`); } }); if (eips.length === 1) { @@ -113,7 +113,7 @@ export class AppService { // title match const conditions = eips.length ? `${eipCondition} AND` : ``; const titleRecords = await this.connection.query( - `SELECT eip, type, category, ts_headline('english',title, q), rank FROM (SELECT eip, type, category, title, q, ts_rank_cd(to_tsvector(title_ts), q) AS rank FROM "EIPs", phraseto_tsquery('english','${txt}') q WHERE ${conditions} 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','${txt}') q WHERE ${conditions} title_ts @@ q ORDER BY rank DESC LIMIT 20) AS foo;`, ); if (titleRecords && titleRecords.length > 0) { @@ -122,7 +122,7 @@ export class AppService { // author match const authorRecords = await this.connection.query( - `SELECT eip, type, category, ts_headline('english', author, q), rank FROM (SELECT eip, type, category, author, q, ts_rank_cd(to_tsvector(author_ts), q) AS rank FROM "EIPs", phraseto_tsquery('english','${txt}') q WHERE ${conditions} author_ts @@ q ORDER BY rank DESC LIMIT 20) AS foo;`, + `SELECT eip, type, category, ts_headline('english', author, q), rank FROM (SELECT eip, type, category, author, q, ts_rank_cd(author_ts, q) AS rank FROM "EIPs", phraseto_tsquery('english','${txt}') q WHERE ${conditions} author_ts @@ q ORDER BY rank DESC LIMIT 20) AS foo;`, ); if (authorRecords && authorRecords.length > 0) { @@ -131,7 +131,7 @@ export class AppService { // content match const contentRecords = await this.connection.query( - `SELECT eip, type, category, title, ts_headline('english',content, q), rank FROM (SELECT eip, type, category, title, content, q, ts_rank_cd(to_tsvector(content_ts), q) AS rank FROM "EIPs", phraseto_tsquery('english','${txt}') q WHERE ${conditions} 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','${txt}') q WHERE ${conditions} content_ts @@ q ORDER BY rank DESC LIMIT 20) AS foo;`, ); if (contentRecords && contentRecords.length > 0) { result['content_list'] = contentRecords;