A critical vulnerability was discovered in React Server Components (Next.js). Our Systems Remain Fully Protected. Learn More.
AI OnAI Off
A critical vulnerability was discovered in React Server Components (Next.js). Our Systems Remain Fully Protected. Learn More.
You will need a client convention right?
//using EPiServer.Find.ClientConventions; client.Conventions.ForInstancesOf<Event>() .IncludeField(x => x.StartDates);
Can you check the index and verify that StartDate is part of the index? (ref the Ignore attribute on your property).
Yes, I have StartDates of my events indexed
"StartDates": [
"2016-12-10T03:00:00Z",
"2016-11-11T11:00:00Z",
"2016-11-15T17:00:00Z"
],
Maybe new extension with GetClosestStartDate() on event class that returns a single start date and index that instead?
Hi Daniel,
I cannot do that because ClosestDate on the time of indexing may be different than the closest date on the time of querying.
My final solution is:
1. Add NestedConvention in initialization module:
SearchClient.Instance.Conventions.NestedConventions.ForInstancesOf<Event>().Add(t => t.StartDatesForIndexing);
2. Create custom class because you signature for Add method is
Expression<Func<TSource, IEnumerable<TListItem>>> expr) where TListItem : class;
my custom class:
[JsonObject]
public class DateIndexCustom
{
[JsonProperty]
public DateTime StartDateForIndexing { get; set; }
}
and property in Event class:
[Ignore]
public virtual DateIndexCustom[] StartDatesForIndexing
{
get
{
var dates = Times?.FilteredItems
?.Select(x => x.GetContent())
.Where(b => b != null)
.OfType<EventInfoBaseBlock>()
.DefaultIfEmpty(new CourseInfoBlock { StartDate = DateTime.MinValue })
.Select(x => new DateIndexCustom { StartDateForIndexing = x.StartDate }).ToArray()
?? new[] { new DateIndexCustom { StartDateForIndexing = DateTime.MinValue } };
return dates;
}
}
3. query looks similar to my initial one:
query = query.OrderBy(d => d.StartDatesForIndexing, st => st.StartDateForIndexing, st => st.StartDateForIndexing.GreaterThan(hideBefore));
4. I reindexed all content
I have some difficulties in doing the sorting in Find.
I have the following structure:
class TimeBlock
{
DateTime StartDate
}
class Event
{
ContentArea Times
}
The goal is to sort events by closest future (more than DateTime.Now + x hours) StartDate of their TimeBlocks.
I tried to index all StartDates like this:
and then do the ordering
but I get an exception “No mapping found for [StartDates.$$date] in order to sort on”
I'll be grateful for any help.