I'm trying to find a node which is not published yet, so I'm thinking I need to use the ContentService. All I know about the content is its url, e.g. "/home/products/myproductname"
You use the content service to iterate over your tree. If you have a lot of content items this may not be the best approach performance wise.
You query the internal examine index base on your url segments. The internal index contains also unpublished items
So if you go the examine way you could start with finding the node on productname (your last url segment)
var searcher = ExamineManager.Instance.SearchProviderCollection["InternalSearcher"];
var criteria = searcher.CreateSearchCriteria();
criteria.RawQuery("urlName:myproductname");
var searchResults = searcher.Search(criteria);
If that only has one result you can be pretty sure you have the correct page. If not you can always use the parentId of the results to find the correct parent item
Alternate option: if you can get the node at /home/products (by content type or a known document id/udi) you could then iterate the children.
Wouldn't be as performant as using Examine, but depending on the number of nodes being queried that may not be an issue. If you're using ContentService this shouldn't be happening on the forward-facing site, so performance again could be less of a concern.
Get IContent from ContentService by url/path
I'm trying to find a node which is not published yet, so I'm thinking I need to use the ContentService. All I know about the content is its url, e.g. "/home/products/myproductname"
How can I find that node?
-Tor
Hi Tor,
I'm a bit confused. You say your content is unpublished, but you want to get it by url.
A content item that is not published does not have URL. So the content service does not support getting a item by url
Dave
Change URL to path then. Clearly the node has a position in the tree, from which you can deduct the path (and url) from.
Hi Tor,
That is not supported.
Here is the docs for the content service : https://our.umbraco.com/apidocs/csharp/api/Umbraco.Core.Services.ContentService.html#UmbracoCoreServicesContentServiceGetByLevelSystemInt32_
So I see 2 options.
So if you go the examine way you could start with finding the node on productname (your last url segment)
var searcher = ExamineManager.Instance.SearchProviderCollection["InternalSearcher"];
var criteria = searcher.CreateSearchCriteria();
criteria.RawQuery("urlName:myproductname");
var searchResults = searcher.Search(criteria);
If that only has one result you can be pretty sure you have the correct page. If not you can always use the parentId of the results to find the correct parent item
Dave
Alternate option: if you can get the node at /home/products (by content type or a known document id/udi) you could then iterate the children.
Wouldn't be as performant as using Examine, but depending on the number of nodes being queried that may not be an issue. If you're using ContentService this shouldn't be happening on the forward-facing site, so performance again could be less of a concern.
Ok, thanks guys. I will give both options, a) search the examine index, and b) try to find the parent node and if found iterate the children, a try.
-Tor
is working on a reply...