ProNotion
12/05/2024, 12:23 PMcsharp
public class ReleaseDateSort : ISortHandler
{
private const string SortOptionSpecifier = "releaseDate:";
/// <inheritdoc />
public bool CanHandle(string query)
=> query.StartsWith(SortOptionSpecifier, StringComparison.OrdinalIgnoreCase);
public SortOption BuildSortOption(string sort)
{
var sortDirection = sort.Substring(SortOptionSpecifier.Length);
return new SortOption
{
FieldName = ReleaseDateSortIndexer.FieldName,
Direction = sortDirection.StartsWith("asc", StringComparison.OrdinalIgnoreCase)
? Direction.Ascending
: Direction.Descending
};
}
}
However, my sort does not appear to be applied. I am passing it as releaseDate:asc
. My breakpoint is hit in the BuildSortOption
method of my ISortHandler
implementation. Am I missing something?ProNotion
12/05/2024, 12:24 PMcsharp
public sealed class ReleaseDateSortIndexer : IContentIndexHandler
{
internal const string FieldName = "releaseDate";
/// <inheritdoc />
public IEnumerable<IndexFieldValue> GetFieldValues(IContent content, string? culture)
{
var releaseDate = content.GetValue<DateTime?>(FieldName);
if (releaseDate.HasValue)
{
return [new IndexFieldValue
{
FieldName = FieldName,
Values = [releaseDate]
}
];
}
if (content.PublishDate.HasValue)
{
return
[
new IndexFieldValue
{
FieldName = FieldName,
Values = [content.PublishDate]
}
];
}
return [];
}
/// <inheritdoc />
public IEnumerable<IndexField> GetFields() =>
[
new()
{
FieldName = FieldName, FieldType = FieldType.Date, VariesByCulture = false
}
];
}
ProNotion
12/06/2024, 4:33 PM