From e8448a67ce42786922178c91f1cf0435aaa01a86 Mon Sep 17 00:00:00 2001 From: skakac Date: Thu, 7 Nov 2024 10:50:48 +0100 Subject: [PATCH] Text score for search --- src/api/controller.ts | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/api/controller.ts b/src/api/controller.ts index cb50f84..83d061c 100644 --- a/src/api/controller.ts +++ b/src/api/controller.ts @@ -68,20 +68,23 @@ export async function searchByContent( chainId: Joi.number().integer().valid(101, 102, 103), }).validateAsync(req.query) - const tokens = await TokenModel.find({ - ...(data.chainId ? { chainId: data.chainId } : {}), - $or: [ - { - $text: { - $search: data.query, + const tokens = await TokenModel.find( + { + ...(data.chainId ? { chainId: data.chainId } : {}), + $or: [ + { + $text: { + $search: data.query, + }, }, - }, - { - address: data.query, - }, - ], - }) - .sort({ holders: -1 }) + { + address: data.query, + }, + ], + }, + { score: { $meta: 'textScore' } } + ) + .sort({ holders: -1, score: { $meta: 'textScore' } }) .skip(data.start) .limit(data.limit)