|A Tinderbox Reference File : Agent Queries : Attribute value pattern matching||aTbRef Site Map|
Attribute value pattern matching
Attribute values may be used as a target for queries:
Whilst most easily understood in the context of string data, the target attribute need not always be specifically of String type. For instance, a File type attribute holds a path to a file - which is a string - and can thus be queries in the above fashion. Set-type atttributes are collections of strings so can be pattern-matched.
Note text can be searched too, as the Text attribute represents the note's body text.
IMPORTANT! Note that in this type of query, although an attribute name is used, a $ prefix is not used.
This is also a shorter AttributeName query method with not pattern supplied that gathers notes for which the boolean value of AttributeName (of any date type [sic]) evaluates to true. For numeric attributes, true is any value other than zero. For string attributes, true is any value other than "false" and the empty string. For date attributes, true is assumed to be a matching day. This query type may also be used in export templates. For example: ^any(child,Urgent)^ gathers all notes which have at least one child whose Urgent attribute resolves to true.
StringAttribute( data or pattern )
Gathers all notes whose AttributeAttribute contains the data string or matches the pattern regular expression.
Patterns, i.e. regular expressions, are those defined for Boost (http://www.boost.org/doc/libs/1_34_1/libs/regex/doc/syntax_perl.html).
For a negative match, where the string is not matched, use an alternate syntax with a preceding exclamation mark (!):
!StringAttribute( data or pattern )
Note how the '!' that triggers the match reversal is placed before the attribute name and not the (data or pattern) part. Thus, opposing examples:
The above two example would have no overlap in their matches. N.B. the $ prefix is not used before the attribute name.
SetAttribute( data or pattern )
Gathers all notes whose SetAttribute values match the data string or matches the pattern regular expression. Unlike a string attribute value where partial matches can be made, the match here must be for a complete individual set value.
Thus for an Set called
MySet with three values 'Carpet;Carrot;Car;', a query for
MySet(Ca) would return no matches. This is because the string 'Ca' is not a complete match for any of the values.
MySet(Car) would get 1 match only - 'Car'. Despite both other values containing the sub-string 'Car', there is no match.
Otherwise the observations above re patterns and negative searches apply.
|Up: Agent Queries|
|Next: String Attributes - comparison operators|
Licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0 License
[See aTbRef CC licence Attribution/Waiver info info]