Search code examples
dotnetnuke2sxc

How do I get DNN Search results to display links to articles with a 2sxc app?


I have a 2sxc app that is a list of resources. It has a listing and each item goes to a details view that has a unique URL based on the title. (The URL field is a field in the content type). Something like this domain.com/resources/details/my-amazing-resource.

When a user searches the site for "amazing", the core DNN search results module displays the results of the app, including the "My Amazing Resource" item, but it doesn't actually link to domain.com/resources/details/my-amazing-resource. It just links to domain.com/resources/.

How can I make it so the search results actually point to the unique URL of the item in the app? Is this possible? Would DNNSharp Search Boost be better for this than the core DNN search module?


Solution

  • Using Jeremy and Daniel's suggestions, I ultimately updated my _resourcelist.cshtml file to have code that looks like this:

    @inherits ToSic.Sxc.Dnn.RazorComponent
    @using ToSic.Razor.Blade;
    @using ToSic.Eav.Run;
    @using ToSic.Sxc.Dnn.Run;
    @using ToSic.Sxc.Search;
    @functions
    {
        /// <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<ISearchItem>> searchInfos, IContainer moduleInfo, DateTime beginDate)
        {
            foreach (var si in searchInfos["Default"])
            {
                // tell the search system what url it should use in the result
                si.QueryString = "resource/" + AsDynamic(si.Entity).Link;
            }
        }
    }