update name sorting
This commit is contained in:
parent
7aa85fc8dd
commit
cc20c8d7d6
|
@ -20,9 +20,11 @@ using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CommonIO;
|
using CommonIO;
|
||||||
|
using MediaBrowser.Controller.Sorting;
|
||||||
using MediaBrowser.Model.LiveTv;
|
using MediaBrowser.Model.LiveTv;
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.Entities
|
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>
|
/// <summary>
|
||||||
/// This is just a helper for convenience
|
/// This is just a helper for convenience
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -484,7 +520,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
{
|
{
|
||||||
return System.IO.Path.Combine(basePath, "channels", ChannelId, Id.ToString("N"));
|
return System.IO.Path.Combine(basePath, "channels", ChannelId, Id.ToString("N"));
|
||||||
}
|
}
|
||||||
|
|
||||||
var idString = Id.ToString("N");
|
var idString = Id.ToString("N");
|
||||||
|
|
||||||
basePath = System.IO.Path.Combine(basePath, "library");
|
basePath = System.IO.Path.Combine(basePath, "library");
|
||||||
|
@ -527,7 +563,32 @@ namespace MediaBrowser.Controller.Entities
|
||||||
sortable = sortable.Remove(sortable.Length - (searchLower.Length + 1));
|
sortable = 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]
|
[IgnoreDataMember]
|
||||||
|
@ -1146,7 +1207,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ConfigurationManager.Configuration.SaveLocalMeta;
|
return ConfigurationManager.Configuration.SaveLocalMeta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -331,6 +331,7 @@
|
||||||
<Compile Include="Security\IEncryptionManager.cs" />
|
<Compile Include="Security\IEncryptionManager.cs" />
|
||||||
<Compile Include="Session\AuthenticationRequest.cs" />
|
<Compile Include="Session\AuthenticationRequest.cs" />
|
||||||
<Compile Include="Social\ISharingManager.cs" />
|
<Compile Include="Social\ISharingManager.cs" />
|
||||||
|
<Compile Include="Sorting\SortHelper.cs" />
|
||||||
<Compile Include="Subtitles\ISubtitleManager.cs" />
|
<Compile Include="Subtitles\ISubtitleManager.cs" />
|
||||||
<Compile Include="Subtitles\ISubtitleProvider.cs" />
|
<Compile Include="Subtitles\ISubtitleProvider.cs" />
|
||||||
<Compile Include="Providers\ItemIdentifier.cs" />
|
<Compile Include="Providers\ItemIdentifier.cs" />
|
||||||
|
|
31
MediaBrowser.Controller/Sorting/SortHelper.cs
Normal file
31
MediaBrowser.Controller/Sorting/SortHelper.cs
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -79,7 +79,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
private IDbCommand _updateInheritedRatingCommand;
|
private IDbCommand _updateInheritedRatingCommand;
|
||||||
|
|
||||||
private const int LatestSchemaVersion = 49;
|
private const int LatestSchemaVersion = 50;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
|
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
|
||||||
|
|
|
@ -1,30 +1,11 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using MediaBrowser.Controller.Sorting;
|
||||||
|
|
||||||
namespace MediaBrowser.Server.Implementations.Sorting
|
namespace MediaBrowser.Server.Implementations.Sorting
|
||||||
{
|
{
|
||||||
public class AlphanumComparator : IComparer<string>
|
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)
|
public static int CompareValues(string s1, string s2)
|
||||||
{
|
{
|
||||||
if (s1 == null || s2 == null)
|
if (s1 == null || s2 == null)
|
||||||
|
@ -51,7 +32,7 @@ namespace MediaBrowser.Server.Implementations.Sorting
|
||||||
StringBuilder thisChunk = new StringBuilder();
|
StringBuilder thisChunk = new StringBuilder();
|
||||||
StringBuilder thatChunk = 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);
|
thisChunk.Append(thisCh);
|
||||||
thisMarker++;
|
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);
|
thatChunk.Append(thatCh);
|
||||||
thatMarker++;
|
thatMarker++;
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace MediaBrowser.Server.Implementations.Sorting
|
||||||
/// <returns>System.Int32.</returns>
|
/// <returns>System.Int32.</returns>
|
||||||
public int Compare(BaseItem x, BaseItem y)
|
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)
|
private string GetValue(BaseItem item)
|
||||||
|
|
|
@ -18,12 +18,7 @@ namespace MediaBrowser.Server.Implementations.Sorting
|
||||||
/// <returns>System.Int32.</returns>
|
/// <returns>System.Int32.</returns>
|
||||||
public int Compare(BaseItem x, BaseItem y)
|
public int Compare(BaseItem x, BaseItem y)
|
||||||
{
|
{
|
||||||
if (!x.EnableAlphaNumericSorting || !y.EnableAlphaNumericSorting)
|
return string.Compare(x.SortName, y.SortName, StringComparison.CurrentCultureIgnoreCase);
|
||||||
{
|
|
||||||
return string.Compare(x.SortName, y.SortName, StringComparison.CurrentCultureIgnoreCase);
|
|
||||||
}
|
|
||||||
|
|
||||||
return AlphanumComparator.CompareValues(x.SortName, y.SortName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user