From 70079874a0f0c0187c05c8d4cf941da8ca879769 Mon Sep 17 00:00:00 2001 From: Cherik Date: Thu, 19 Sep 2024 12:04:43 +0330 Subject: [PATCH 1/2] add best match sort option --- src/entities/project.ts | 1 + src/repositories/projectRepository.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/entities/project.ts b/src/entities/project.ts index 711e1334b..ab6f6a8a8 100644 --- a/src/entities/project.ts +++ b/src/entities/project.ts @@ -77,6 +77,7 @@ export enum SortingField { InstantBoosting = 'InstantBoosting', ActiveQfRoundRaisedFunds = 'ActiveQfRoundRaisedFunds', EstimatedMatching = 'EstimatedMatching', + BestMatch = 'BestMatch', } export enum FilterField { diff --git a/src/repositories/projectRepository.ts b/src/repositories/projectRepository.ts index 1edcc8485..a17703158 100644 --- a/src/repositories/projectRepository.ts +++ b/src/repositories/projectRepository.ts @@ -252,6 +252,8 @@ export const filterProjectsQuery = (params: FilterProjectQueryInputParams) => { .addOrderBy('project.verified', 'DESC'); // Secondary sorting condition } break; + case SortingField.BestMatch: + break; default: query From 61524cdd05f1cf1488a0b99cccb196931650e258 Mon Sep 17 00:00:00 2001 From: Cherik Date: Thu, 19 Sep 2024 12:06:00 +0330 Subject: [PATCH 2/2] update addSearchQuery to prioritize the title --- src/resolvers/projectResolver.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/resolvers/projectResolver.ts b/src/resolvers/projectResolver.ts index bafb581a1..74915f8ac 100644 --- a/src/resolvers/projectResolver.ts +++ b/src/resolvers/projectResolver.ts @@ -328,19 +328,22 @@ export class ProjectResolver { // .addSelect('similarity(project.description, :searchTerm)', 'desc_slm') // .addSelect('similarity(project.impactLocation, :searchTerm)', 'loc_slm') // .setParameter('searchTerm', searchTerm) + .addSelect( + `(CASE + WHEN project.title %> :searchTerm THEN 1 + ELSE 2 + END)`, + 'title_priority', + ) .andWhere( new Brackets(qb => { - qb.where('project.title %> :searchTerm ', { - searchTerm, - }) - .orWhere('project.description %> :searchTerm ', { - searchTerm, - }) - .orWhere('project.impactLocation %> :searchTerm', { - searchTerm, - }); + qb.where('project.title %> :searchTerm', { searchTerm }) + .orWhere('project.description %> :searchTerm', { searchTerm }) + .orWhere('project.impactLocation %> :searchTerm', { searchTerm }); }), ) + .orderBy('title_priority', 'ASC') + .setParameter('searchTerm', searchTerm) ); }