From 8f51e20b2e944fde17ddefd587703e6b744540f9 Mon Sep 17 00:00:00 2001 From: softsimon Date: Tue, 21 Feb 2023 17:14:51 +0400 Subject: [PATCH 1/3] Fixes a syntax error with certain keywords --- backend/src/api/explorer/nodes.api.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/src/api/explorer/nodes.api.ts b/backend/src/api/explorer/nodes.api.ts index d292aa2e3..0d641d3cf 100644 --- a/backend/src/api/explorer/nodes.api.ts +++ b/backend/src/api/explorer/nodes.api.ts @@ -362,7 +362,12 @@ class NodesApi { public async $searchNodeByPublicKeyOrAlias(search: string) { try { const publicKeySearch = search.replace('%', '') + '%'; - const aliasSearch = search.replace(/[-_.]/g, ' ').replace(/[^a-zA-Z0-9 ]/g, '').split(' ').map((search) => '+' + search + '*').join(' '); + const aliasSearch = search + .replace(/[-_.]/g, ' ') + .replace(/[^a-zA-Z0-9 ]/g, '') + .split(' ') + .filter(key => key.length) + .map((search) => '+' + search + '*').join(' '); const query = `SELECT public_key, alias, capacity, channels, status FROM nodes WHERE public_key LIKE ? OR MATCH alias_search AGAINST (? IN BOOLEAN MODE) ORDER BY capacity DESC LIMIT 10`; const [rows]: any = await DB.query(query, [publicKeySearch, aliasSearch]); return rows; From b6792784e85caac81a65d2a408881b7fc759c51d Mon Sep 17 00:00:00 2001 From: softsimon Date: Wed, 22 Feb 2023 10:19:19 +0400 Subject: [PATCH 2/3] Adding regex comments. --- backend/src/api/explorer/nodes.api.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/api/explorer/nodes.api.ts b/backend/src/api/explorer/nodes.api.ts index 0d641d3cf..36bbf26d2 100644 --- a/backend/src/api/explorer/nodes.api.ts +++ b/backend/src/api/explorer/nodes.api.ts @@ -363,8 +363,8 @@ class NodesApi { try { const publicKeySearch = search.replace('%', '') + '%'; const aliasSearch = search - .replace(/[-_.]/g, ' ') - .replace(/[^a-zA-Z0-9 ]/g, '') + .replace(/[-_.]/g, ' ') // Replace all -_. characters with empty space. Eg: "ln.nicehash" becomes "ln nicehash". + .replace(/[^a-zA-Z0-9 ]/g, '') // Remove all special characters and keep just A to Z, 0 to 9. .split(' ') .filter(key => key.length) .map((search) => '+' + search + '*').join(' '); From 10bfb512159f34c12ea9cf8a6948fa20a970a1b0 Mon Sep 17 00:00:00 2001 From: wiz Date: Thu, 23 Feb 2023 13:37:09 +0900 Subject: [PATCH 3/3] Add simon's comment to $searchNodeByPublicKeyOrAlias() --- backend/src/api/explorer/nodes.api.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/api/explorer/nodes.api.ts b/backend/src/api/explorer/nodes.api.ts index 36bbf26d2..b3f83faa6 100644 --- a/backend/src/api/explorer/nodes.api.ts +++ b/backend/src/api/explorer/nodes.api.ts @@ -368,6 +368,7 @@ class NodesApi { .split(' ') .filter(key => key.length) .map((search) => '+' + search + '*').join(' '); + // %keyword% is wildcard search and can't be indexed so it's slower as the node database grow. keyword% can be indexed but then you can't search for "Nicehash" and get result for ln.nicehash.com. So we use fulltext index for words "ln, nicehash, com" and nicehash* will find it instantly. const query = `SELECT public_key, alias, capacity, channels, status FROM nodes WHERE public_key LIKE ? OR MATCH alias_search AGAINST (? IN BOOLEAN MODE) ORDER BY capacity DESC LIMIT 10`; const [rows]: any = await DB.query(query, [publicKeySearch, aliasSearch]); return rows;