Searching¶
The dantalian.findlib module implements tag queries. See Tagging for more information about tags.
Queries are represented as a tree of SearchNodes.
Example usage:
from dantalian import findlib
# Find files which are tagged foo and bar
paths = findlib.search(findlib.parse_query('AND foo bar END'))
- dantalian.findlib.search(search_node)¶
Return a list of result paths for a given search query.
- dantalian.findlib.parse_query(rootpath, query)¶
Parse a query string into a query node tree.
Parent node syntax:
NODE foo [bar...] END
where NODE is AND, OR, or MINUS
Tokens beginning with a backslash are used directly in DirNode`s. Everything else parses to a :class:`DirNode.
Tagnames are converted to paths using the given rootpath.
Query strings look like:
'AND foo bar OR spam eggs END AND \AND \OR \END \\\END END END'
which parses to:
AndNode([ DirNode('foo'), DirNode('bar'), OrNode([ DirNode('spam'), DirNode('eggs'), ]), AndNode([ DirNode('AND'), DirNode('OR'), DirNode('END'), DirNode('\\END'), ]), ])
Query nodes¶
Query nodes are used to represent a search query. Query node trees can be built manually using the node classes or by using parse_query()
- class dantalian.findlib.SearchNode¶
An abstract interface for all query nodes.
- get_results(self)¶
Abstract method. Returns the results of query represented by the current node.
Returns: A dictionary mapping inode objects to paths.
- class dantalian.findlib.GroupNode(children)¶
Abstract class for query nodes that have a list of child nodes, i.e. non-leaf nodes.
Parameters: children (list) – List of children nodes.
- class dantalian.findlib.AndNode(children)¶
Query node that merges the results of its children nodes by set intersection.
Parameters: children (list) – List of children nodes.
- class dantalian.findlib.OrNode(children)¶
Query node that merges the results of its children nodes by set union.
Parameters: children (list) – List of children nodes.
- class dantalian.findlib.MinusNode(children)¶
Query node that merges the results of its children nodes by set difference: the results of its first child minus the results of the rest of its children.
Parameters: children (list) – List of children nodes.
- class dantalian.findlib.DirNode(dirpath)¶
Query node that returns a directory’s contents as results. These are the leaf nodes in a query search tree.