Skip to content

Commit

Permalink
Merge pull request #1830 from Giveth/add-best-match-sorting
Browse files Browse the repository at this point in the history
Add best match sorting
  • Loading branch information
MohammadPCh committed Sep 23, 2024
2 parents d0728d8 + 61524cd commit f1d60da
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/entities/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export enum SortingField {
InstantBoosting = 'InstantBoosting',
ActiveQfRoundRaisedFunds = 'ActiveQfRoundRaisedFunds',
EstimatedMatching = 'EstimatedMatching',
BestMatch = 'BestMatch',
}

export enum FilterField {
Expand Down
2 changes: 2 additions & 0 deletions src/repositories/projectRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ export const filterProjectsQuery = (params: FilterProjectQueryInputParams) => {
.addOrderBy('project.verified', 'DESC'); // Secondary sorting condition
}
break;
case SortingField.BestMatch:
break;

default:
query
Expand Down
21 changes: 12 additions & 9 deletions src/resolvers/projectResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

Expand Down

0 comments on commit f1d60da

Please sign in to comment.