Compare commits

..

3 Commits

Author SHA1 Message Date
Benedek Farkas
9de766de29 #8879: Adding GetNullableDateTime to ISearchHit and LuceneSearchHit (#8883)
Some checks failed
Compile / Compile .NET solution (push) Has been cancelled
Compile / Compile Client-side Assets (push) Has been cancelled
SpecFlow Tests / SpecFlow Tests (push) Has been cancelled
Build Crowdin Translation Packages / build-crowdin-translation-packages (push) Has been cancelled
2026-01-09 15:13:43 +01:00
Benedek Farkas
f2f67d3c0b #8268: Removing obsolete TermPart.SortObsolete (and TermsComparer) from Taxonomies (#8887) 2026-01-09 14:09:51 +01:00
Benedek Farkas
1bd5d0a905 Modifying search settings deserialization to allow line breaks in the imported XML (#8882) 2026-01-09 13:06:45 +01:00
4 changed files with 13 additions and 84 deletions

View File

@@ -38,7 +38,7 @@ namespace Lucene.Models
public string GetString(string name)
{
var field = _doc.GetField(name);
return field == null ? null : field.StringValue;
return field?.StringValue;
}
public DateTime GetDateTime(string name)
@@ -46,5 +46,11 @@ namespace Lucene.Models
var field = _doc.GetField(name);
return field == null ? DateTime.MinValue : DateTools.StringToDate(field.StringValue);
}
public DateTime? GetNullableDateTime(string name)
{
var field = _doc.GetField(name);
return field == null ? default(DateTime?) : DateTools.StringToDate(field.StringValue);
}
}
}

View File

@@ -18,12 +18,13 @@ namespace Orchard.Search.Helpers
foreach (var item in items)
{
var pair = item.Split(new[] { ':' }, StringSplitOptions.None);
var index = pair[0];
var fields = pair[1].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var pair = item.Split(new[] { ':' });
var index = pair[0].Trim();
var fields = pair[1].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray();
dictionary[index] = fields;
}
return dictionary;
}

View File

@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
@@ -83,83 +82,5 @@ namespace Orchard.Taxonomies.Models
{
return terms.OrderBy(term => term.FullWeight);
}
[Obsolete]
public static IEnumerable<TermPart> SortObsolete(IEnumerable<TermPart> terms)
{
var list = terms.ToList();
var index = list.ToDictionary(x => x.FullPath);
return list.OrderBy(x => x, new TermsComparer(index));
}
[Obsolete]
private class TermsComparer : IComparer<TermPart>
{
private readonly IDictionary<string, TermPart> _index;
public TermsComparer(IDictionary<string, TermPart> index)
{
_index = index;
}
public int Compare(TermPart x, TermPart y)
{
// if two nodes have the same parent, then compare by weight, then by path
// /1/2/3 vs /1/2/4 => 3 vs 4
if (x.Path == y.Path)
{
var weight = y.Weight.CompareTo(x.Weight);
if (weight != 0)
{
return weight;
}
// if same parent path and same weight, compare by name
return string.Compare(x.Name, y.Name, StringComparison.OrdinalIgnoreCase);
}
// if two nodes have different parents
// if the two nodes have the same root, the deeper is after (i.e. one starts with the other)
// /1/2 vs /1/2/3 => /1/2 first
if (x.FullPath.StartsWith(y.FullPath, StringComparison.OrdinalIgnoreCase))
{
return 1;
}
if (y.FullPath.StartsWith(x.FullPath, StringComparison.OrdinalIgnoreCase))
{
return -1;
}
// otherwise compare first none matching parent
// /1/2 vs /1/3 => 2 vs 3
// /2/3 vs /4 => 2 vs 4
var xPath = x.FullPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
var yPath = y.FullPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
string xFullPath = "", yFullPath = "";
for (var i = 0; i < Math.Min(xPath.Length, yPath.Length); i++)
{
xFullPath += "/" + xPath[i];
yFullPath += "/" + yPath[i];
if (!xFullPath.Equals(yFullPath, StringComparison.OrdinalIgnoreCase))
{
var xParent = _index[xFullPath];
var yParent = _index[yFullPath];
return Compare(xParent, yParent);
}
}
return 0;
}
}
}
}
}

View File

@@ -11,5 +11,6 @@ namespace Orchard.Indexing
bool GetBoolean(string name);
string GetString(string name);
DateTime GetDateTime(string name);
DateTime? GetNullableDateTime(string name);
}
}