1

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;
        }
    }
}
DNNdiva
  • 25
  • 6

1 Answers1

0

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 ;)

iJungleBoy
  • 5,325
  • 1
  • 9
  • 21
  • Too large for the number of characters here... So... https://2sxclog--dnndiva.repl.co/001.html I did run a reindex just in case. – DNNdiva Aug 14 '19 at 22:40
  • So the query looks correct. What did you get upon re-indexing? does it show up correctly now? – iJungleBoy Aug 19 '19 at 10:00
  • This is what shows after re-indexing. But the search is still returning the results of the help page (blog home) plus each article, while I'd like the results only for each articles. – DNNdiva Aug 20 '19 at 21:25
  • Just so I'm sure I understand - you now get the correct hits + the home (which you would like removed) - is this right? – iJungleBoy Aug 22 '19 at 09:32
  • I always got the correct hits (as in all the articles), but what I do not want the blog home listing items being returned on the search. See: https://2sxclog--dnndiva.repl.co/002.html – DNNdiva Aug 23 '19 at 18:49
  • That's good then. The main hits are still there, because we only modified the SearchIndex stream (containing everything), but the top 10 or so are also in the default-stream, which are still indexed. Best remove that stream, probably something like `searchInfos.Remove("Default")` and maybe 2-3 other streams. – iJungleBoy Aug 26 '19 at 08:15
  • OMGourd! It worked! You rock so so much, iJungleBoy! For the newbies out there... As suggested I added the line `searchInfos.Remove("Default");` just above the si.QueryString line. Like so: https://2sxclog--dnndiva.repl.co/003.html – DNNdiva Aug 26 '19 at 19:15
  • Note that I would put it before the foreach-line or after the {} of the foreach, as it doesn't need to be looped many times :) – iJungleBoy Aug 27 '19 at 12:07
  • Oh, much better. Thanks. I updated the code on the sample. =) – DNNdiva Aug 27 '19 at 17:12