and that will give me IPublishedContent which is what I need. I read a few posts on the forum saying that uQuery was no longer the way to go I haven't found exactly how to do it simply with the methods described in the MVC docs : http://our.umbraco.org/documentation/reference/Templating/Mvc/querying
TypedContentAtRoot returns an IEnumerable which makes it harder to query all the nodes on my site using that method (though not impossible at all. Only that my code is nowhere near as clear as the uQuery version).
I also tried the Examine route and ended up with :
var criteria = ExamineManager.Instance.SearchProviderCollection["MySearcher"].CreateSearchCriteria("content"); var filter = criteria.NodeTypeAlias("docTypeAlias") .And() .Field("propAlias", id.ToString()); UmbracoHelper helper = new UmbracoHelper(UmbracoContext.Current); var results = helper.TypedSearch(filter.Compile());
Once again, this works fine. I like it a bit less because I have to convert my query (id) to a string but it also works. I only have a limited amount of data I can test on so I don't know if I should consider speed in my how I will do it. And if I do, which way should I go.
I will have ~5000 nodes that I will be querying on.
uQuery and INode are essentially obsolete, you should be using IPublishedContent everywhere. There might be some extension methods that need to be created on top of IPublishedContent for making things this like this a bit simpler.
The query you are trying to execute is a fairly intensive one with 5000+ nodes. Is there a reason you need to query your whole site for nodes of a specific type?
Using Examine will have the fastest execution time for something like this.
Here's an extension method you could create (we'll add this to the core) for acheiving this with IPublishedContent:
Also note that in nearly all base classes that are shipped with Umbraco including controllers, views, etc... we always expose an Umbraco helper already, you generally don't have to create one yourself. In UmbracoTemplatePage and UmbracoViewPage
I am building an archive for a publication that has a fairly big archive (5000 or so articles). Each article is a node in my Umbraco site. I want to be able to navigate the archives using different methods. For example, using a "Category" (which is a field in my "Article" Document Type). This is not the only criteria but one of the, hence the query I am trying to execute. If I shouldn't be doing this for what I am trying to achieve please let me know. If it makes a difference, the website has < 50 nodes that are not of the "Article" document type. All the rest is article. I am building an examine search index only for that document type.
Otherwise, there is one thing I don't understand in your first post. You say that examine will give me the fastest result and then then post the extension method with
For that number of records I'd suggest sticking with the Examine solution you came up with since that will be much quicker in terms of processing.
Otherwise, if you don't want to use Examine, then you can use that extension method or the XPath method. That extension method is just a simple Linq statement to IPublishedContent. So if you use it like this:
Just out of curiosity, the LINQ queries to IPublishedContent use the content cached by umbraco if they don't use the examine index? Do they hit the DB for a high number of nodes like that?
IPublishedContent does not hit the database at all for content. These entities are still coming from the XML file (not examine) and soon we'll be able to change that out to any different caching medium (provider based - could be Examine/Lucene as an option).
That said, the IPublishedContent returned for Media does come from Examine since there's no XML file for media. If it's not found their it will go to the db and be cached.
uQuery vs Examine vs IPublishedContent for Querying
Hi,
I am trying to query my entire site tree for nodes of a certain document type for which a property matches a certain value. With uQuery I had :
which worked perfectly fine. I am using MVC though so I need IPublishedContent while uQuery returns Nodes.
So I could do :
and that will give me IPublishedContent which is what I need. I read a few posts on the forum saying that uQuery was no longer the way to go I haven't found exactly how to do it simply with the methods described in the MVC docs : http://our.umbraco.org/documentation/reference/Templating/Mvc/querying
TypedContentAtRoot returns an IEnumerable which makes it harder to query all the nodes on my site using that method (though not impossible at all. Only that my code is nowhere near as clear as the uQuery version).
I also tried the Examine route and ended up with :
Once again, this works fine. I like it a bit less because I have to convert my query (id) to a string but it also works. I only have a limited amount of data I can test on so I don't know if I should consider speed in my how I will do it. And if I do, which way should I go.
I will have ~5000 nodes that I will be querying on.
What's the correct way to go for that?
Thanks a lot!
Hi Hugo,
uQuery and INode are essentially obsolete, you should be using IPublishedContent everywhere. There might be some extension methods that need to be created on top of IPublishedContent for making things this like this a bit simpler.
The query you are trying to execute is a fairly intensive one with 5000+ nodes. Is there a reason you need to query your whole site for nodes of a specific type?
Using Examine will have the fastest execution time for something like this.
Here's an extension method you could create (we'll add this to the core) for acheiving this with IPublishedContent:
Then in your mvc view you could do:
Also note that in nearly all base classes that are shipped with Umbraco including controllers, views, etc... we always expose an Umbraco helper already, you generally don't have to create one yourself. In UmbracoTemplatePage and UmbracoViewPage
Oh and there's another method which you can use too that's available in 6.1+
My XPath is ultra rusty so not sure if that is the exact xpath syntax, but that would work for you too.
I've added that method to 6.2 in revision: 49d5791825bfb4293e9daafdb378cc463e49aa5f
Thanks a lot Shannon,
I am building an archive for a publication that has a fairly big archive (5000 or so articles). Each article is a node in my Umbraco site. I want to be able to navigate the archives using different methods. For example, using a "Category" (which is a field in my "Article" Document Type). This is not the only criteria but one of the, hence the query I am trying to execute. If I shouldn't be doing this for what I am trying to achieve please let me know. If it makes a difference, the website has < 50 nodes that are not of the "Article" document type. All the rest is article. I am building an examine search index only for that document type.
Otherwise, there is one thing I don't understand in your first post. You say that examine will give me the fastest result and then then post the extension method with
Will that use examine in the background? If not, what does it use?
Thanks again!
-Hugo
Sorry, didn't mean to be confusing there :)
For that number of records I'd suggest sticking with the Examine solution you came up with since that will be much quicker in terms of processing.
Otherwise, if you don't want to use Examine, then you can use that extension method or the XPath method. That extension method is just a simple Linq statement to IPublishedContent. So if you use it like this:
It will find all nodes in your site with the doc type alias 'docTypeAlias'.
Make more sense ?
Sure does, thank you.
Just out of curiosity, the LINQ queries to IPublishedContent use the content cached by umbraco if they don't use the examine index? Do they hit the DB for a high number of nodes like that?
IPublishedContent does not hit the database at all for content. These entities are still coming from the XML file (not examine) and soon we'll be able to change that out to any different caching medium (provider based - could be Examine/Lucene as an option).
That said, the IPublishedContent returned for Media does come from Examine since there's no XML file for media. If it's not found their it will go to the db and be cached.
Thank you so much for your help!
is working on a reply...