I have a problem with sorting my search results. Below you have two types of searching:
Using Unified search:
var unifiedSearch = searchClient.UnifiedSearch()
.OrderBy(x => x.SearchPublishDate)
var typeSearch = searchClient.Search()
.OrderBy(x => x.PublishDate).
IncludeType(x => new SearchViewModel
Name = x.Name,
PublishDate = x.StartPublish
In unified search everything works fine. My results are sorted by SearchPublishDate as expected. The problem is in the second query. It returns the same results as the first one but the order is different. It seems to be ordered by score instead of PublishDate. Any sugestions what am I doing wrong?
The problem is that the property PublishDate doesn't exist in the index. You ned to change your search to search for SitePageData instead, something like this:
var typeSearch = searchClient.Search<SitePageDatal>()
.OrderBy(x => x.StartPublish)
And then do the mapping to SearchViewModel or do a projection directly in the Find query by using the Select extension method.