From 16ea3e4ede239865a7813462ad368a238ccb2ea9 Mon Sep 17 00:00:00 2001 From: skakac Date: Mon, 4 Nov 2024 15:45:07 +0100 Subject: [PATCH] Use text search for better performance --- src/api/controller.ts | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/api/controller.ts b/src/api/controller.ts index a9d7b82..cb50f84 100644 --- a/src/api/controller.ts +++ b/src/api/controller.ts @@ -72,15 +72,8 @@ export async function searchByContent( ...(data.chainId ? { chainId: data.chainId } : {}), $or: [ { - name: { - $regex: escapeRegex(data.query), - $options: 'i', - }, - }, - { - symbol: { - $regex: escapeRegex(data.query), - $options: 'i', + $text: { + $search: data.query, }, }, { @@ -101,5 +94,5 @@ export async function searchByContent( } function escapeRegex(string: string) { - return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&'); -} \ No newline at end of file + return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&') +}