简体   繁体   English

2sxc 博客应用帖子和 DNN 搜索

[英]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.在使用 2sxc 博客应用程序时,我注意到 DNN 搜索结果显示了所有帖子,但帖子标题的链接是主博客页面,而不是实际的帖子链接。

Example search results show:示例搜索结果显示:

Page title: I am a post title页面标题:我是帖子标题

Link for the above title is: /blog上面标题的链接是: /blog

When it should be: /blog/post/i-am-a-post-title什么时候应该是: /blog/post/i-am-a-post-title

Managed to modify the search result by adding the following to the cshtml code:通过将以下内容添加到 cshtml 代码中,设法修改了搜索结果:

@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?但我希望显示UrlKey而不是si.Entity.EntityId ,有什么想法吗?

Simple - just convert to a DynamicEntity - https://github.com/2sic/2sxc/wiki/DotNet-DynamicEntity :简单 - 只需转换为 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来自瑞士的爱 :) PS:如果这解决了您的问题,请标记为已回答

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.使 searchInfo 成为一个动态实体后,像“Title”这样的属性就起作用了。 But the property "UrlKey" doesn't work.但是属性“UrlKey”不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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