SearchClient.Instance.Search<Events>()
.Filter(x => x.StartDate.MatchDay(DateTime.Today.Year,
DateTime.Today.Month,
DateTime.Today.Day))
.GetResult();
Great, but x.StartDate is nullable (i.e. of type DateTime?) and MatchDay() is only available for the non-nullable DateTime.
If anyone could explain why the code in my first post does not work, it would make me really happy! :-)
It seems that epifind cannot handle .Value
Can you try the following code:
public static FilterExpression<DateTime?> AsDateMatch(this DateTime? value, DateTime matchValue)
{
var minValue = new DateTime(matchValue.Year, matchValue.Month, matchValue.Day, 0, 0, 0);
var maxValue = new DateTime(matchValue.Year, matchValue.Month, matchValue.Day, 23, 59, 59);
return new FilterExpression<DateTime?>(x => x.Exists() & x.InRange(minValue, maxValue));
}
Ok, I think I know why the original code doesn't work.
First, I've indexed the following object:
public class Event
{
public string Title { get; set; }
public DateTime? StartDate { get; set; }
}
Then I opened epifind index, and noticed that StartDate field is indexed as StartDate$$date
Then I used Fiddler to see all requests that are sent to epifind, and noticed that x.Value.Date.Match(matchValue) generates the following query:
"term":{"StartDate.Value$$date":"2016-03-02T23:00:00Z"}
Since StartDate.Value$$date field doesn't exist, we're getting no hits.
Hope this helps!
I need to filter only events that starts today, ignoring the time of day. I have tried with the following extension method:
...but this does not work. It seems that x.Value.Date.Match(matchValue) are not allowed.
I use the extension method like this: