Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David Amri 214 posts 740 karma points
    Oct 25, 2017 @ 13:43
    David Amri
    0

    Combine examine search result

    Greetings,

    My content tree looks like this:

    • Main Content (with template)
      • Sub Content (no template)
      • Sub Content (no template)
      • Sub Content (no template)

    The sub content gets indexed but right now it will throw three "search results items" on my search page, one for each node. How would I combine these into the Main Content "search result item"?

    Cheers!

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Oct 25, 2017 @ 13:48
    Ismail Mayat
    100

    David,

    You need to implement gathering node data event. In the event for the current page that is being indexed if it has template (you could use some other criteria eg if page that has these non template child pages is of type x then you could test for that).

    If it does have template then get its child pages then get their content and put into new string the combined contents using stringbuilder then inject into the index for this page a new field. Call that field what ever you like then you can search on that field and you will get one result.

    Regards

    Ismial

  • David Amri 214 posts 740 karma points
    Oct 26, 2017 @ 06:51
    David Amri
    0

    Hi Ismail,

    Thank you, I will look it up. A quick question regarding the class files, I'm kind of new to Umbraco and I'm not really a developer, more of a designer, so bare with me. Where in the solution would it be appropriate to place my class files? Can I make a new folder for this or should these be placed inside some specific folder?

    Also, could you please post an example of what that code might look like?

    Best regards!

    David

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Oct 26, 2017 @ 07:59
    Ismail Mayat
    0

    David,

    Here is example of said class,

    public class ExamineEvents:IApplicationEventHandler
    {
        public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
    
        }
    
        public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            ExamineManager.Instance.IndexProviderCollection["ExternalIndexer"].GatheringNodeData +=
                ExternalIndexerGatheringNodeData;
    
    
        }
    
    
    
        private void ExternalIndexerGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            if (e.IndexType == IndexTypes.Content)
            {
                try
                {
                    e.Fields.Add("searchablePath", e.Fields["path"].Replace(",", " ")); //we can then search using language root node
                    var fields = e.Fields;
                    var combinedFields = new StringBuilder();
                    foreach (var keyValuePair in fields)
                    {
                        combinedFields.AppendLine(keyValuePair.Value);
                    }
                    e.Fields.Add("contents", combinedFields.ToString());
                }
                catch (Exception ex)
                {
                    LogHelper.Error<Exception>("error munging fields for " + e.NodeId, ex);
                }
            }
        }
    
        public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
    
        }
    }
    

    you need update the ExternalGatheringNodeData method and do your tests there then as I have done inject in a new field.

    Are you working on a site built by someone else? Or did you create this site fresh? You will also need visual studio to add this code.

    Regards

    Ismail

  • David Amri 214 posts 740 karma points
    Oct 26, 2017 @ 08:27
    David Amri
    0

    Thanks Ismail,

    I'm working on a inhouse project so I have access to everything and yes we are working with Visual Studio.

    Cheers!

    David

  • David Amri 214 posts 740 karma points
    Oct 30, 2017 @ 10:01
    David Amri
    0

    Hi Ismail,

    Thank's for all the help. I've managed to combine the fields but I have a couple of questions regarding this.

    In the combined field there is data like __Raw html data. Is it possible to exclude this, or any other from the combined field?

    Also do I have to exclude the nodes (the children nodes with no templates) in the search result with razor code or am I doing something wrong in GatheringNodeData code if I have to do this?

    Right now the parent of the children nodes with no templates will get the data from its children but I get the children as individual search results.

    Best regards

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Nov 01, 2017 @ 09:13
    Ismail Mayat
    0

    David,

    You will need to exclude them in the search. Not sure what you mean by __Raw fields are in combined field?

    Regards

    Ismail

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Oct 26, 2017 @ 08:32
    Ismail Mayat
    0

    David,

    What is the project structure in visual studio? Do you have web project and other projects for the other layers?

    Regards

    Ismail

  • David Amri 214 posts 740 karma points
    Oct 26, 2017 @ 09:15
    David Amri
    0

    It is a single web application project, no other projects share any data or files. The file structure looks like this:

    • Web application project
      • Properties
      • References
      • AppBrowsers
      • AppData
      • AppPlugins
      • bin
      • Config
      • css
      • img
      • js
      • Media
      • obj
      • scss
      • umbraco
      • umbracoclient
      • Views

    Best regards

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Oct 26, 2017 @ 09:20
    Ismail Mayat
    1

    You can then create class file and put it in app_code folder which you do not have but you can add it. When site loads it will run that class file

    Love you avatar btw big fan of street fighter prefer fighting with guile myself

  • David Amri 214 posts 740 karma points
    Oct 26, 2017 @ 11:00
    David Amri
    0

    Awsome, thanks Ismail!

    Yeah, nothing beats a good street fight! :D

    I get a compilation error. looks like "Helpers" does not exists in namespace "UmbracoSiteExtensions"?

    I've read that this is a custom addition namespace and this should work with v7.

    Best regards

    David

Please Sign in or register to post replies

Write your reply to:

Draft