Search code examples
dotnetnuke2sxc

2sxc blog app posts and DNN search


While using the 2sxc blog app, i noticed that the DNN search results shows all the post but the link of the post title is the main Blog page and not the actual post link.

Example search results show:

Page title: I am a post title

Link for the above title is: /blog

When it should be: /blog/post/i-am-a-post-title

Managed to modify the search result by adding the following to the cshtml code:

@using ToSic.Eav.DataSources
@using ToSic.SexyContent.Search
@using DotNetNuke.Entities.Modules

@functions{

    // Prepare the data - get all categories through the pipeline

    public override void CustomizeData()
    {

    }

    /// <summary>

    /// Populate the search - ensure that each entity has an own url/page

    /// </summary>

    /// <param name="searchInfos"></param>

    /// <param name="moduleInfo"></param>

    /// <param name="startDate"></param>

    public override void CustomizeSearch(Dictionary<string, List<ISearchInfo>> searchInfos, ModuleInfo moduleInfo, DateTime startDate)
    {

        foreach (var si in searchInfos["Default"])
        {
            si.QueryString = "post=" + si.Entity.EntityId;
        }
    }
}

But rather than si.Entity.EntityId i want the UrlKey to show, any idea to how to that?


Solution

  • Simple - just convert to a DynamicEntity - https://github.com/2sic/2sxc/wiki/DotNet-DynamicEntity:

        foreach (var si in searchInfos["Default"])
        {
            si.QueryString = "post=" + AsDynamic(si.Entity).UrlKey;
        }
    

    Love from Switzerland :) PS: Pls mark as answered if this fixed your issue