Skip to content

Commit

Permalink
Prioritize project with exact name match in search
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv committed Aug 26, 2023
1 parent d97dc46 commit d8edb07
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public ResponseEntity<PaginatedResult<ProjectMember>> getProjectMembers(final St
@Override
@ApplicableFilters({ProjectCategoryFilter.class, ProjectPlatformFilter.class, ProjectAuthorFilter.class, ProjectQueryFilter.class, ProjectLicenseFilter.class, ProjectMCVersionFilter.class, ProjectTagFilter.class})
@ApplicableSorters({SorterRegistry.VIEWS, SorterRegistry.DOWNLOADS, SorterRegistry.NEWEST, SorterRegistry.STARS, SorterRegistry.UPDATED, SorterRegistry.RECENT_DOWNLOADS, SorterRegistry.RECENT_VIEWS, SorterRegistry.SLUG})
public ResponseEntity<PaginatedResult<Project>> getProjects(@Deprecated(forRemoval = true) final boolean orderWithRelevance, final @NotNull RequestPagination pagination) {
public ResponseEntity<PaginatedResult<Project>> getProjects(final boolean prioritizeExactMatch, final @NotNull RequestPagination pagination) {
final boolean seeHidden = this.getGlobalPermissions().has(Permission.SeeHidden);
return ResponseEntity.ok(this.projectsApiService.getProjects(pagination, seeHidden));
return ResponseEntity.ok(this.projectsApiService.getProjects(pagination, seeHidden, prioritizeExactMatch));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ default ResponseEntity<PaginatedResult<ProjectMember>> getProjectMembers(
})
@GetMapping("/projects")
ResponseEntity<PaginatedResult<Project>> getProjects(
@Parameter(deprecated = true, description = "No longer functions. Sort by (recent) stars, downloads, or views instead") @RequestParam(defaultValue = "true", required = false) boolean orderWithRelevance,
@Parameter(description = "Whether to prioritize the project with an exact name match if present") @RequestParam(defaultValue = "true", required = false) boolean prioritizeExactMatch,
@Parameter(description = "Pagination information") @NotNull RequestPagination pagination
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public PaginatedResult<User> getProjectWatchers(final String slug, final Request

@Transactional(readOnly = true)
@Cacheable(CacheConfig.PROJECTS)
public PaginatedResult<Project> getProjects(final RequestPagination pagination, final boolean seeHidden) {
public PaginatedResult<Project> getProjects(final RequestPagination pagination, final boolean seeHidden, final boolean prioritizeExactMatch) {
// get query from filter
String query = null;
for (final Filter.FilterInstance filterInstance : pagination.getFilters().values()) {
Expand All @@ -78,7 +78,7 @@ public PaginatedResult<Project> getProjects(final RequestPagination pagination,
}
}

if (query != null && !query.isBlank()) {
if (prioritizeExactMatch && query != null && !query.isBlank()) {
pagination.getSorters().put("exact_match", sb -> sb.append(" exact_match ASC"));
}

Expand Down

0 comments on commit d8edb07

Please sign in to comment.