Search for a string in all nodes with Python

def quickFindRecursive(startNodeId, searchValue)

Loops through all nodes recursively from startNodeId searching for searchValue (on both node.Name and all node.Properties.Value). It uses nodefactory and is as fast as XsltSearch. Start node id -1 = content root. Primarily intended for admin section use (PyPad), but could easily be used in a site search function aswell – then one would add conditions for protected and hidden nodes.

Returns a list of tuples with node id, property alias (or [Name]), and property value.

print quickFindRecursive(-1,"Dogs")
[[1045,"[Name]","Dogs"],[1054,"BodyText","I like dogs"]]


def quickFindRecursive(startNodeId, searchValue):
  n = Node(startNodeId)
  r = []
  for c in n.Children:
    if c.Name==findWhat:
      r.append([c.Id, "[Name]", c.Name])
    for p in c.Properties:
        if str(p.Value).find(searchValue)>-1:
          r.append([c.Id, p.Alias, p.Value])
    r = r + quickFindRecursive(c.Id,searchValue)
  return r

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s