Take the community feedback survey now.

Sort a combined list of search hits from both WebContent and EPiServer content on Publish Date

Vote:
 

We are trying to help a customer who has a CMS 11 implementation with Search and Navigation (EPiServer.Find 13.6.0), using UnifiedSearch.

In addition to EPiServer content, they have a connector that crawls a server with documents, of which most have a publish date specified in the metadata. We can see that the date is included in the metadata in the indexed WebContent documents.

Now they want to sort this mixed list of data consisting of search hits based on both WebContent and PageData by publish date, and that is when we run into problems. 

The StartPublish value for WebContent is the date when it was indexed by the crawler, not the publishdate of the original document.

We tried adding a key "date" to the metadata when indexing PageData, but the existing metadata is then overwritten.

SearchClient.Instance.Conventions.UnifiedSearchRegistry.ForInstanceOf<PageData>()
   .ProjectMetaDataFrom(page =>
   new Dictionary<string, EPiServer.Find.IndexValue>
   {
       { "date", new EPiServer.Find.IndexValue(page.StartPublish.ToString()) }
   });

And also tried projecting the value from the "date" key to the a StartPublish field to the WebContent, but the value for PublishDate is not set.
We tried both IndexProjectionBuilder and HitProjectionBuilder with no luck. 
An example of the attempt with IndexProjectionBuilder:

SearchClient.Instance.Conventions.UnifiedSearchRegistry.AddIndexProjectionCustomization(
    typeof(WebContent),
    builder => new IndexProjectionBuilder(builder, projection =>
    {
        projection.PublishDateProjection =
         (Expression<Func<WebContent, DateTime?>>)(p =>
          p.SearchMetaData != null
          && p.SearchMetaData.ContainsKey("date")
          && p.SearchMetaData["date"] != null
           ? p.SearchMetaData["date"].DateTimeValue
           : null);
    })
);

Has anyone managed to find a way to sort a combined list of search hits from both WebContent and EPiServer content on publish date?

EPiServer.Find 13.6.0 (UnifiedSearch)
EPiServer.CMS 11.21.3

#340821
Edited, Oct 22, 2025 13:58
* 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.