diff options
| author | dkanada <dkanada@users.noreply.github.com> | 2020-03-23 02:30:41 +0900 |
|---|---|---|
| committer | Joshua M. Boniface <joshua@boniface.me> | 2020-03-22 15:25:11 -0400 |
| commit | da34bd940ea3681b9b6f872548933cf4c7d401f4 (patch) | |
| tree | cc2764b1c0feb5053fb3cbf8848c7627a15950ff /Emby.Server.Implementations | |
| parent | 54efde407330587c018ccc3530b17c66ab5cf41f (diff) | |
Merge pull request #2478 from JustAMan/fix-search-orderv10.5.2
Fix ordering of search results
(cherry picked from commit 0d9787dfb4445e837eaf801c366d4d61464564af)
Signed-off-by: Joshua M. Boniface <joshua@boniface.me>
Diffstat (limited to 'Emby.Server.Implementations')
| -rw-r--r-- | Emby.Server.Implementations/Data/SqliteItemRepository.cs | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index 44f38504a..0eb396af4 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -2914,29 +2914,30 @@ namespace Emby.Server.Implementations.Data private string GetOrderByText(InternalItemsQuery query) { var orderBy = query.OrderBy; - if (string.IsNullOrEmpty(query.SearchTerm)) + bool hasSimilar = query.SimilarTo != null; + bool hasSearch = !string.IsNullOrEmpty(query.SearchTerm); + + if (hasSimilar || hasSearch) { - int oldLen = orderBy.Count; - if (oldLen == 0 && query.SimilarTo != null) + List<(string, SortOrder)> prepend = new List<(string, SortOrder)>(4); + if (hasSearch) { - var arr = new (string, SortOrder)[oldLen + 2]; - orderBy.CopyTo(arr, 0); - arr[oldLen] = ("SimilarityScore", SortOrder.Descending); - arr[oldLen + 1] = (ItemSortBy.Random, SortOrder.Ascending); - query.OrderBy = arr; + prepend.Add(("SearchScore", SortOrder.Descending)); + prepend.Add((ItemSortBy.SortName, SortOrder.Ascending)); } - } - else - { - query.OrderBy = new[] + + if (hasSimilar) { - ("SearchScore", SortOrder.Descending), - (ItemSortBy.SortName, SortOrder.Ascending) - }; - } - + prepend.Add(("SimilarityScore", SortOrder.Descending)); + prepend.Add((ItemSortBy.Random, SortOrder.Ascending)); + } - if (orderBy.Count == 0) + var arr = new (string, SortOrder)[prepend.Count + orderBy.Count]; + prepend.CopyTo(arr, 0); + orderBy.CopyTo(arr, prepend.Count); + orderBy = query.OrderBy = arr; + } + else if (orderBy.Count == 0) { return string.Empty; } |
