Search code examples
dotnetnuke2sxc

How to disable index searching on the list and just get the articles indexed on search results?


Using 2sxc Blogg App and when using search I get the results of the blog home page listed, which simply list the blog home and the article titles which all take the user to the blog home page, so they are pretty much useless links, then I get the actual articles with the links to the articles. So I need to suppress the blog page itself, but not its dynamic children (the articles).

/help <-- no, thanks, your links are useless.
/help/post <-- yes, please, list all.

Any idea on how I could achieve that? I got directed to CustomizeData() doc, but I have no idea what to do. The current one set on the main blog list page is as follows:

@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<ToSic.SexyContent.Search.ISearchInfo>> searchInfos, DotNetNuke.Entities.Modules.ModuleInfo moduleInfo, DateTime startDate)
    {
        foreach (var si in searchInfos["SearchIndex"])
        {
            si.QueryString = "post=" + AsDynamic(si.Entity).UrlKey;
        }
    }
}

Solution

  • welcome to StackOverflow ;)

    The basic DNN index asks each module for the data it has, and then builds the index on that. Since a module can have multiple items for the search, they are each an own "document" which can be configured - for example what URL to use in the search results. To enable view-developers to customize these things, 2sxc has this hook to customize the search results. So the way it's meant to work is...

    1. the backend collects the data
    2. then detects that the search index is being built (and not a user viewing the page)
    3. then call the code for optional reconfiguration
    4. then pass the items on to DNN search

    So what the code should do is take each item as it was prepared by the backend, change the url to use and then let the rest of the system do its magic. If this isn't working, there are a few possibilities:

    1. something in DNN or 2sxc is broken (I really hope that's not it)
    2. the code caused errors and since it happens in the background, you don't see it
    3. the data is not being passed to the code, for example because it was filtered out - for example, old data isn't updated in the index, because the indexer will ask for new data only, and therefor older data won't be updated on normal re-indexes, no matter how you update the code.

    Let's try to find out what the cause is

    1. open the app query https://azing.org/2sxc/r/T1GdqnNa and select the **Blog Posts for Home and Tags", and test-run the query to see if it gives you results. if not, something may be wrong with the query. In the json-looking test-results on the screen, do check if there is something in the set "SearchIndex" - this is the data stream that skips paging and returns all items. If this is empty, get back to us. Note: if you don't get any results, do check what Test-Parameters the query is using (box to the right), and maybe edit the ModuleId in case it's wrong
    2. check if you see any events in the DNN event-log. if you don't, make sure you re-index the whole data in DNN and check again.

    Post your results, so we can check how this can be fixed ;)