How do you apply a DateTime
field comparison in Sitecore using the Sitecore.ContentSearch
SDK?
The ContentSearchResult[string key]
function always returns a string which cannot be cast into a DateTime
for comparisons.
The solution to this is to use the following function overload:
ContentSearchResult[ObjectIndexerKey key]
.
Example Query:
queryable = queryable.Where(p =>
((DateTime)p[(ObjectIndexerKey)"Date"]) > lastWeek.Boost(4f)
);
Note: The boost above does not appear to be translated in the query