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?
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");
}
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:
but am hoping there is a quicker way, say using xpath?
Thanks
J
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:
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:
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
Thanks Marc. Really useful.
Will look at this tomorrow.
J
There is also a helper method which is called "OfTypes()" where you can select the descendens of your home node by document type alias.
Also v useful - I had not noticed that
Thanks
J
is working on a reply...