Skip to content
This repository has been archived by the owner on Oct 31, 2022. It is now read-only.

Commit

Permalink
Add Ascending sort order; Fixes #106
Browse files Browse the repository at this point in the history
  • Loading branch information
Saalvage authored and uwlnf committed Aug 31, 2022
1 parent 0ae178c commit ba690e7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Backend/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private IEnumerable<WebserviceEntry> 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();
Expand Down
2 changes: 1 addition & 1 deletion Models/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static Func<WebserviceEntry, double> 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)),
};
Expand Down
3 changes: 2 additions & 1 deletion Models/WseSearchParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public record WseSearchParameters(
bool? HasBookmark,
ISet<Tag>? Tags,
StarCount MinReviewAvg,
Order Order
Order Order,
bool Ascending
);

0 comments on commit ba690e7

Please sign in to comment.