Find document content by property Node.findByProperty(propertyname,value) ???
Hi, I need to mirror content from another db (actually Filemaker, but I get the data via xml). And I prefer doing it with .net-code rather than with SQL. For that reason I need a way to find a document by a ID, which in Umbraco is just a regular property - not the node id and not the name.
I rather not write a SQL Query, but I do think I can use NodeFactory.ChildrenAsTable. But I would like to ask you first if there was any other more direct method, like Node.findByProperty(propertyname,value) or something?
You can right a quick method to do this farily easily in c#. Just iterate through all the nodes and add the ones with a matching property to a collection. You can iterate through nodes like this:
[code]
...
using umbraco.presentation.nodeFactory;
....
public Nodes GetNodes()
{
Nodes myNodes = new Nodes();
Node root = new Node(-1);
myNodes.Add(root);
IterateNodes(root.Children, myNodes);
return myNodes;
}
private static void IterateNodes(Nodes nodes, Nodes myNodes)
{
foreach (Node n in nodes)
{
myNodes.Add(n);
if (n.Children.Count > 0)
IterateNodes(n.Children, myNodes);
}
}
[/code]
Just alter that to add a check for a property using the GetProperty() method of the Node.
Yes, thank you, I think I will go that way, but I still wonder if there is some method that internally uses a "sql select where @parameter=@value" to get the specific node.
The Nodes in nodeFactory are cached in memory so iterating them should be very fast.
However, there is also the Document class in the umbraco.cms.businesslogic.web namespace. This has various static methods which may be of use, such as Document.getContentOfContentType(). Check them out, it may help.
If you're searching through published content, use xpath some sort of as a path expression which will resemble your sql much. If you're searching through the backend content (published/non published content), consider using Lucene search as all nodes are Lucene indexed. Fast and easy to implement
Find document content by property Node.findByProperty(propertyname,value) ???
Hi, I need to mirror content from another db (actually Filemaker, but I get the data via xml). And I prefer doing it with .net-code rather than with SQL. For that reason I need a way to find a document by a ID, which in Umbraco is just a regular property - not the node id and not the name.
I rather not write a SQL Query, but I do think I can use NodeFactory.ChildrenAsTable. But I would like to ask you first if there was any other more direct method, like Node.findByProperty(propertyname,value) or something?
Thanks!
You can right a quick method to do this farily easily in c#. Just iterate through all the nodes and add the ones with a matching property to a collection. You can iterate through nodes like this:
[code]
...
using umbraco.presentation.nodeFactory;
....
public Nodes GetNodes()
{
Nodes myNodes = new Nodes();
Node root = new Node(-1);
myNodes.Add(root);
IterateNodes(root.Children, myNodes);
return myNodes;
}
private static void IterateNodes(Nodes nodes, Nodes myNodes)
{
foreach (Node n in nodes)
{
myNodes.Add(n);
if (n.Children.Count > 0)
IterateNodes(n.Children, myNodes);
}
}
[/code]
Just alter that to add a check for a property using the GetProperty() method of the Node.
Yes, thank you, I think I will go that way, but I still wonder if there is some method that internally uses a "sql select where @parameter=@value" to get the specific node.
The Nodes in nodeFactory are cached in memory so iterating them should be very fast.
However, there is also the Document class in the umbraco.cms.businesslogic.web namespace. This has various static methods which may be of use, such as Document.getContentOfContentType(). Check them out, it may help.
Hi,
If you're searching through published content, use xpath some sort of as a path expression which will resemble your sql much. If you're searching through the backend content (published/non published content), consider using Lucene search as all nodes are Lucene indexed. Fast and easy to implement
Have a look at http://www.netaddicts.be/articles/umbraco-and-lucenenet.aspx
Hope this helps.
Regards,
/Dirk
"The Nodes in nodeFactory are cached in memory", ah, I was just going to ask.
"Lucene", wow cool!
Thanks for your input!
/back to the code
is working on a reply...