Our sort order is not working correctly, and I found it’s because the solr query being generated ends with sort=date_tdts%20desc – when it should end with sort=date_tdt%20desc (note the extra ‘s’). But I’m not sure where this extra s is coming from in the code. This is the index field configuration:
[IndexField("date_tdt")]
public DateTime Date { get; set; }
Here is the code that generates the query:
var orderExpression = searchAdapter.MapFilterToOrder(query, out bool orderByDescending);
var resultsQueryable = providerSearchContext.GetQueryable<TSearchItem>()
.Where(basePredicate);
if(query.Filters != null)
{
var queryPredicate = CombinePredicates(query.Filters.Select(searchAdapter.MapFilterToPredicate));
resultsQueryable = resultsQueryable.Where(queryPredicate);
}
if (orderExpression != null)
{
resultsQueryable = orderByDescending
? resultsQueryable.OrderByDescending(orderExpression)
: resultsQueryable.OrderBy(orderExpression);
}
public virtual Expression<Func<ArticleSearchResultItem, object>> MapFilterToOrder(SearchQuery query,
out bool @descending)
{
@descending = true;
return x => x.Date;
}
why is it appending an s to date_tdt?
The in the solution (not in Solr) needed to be updated so that it knew what type to treat the field as:
<contentSearch>
<indexConfigurations>
<defaultSolrIndexConfiguration>
<fieldMap>
<fieldNames>
<field fieldName="date_tdt" returnType="datetime"></field>
</fieldNames>
</fieldMap>
</defaultSolrIndexConfiguration>
</indexConfigurations>
</contentSearch>