Skip to content

Commit

Permalink
Use text search for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
skakac committed Nov 4, 2024
1 parent 32e3705 commit 16ea3e4
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/api/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
{
Expand All @@ -101,5 +94,5 @@ export async function searchByContent(
}

function escapeRegex(string: string) {
return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&');
}
return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&')
}

0 comments on commit 16ea3e4

Please sign in to comment.