The Free Software Media System - Server Backend & API
update name sorting
Luke Pulverenticc20c8d7d6c8
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.csindex c9fa1cf79d..995480535d 100644--- a/MediaBrowser.Controller/Entities/BaseItem.cs+++ b/MediaBrowser.Controller/Entities/BaseItem.cs@@ -20,9 +20,11 @@ using System.Globalization;using System.IO;using System.Linq;using System.Runtime.Serialization;+using System.Text;using System.Threading;using System.Threading.Tasks;using CommonIO;+using MediaBrowser.Controller.Sorting;using MediaBrowser.Model.LiveTv;namespace MediaBrowser.Controller.Entities@@ -299,6 +301,40 @@ namespace MediaBrowser.Controller.Entities}}+ private List<Tuple<StringBuilder,bool>> GetSortChunks(string s1)+ {+ var list = new List<Tuple<StringBuilder, bool>>();++ int thisMarker = 0, thisNumericChunk = 0;++ while ((thisMarker < s1.Length))+ {+ if (thisMarker >= s1.Length)+ {+ break;+ }+ char thisCh = s1[thisMarker];++ StringBuilder thisChunk = new StringBuilder();++ while ((thisMarker < s1.Length) && (thisChunk.Length == 0 || SortHelper.InChunk(thisCh, thisChunk[0])))+ {+ thisChunk.Append(thisCh);+ thisMarker++;++ if (thisMarker < s1.Length)+ {+ thisCh = s1[thisMarker];+ }+ }++ var isNumeric = thisChunk.Length > 0 && char.IsDigit(thisChunk[0]);+ list.Add(new Tuple<StringBuilder, bool>(thisChunk, isNumeric));+ }++ return list;+ }+/// <summary>/// This is just a helper for convenience/// </summary>@@ -484,7 +520,7 @@ namespace MediaBrowser.Controller.Entities{return System.IO.Path.Combine(basePath, "channels", ChannelId, Id.ToString("N"));}-+var idString = Id.ToString("N");basePath = System.IO.Path.Combine(basePath, "library");@@ -527,7 +563,32 @@ namespace MediaBrowser.Controller.Entitiessortable = sortable.Remove(sortable.Length - (searchLower.Length + 1));}}- return sortable;+ return ModifySortChunks(sortable);+ }++ private string ModifySortChunks(string name)+ {+ var chunks = GetSortChunks(name);++ var builder = new StringBuilder();++ foreach (var chunk in chunks)+ {+ var chunkBuilder = chunk.Item1;++ // This chunk is numeric+ if (chunk.Item2)+ {+ while (chunkBuilder.Length < 10)+ {+ chunkBuilder.Insert(0, '0');+ }+ }++ builder.Append(chunkBuilder);+ }+ Logger.Debug("ModifySortChunks Start: {0} End: {1}", name, builder.ToString());+ return builder.ToString();}[IgnoreDataMember]@@ -1146,7 +1207,7 @@ namespace MediaBrowser.Controller.Entities{return false;}-+return ConfigurationManager.Configuration.SaveLocalMeta;}diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csprojindex 8941e5384b..6f429ed2fc 100644--- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj+++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj@@ -331,6 +331,7 @@<Compile Include="Security\IEncryptionManager.cs" /><Compile Include="Session\AuthenticationRequest.cs" /><Compile Include="Social\ISharingManager.cs" />+ <Compile Include="Sorting\SortHelper.cs" /><Compile Include="Subtitles\ISubtitleManager.cs" /><Compile Include="Subtitles\ISubtitleProvider.cs" /><Compile Include="Providers\ItemIdentifier.cs" />diff --git a/MediaBrowser.Controller/Sorting/SortHelper.cs b/MediaBrowser.Controller/Sorting/SortHelper.csnew file mode 100644index 0000000000..95a3c26c48--- /dev/null+++ b/MediaBrowser.Controller/Sorting/SortHelper.cs@@ -0,0 +1,31 @@+using System;+using System.Collections.Generic;+using System.Linq;+using System.Text;+using System.Threading.Tasks;++namespace MediaBrowser.Controller.Sorting+{+ public static class SortHelper+ {+ private enum ChunkType { Alphanumeric, Numeric };++ public static bool InChunk(char ch, char otherCh)+ {+ var type = ChunkType.Alphanumeric;++ if (char.IsDigit(otherCh))+ {+ type = ChunkType.Numeric;+ }++ if ((type == ChunkType.Alphanumeric && char.IsDigit(ch))+ || (type == ChunkType.Numeric && !char.IsDigit(ch)))+ {+ return false;+ }++ return true;+ }+ }+}diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.csindex 19185e9659..8a679eb056 100644--- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs+++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs@@ -79,7 +79,7 @@ namespace MediaBrowser.Server.Implementations.Persistenceprivate IDbCommand _updateInheritedRatingCommand;- private const int LatestSchemaVersion = 49;+ private const int LatestSchemaVersion = 50;/// <summary>/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.diff --git a/MediaBrowser.Server.Implementations/Sorting/AlphanumComparator.cs b/MediaBrowser.Server.Implementations/Sorting/AlphanumComparator.csindex b76bf0a9cd..232bdb3b58 100644--- a/MediaBrowser.Server.Implementations/Sorting/AlphanumComparator.cs+++ b/MediaBrowser.Server.Implementations/Sorting/AlphanumComparator.cs@@ -1,30 +1,11 @@using System.Collections.Generic;using System.Text;+using MediaBrowser.Controller.Sorting;namespace MediaBrowser.Server.Implementations.Sorting{public class AlphanumComparator : IComparer<string>{- private enum ChunkType { Alphanumeric, Numeric };-- private static bool InChunk(char ch, char otherCh)- {- var type = ChunkType.Alphanumeric;-- if (char.IsDigit(otherCh))- {- type = ChunkType.Numeric;- }-- if ((type == ChunkType.Alphanumeric && char.IsDigit(ch))- || (type == ChunkType.Numeric && !char.IsDigit(ch)))- {- return false;- }-- return true;- }-public static int CompareValues(string s1, string s2){if (s1 == null || s2 == null)@@ -51,7 +32,7 @@ namespace MediaBrowser.Server.Implementations.SortingStringBuilder thisChunk = new StringBuilder();StringBuilder thatChunk = new StringBuilder();- while ((thisMarker < s1.Length) && (thisChunk.Length == 0 || InChunk(thisCh, thisChunk[0])))+ while ((thisMarker < s1.Length) && (thisChunk.Length == 0 || SortHelper.InChunk(thisCh, thisChunk[0]))){thisChunk.Append(thisCh);thisMarker++;@@ -62,7 +43,7 @@ namespace MediaBrowser.Server.Implementations.Sorting}}- while ((thatMarker < s2.Length) && (thatChunk.Length == 0 || InChunk(thatCh, thatChunk[0])))+ while ((thatMarker < s2.Length) && (thatChunk.Length == 0 || SortHelper.InChunk(thatCh, thatChunk[0]))){thatChunk.Append(thatCh);thatMarker++;diff --git a/MediaBrowser.Server.Implementations/Sorting/SeriesSortNameComparer.cs b/MediaBrowser.Server.Implementations/Sorting/SeriesSortNameComparer.csindex 09612a49c9..4efc3218b2 100644--- a/MediaBrowser.Server.Implementations/Sorting/SeriesSortNameComparer.cs+++ b/MediaBrowser.Server.Implementations/Sorting/SeriesSortNameComparer.cs@@ -16,7 +16,7 @@ namespace MediaBrowser.Server.Implementations.Sorting/// <returns>System.Int32.</returns>public int Compare(BaseItem x, BaseItem y){- return AlphanumComparator.CompareValues(GetValue(x), GetValue(y));+ return string.Compare(GetValue(x), GetValue(y), StringComparison.CurrentCultureIgnoreCase);}private string GetValue(BaseItem item)diff --git a/MediaBrowser.Server.Implementations/Sorting/SortNameComparer.cs b/MediaBrowser.Server.Implementations/Sorting/SortNameComparer.csindex 389b21ba78..873753a2b2 100644--- a/MediaBrowser.Server.Implementations/Sorting/SortNameComparer.cs+++ b/MediaBrowser.Server.Implementations/Sorting/SortNameComparer.cs@@ -18,12 +18,7 @@ namespace MediaBrowser.Server.Implementations.Sorting/// <returns>System.Int32.</returns>public int Compare(BaseItem x, BaseItem y){- if (!x.EnableAlphaNumericSorting || !y.EnableAlphaNumericSorting)- {- return string.Compare(x.SortName, y.SortName, StringComparison.CurrentCultureIgnoreCase);- }-- return AlphanumComparator.CompareValues(x.SortName, y.SortName);+ return string.Compare(x.SortName, y.SortName, StringComparison.CurrentCultureIgnoreCase);}/// <summary>