diff --git a/backend/src/main/java/io/papermc/hangar/controller/extras/resolvers/RequestPaginationResolver.java b/backend/src/main/java/io/papermc/hangar/controller/extras/resolvers/RequestPaginationResolver.java index 2b3ebe5e8..c752c9075 100644 --- a/backend/src/main/java/io/papermc/hangar/controller/extras/resolvers/RequestPaginationResolver.java +++ b/backend/src/main/java/io/papermc/hangar/controller/extras/resolvers/RequestPaginationResolver.java @@ -121,8 +121,6 @@ public RequestPagination resolveArgument(final @NotNull MethodParameter paramete paramNames.remove("sort"); paramNames.remove("limit"); paramNames.remove("offset"); - // TODO remove these bellow eventually - paramNames.remove("relevance"); // remove request params for (final Parameter param : parameter.getExecutable().getParameters()) { diff --git a/backend/src/main/java/io/papermc/hangar/model/api/project/ProjectSortingStrategy.java b/backend/src/main/java/io/papermc/hangar/model/api/project/ProjectSortingStrategy.java index afd561a02..1d735cffd 100644 --- a/backend/src/main/java/io/papermc/hangar/model/api/project/ProjectSortingStrategy.java +++ b/backend/src/main/java/io/papermc/hangar/model/api/project/ProjectSortingStrategy.java @@ -2,41 +2,32 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; +import org.jetbrains.annotations.Nullable; /** * Gets or Sets ProjectSortingStrategy */ public enum ProjectSortingStrategy { - STARS(0, "Most stars", "hp.stars DESC, p.name ASC", "stars"), - DOWNLOADS(1, "Most downloads", "hp.downloads DESC", "downloads"), - VIEWS(2, "Most views", "hp.views DESC", "views"), - NEWEST(3, "Newest", "p.created_at DESC", "newest"), - UPDATED(4, "Recently updated", "hp.last_updated DESC", "updated"), - ONLY_RELEVANCE(5, "Only relevance", "hp.last_updated DESC", "only_relevance"), - RECENT_DOWNLOADS(6, "Recent views", "hp.recent_views DESC", "recent_views"), - RECENT_VIEWS(7, "Recent downloads", "hp.recent_downloads DESC", "recent_downloads"); + STARS("Most stars", "hp.stars DESC, p.name ASC", "stars"), + DOWNLOADS("Most downloads", "hp.downloads DESC", "downloads"), + VIEWS("Most views", "hp.views DESC", "views"), + NEWEST("Newest", "p.created_at DESC", "newest"), + UPDATED("Recently updated", "hp.last_updated DESC", "updated"), + RECENT_DOWNLOADS("Recent views", "hp.recent_views DESC", "recent_views"), + RECENT_VIEWS("Recent downloads", "hp.recent_downloads DESC", "recent_downloads"); - public static final ProjectSortingStrategy Default = UPDATED; - - private final int value; + private static final ProjectSortingStrategy[] VALUES = values(); private final String title; private final String sql; private final String apiName; - public static final ProjectSortingStrategy[] VALUES = values(); - - ProjectSortingStrategy(final int value, final String title, final String sql, final String apiName) { - this.value = value; + ProjectSortingStrategy(final String title, final String sql, final String apiName) { this.title = title; this.sql = sql; this.apiName = apiName; } - public int getValue() { - return this.value; - } - public String getTitle() { return this.title; } @@ -56,10 +47,10 @@ public String toString() { } @JsonCreator - public static ProjectSortingStrategy fromApiName(final String apiName) { - for (final ProjectSortingStrategy b : values()) { - if (b.apiName.equals(apiName)) { - return b; + public static @Nullable ProjectSortingStrategy fromApiName(final String apiName) { + for (final ProjectSortingStrategy strategy : VALUES) { + if (strategy.apiName.equals(apiName)) { + return strategy; } } return null; diff --git a/backend/src/main/java/io/papermc/hangar/service/api/ProjectsApiService.java b/backend/src/main/java/io/papermc/hangar/service/api/ProjectsApiService.java index e2643864f..a9eaccce9 100644 --- a/backend/src/main/java/io/papermc/hangar/service/api/ProjectsApiService.java +++ b/backend/src/main/java/io/papermc/hangar/service/api/ProjectsApiService.java @@ -15,8 +15,10 @@ import io.papermc.hangar.model.api.requests.RequestPagination; import io.papermc.hangar.model.common.Permission; import java.time.OffsetDateTime; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.function.Consumer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; @@ -79,7 +81,12 @@ public PaginatedResult getProjects(final RequestPagination pagination, } if (prioritizeExactMatch && query != null && !query.isBlank()) { - pagination.getSorters().put("exact_match", sb -> sb.append(" exact_match ASC")); + // This sorter needs to be first + final Map> sorters = pagination.getSorters(); + final Map> copy = new LinkedHashMap<>(sorters); + sorters.clear(); + sorters.put("exact_match", sb -> sb.append(" exact_match ASC")); + sorters.putAll(copy); } final List projects = this.projectsApiDAO.getProjects(seeHidden, this.getHangarUserId(), pagination, query); diff --git a/frontend/src/components/projects/DependencyTable.vue b/frontend/src/components/projects/DependencyTable.vue index ce58380c7..6f82f6eec 100644 --- a/frontend/src/components/projects/DependencyTable.vue +++ b/frontend/src/components/projects/DependencyTable.vue @@ -71,7 +71,7 @@ function reset() { async function onSearch(val: string, index: number) { if (val) { - const projects = await useApi>(`projects?relevance=true&limit=25&offset=0&q=${val.replace("/", " ")}`); + const projects = await useApi>(`projects?limit=25&offset=0&q=${val.replace("/", " ")}`); completionResults.value[index] = projects.result .filter((p) => p.namespace.owner !== route.params.user || p.namespace.slug !== route.params.project) .map((p) => p.namespace); diff --git a/frontend/src/i18n/locales/en.json b/frontend/src/i18n/locales/en.json index bd644f366..4d8efe749 100644 --- a/frontend/src/i18n/locales/en.json +++ b/frontend/src/i18n/locales/en.json @@ -49,7 +49,6 @@ "clear": "(clear)", "query": "Search in {0} projects...", "sortBy": "Sort by", - "relevanceSort": "Sort by relevance", "noProjects": "There are no projects. 😢", "noProjectsFound": "Found 0 projects. 😢", "title": "Find your favorite plugins",