Copied to clipboard

Flag this post as spam?

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


  • Jules 269 posts 560 karma points
    Nov 15, 2015 @ 00:30
    Jules
    0

    Quickest way to return list of nodes with specific doc types in large site

    Umbraco 7.2.6

    What is the quickest way in a large site (about 2000 nodes) to return a list of nodes that all have one of about 5 different doc types. Would need to search everything below the Home node.

    I could use TypedContent with something like:

    homeNode.Descendants().Where(n=>n.ContentType.Alias=="DocType1" && n.ContentType.Alias == "DocType2" && n. etc etc);
    

    but am hoping there is a quicker way, say using xpath?

    Thanks

    J

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Nov 15, 2015 @ 01:14
    Marc Goodson
    4

    Hi Jules

    There are a couple of helper methods that you could look at

    Umbraco.TypedContentAtXPath accepts an XPath, that could define your document type filter eg:

    var matchingPages = Umbraco.TypedContentAtXPath("//Home|//LandingPage");
    

    would find all documents with a document type alias of Home or LandingPage.

    However as a site gets larger, and because you mention the quickest way; you should also consider using Examine;

    There is an Umbraco.TypedSearch helper that returns an IEnumerable of IPublishedContent that accepts an Examine Search Criteria; so you could filter by the nodeTypeAlias index field eg:

    var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
        var criteria = searcher.CreateSearchCriteria(Examine.SearchCriteria.BooleanOperation.Or);
        var nodeTypeAliasList = new string[] {"Home","LandingPage"};
        var examineQuery = criteria.GroupedOr(new string[]{"nodeTypeAlias"}, nodeTypeAliasList);    
        var examineMatchingPages = Umbraco.TypedSearch(examineQuery.Compile());
    

    In your development site if you have compilation debug set to true; you can access the MiniProfiler by adding ?umbDebug=true on the querystring; if you wrap both these versions of filtering your content in a disposable timer object, you will be able to see in the miniprofiler which is the fastest for your content structure...

    eg

    var matchingPages = default(IEnumerable<IPublishedContent>);
    using (DisposableTimer.DebugDuration<UmbracoTemplatePage>("Measuring Using TypedContentByXPath"))
    {   
        matchingPages = Umbraco.TypedContentAtXPath("//Home|//LandingPage");
    }
    

    enter image description here

  • Jules 269 posts 560 karma points
    Nov 15, 2015 @ 21:33
    Jules
    0

    Thanks Marc. Really useful.

    Will look at this tomorrow.

    J

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Nov 16, 2015 @ 06:13
    David Brendel
    1

    There is also a helper method which is called "OfTypes()" where you can select the descendens of your home node by document type alias.

  • Jules 269 posts 560 karma points
    Nov 16, 2015 @ 11:04
    Jules
    0

    Also v useful - I had not noticed that

    Thanks

    J

Please Sign in or register to post replies

Write your reply to:

Draft