From ba690e78ffc8af235f9d478b82ac2e6ddd680dec Mon Sep 17 00:00:00 2001 From: Salvage <29021710+Saalvage@users.noreply.github.com> Date: Tue, 30 Aug 2022 17:10:07 +0200 Subject: [PATCH] Add Ascending sort order; Fixes #106 --- Backend/Controllers/SearchController.cs | 2 +- Models/Order.cs | 2 +- Models/WseSearchParameters.cs | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Backend/Controllers/SearchController.cs b/Backend/Controllers/SearchController.cs index 59a9ae9..a81e554 100644 --- a/Backend/Controllers/SearchController.cs +++ b/Backend/Controllers/SearchController.cs @@ -24,7 +24,7 @@ private IEnumerable GetBaseWses(WseSearchParameters parameters) .AsEnumerable() .Select(x => (wse: x, score: parameters.Order.GetMapper().Invoke(x) * (parameters.Query == null ? 1 : FuzzingService.CalculateScore1(parameters.Query, x)))) - .OrderByDescending(x => x.score) + .OrderBy(x => parameters.Ascending ? x.score : -x.score) .TakeWhile(x => parameters.Query == null || x.score > 0.05) .Select(x => { x.wse.ChangeLog = x.score.ToString(); diff --git a/Models/Order.cs b/Models/Order.cs index 66eacb7..84e0eb2 100644 --- a/Models/Order.cs +++ b/Models/Order.cs @@ -16,7 +16,7 @@ public static Func GetMapper(this Order order) (double)x.ViewCount / (DateTimeOffset.UtcNow - x.CreatedAt).Ticks * (x.Reviews.Any() ? x.Reviews.Average(y => (int)y.StarCount) : 2.5), Order.ViewCount => x => x.ViewCount, - Order.ReviewAverage => x => (x.Reviews.Any() ? x.Reviews.Average(y => (int)y.StarCount) : 2.5), + Order.ReviewAverage => x => x.Reviews.Any() ? x.Reviews.Average(y => (int)y.StarCount) : 2.5, Order.Recency => x => x.CreatedAt.UtcTicks, _ => throw new InvalidEnumArgumentException(nameof(order), (int)order, typeof(Order)), }; diff --git a/Models/WseSearchParameters.cs b/Models/WseSearchParameters.cs index 16d80af..cd522ca 100644 --- a/Models/WseSearchParameters.cs +++ b/Models/WseSearchParameters.cs @@ -6,5 +6,6 @@ public record WseSearchParameters( bool? HasBookmark, ISet? Tags, StarCount MinReviewAvg, - Order Order + Order Order, + bool Ascending );