SaaS CMS has officially launched! Learn more now.

Sorting by publish date doesn't work



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)

Using Search:

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?

Mar 28, 2018 15:05

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.

Mar 28, 2018 18:20
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.