Copied to clipboard

Flag this post as spam?

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


  • Ben Grice 24 posts 176 karma points
    Apr 27, 2016 @ 15:44
    Ben Grice
    0

    Examine search - searching and returning documents that don't have a template.

    Hi there, I am trying to configure my search to only return pages that actually have a template. Here is the structure - the nodes with a single * at the beginning/end do not have a template so cannot be rendered, however if picked up in a search I'd like their parent page (with a double **) to be returned:

    Home
        Working for Us
        Human Resources
            FAQs: Employees
                **Sickness Absence**
                    *Sickness Absence*
                        *Does the policy apply to me?*
                        *If I am unwell and unable what do I do?*
                        *Do I need to speak to my manager?*
                **Annual Leave**
                    *Annual Leave*
                        *Do I need to book in advance*
                        *Does the policy apply to me?*
    
        Finance
        Staff Development
            **FAQs:**
                *Learning and Development*
                    *How much does it cost*
                    *What support can I access?*
                    *How do I obtain information on the course?*
    

    My basic search of model.SearchResults = Umbraco.TypedSearch(query); is correctly finding the articles. The problem is that some of the articles don’t actually exists as pages, so I’d like the page returned in the result to be the parent of the result page (or, in some cases, the parent of the parent)

    At present, I don’t want to exclude any doc types from my search, nor do I think using umbracoNaviHide will do the job as I don’t want to exclude any pages.

    Is there a solution to what I am looking for here (e.g. Is there any way to check for something like Page.HasTemplate == false?) My C#/.Net skills are pretty good so I hopefully shouldn’t have any problem writing a detailed query in code if needs be, just finding it hard to work out the best way to achieve this in Umbraco. If it helps I can provide the full doc types of my structure above.

    Thanks in advance

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Apr 27, 2016 @ 19:01
    Dan Diplo
    0

    You can probably use the GatheringNodeData event to get the parent node and index that. See an example:

    http://staheri.com/my-blog/2015/march/custom-examine-indexing-using-umbraco-cache/

    Another alternative is to actually give the pages without a template a template - but have the template perform a redirect to the parent page. That way when the template appears in the search when you click it you get the parent page.

  • Ben Grice 24 posts 176 karma points
    May 23, 2016 @ 08:35
    Ben Grice
    100

    It appears that the results of an Umbraco.TypedSearch (IPublishedContent) do indeed have a TemplateId property. If TemplateId == 0, then no template exists.

    var themodel = new SearchModel { Query = query };
                        if (!string.IsNullOrEmpty(query))
                        {
                            themodel.SearchResults = Umbraco.TypedSearch(query);
                            if (themodel.SearchResults != null)
    
     foreach (var result in themodel.SearchResults)
                                    {
    
    if (result.TemplateId > 0)
    {
    

    If no template exists, then get the parent node

      else if (result.Parent.TemplateId > 0)
    

    May not be the most elaborate solution, but seems to do the job for me.

Please Sign in or register to post replies

Write your reply to:

Draft