简体   繁体   中英

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?

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

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

After making the searchInfo to be a dynamic entity, property like "Title" works. But the property "UrlKey" doesn't work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM