|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Query SearchQuery searches help you search the contents of forms attached to your topics, as well as the values of other meta-data attached to the topic. Using query searches you can search:
On this page:
Field specifiersYou use field specifiers to say what value from the topic you are interested in. All meta-data in a topic is referenced according to a simple plan.
META:TOPICPARENT , META:TOPICINFO etc - are structures which are indexed by keys. For example, META:TOPICINFO has 4 entries, which are indexed by the keys author , date , format and version . META:FILEATTACHMENT , META:FIELD and META:PREFERENCE are all arrays, which means they can have any number of records under them. Arrays are indexed by numbers - for example, the first entry in the META:FIELD array is entry 0.
It's a bit clumsy having to type META:FILEATTACHMENT every time you want to refer to the array of attachments in a topic, so there are some predefined aliases that make it a bit less typing:
fields shortcut when accessing form fields, but always use the name of the form instead.
If you use the name of a field (for example, LastName ) in the query without a . before it, that is taken to mean "the value of the field named this". This works if and only if the field name isn't the same as of the top level entry names or their aliases described above. For example, the following expressions will all evaluate to the same thing:
X would conflict with the name of an entry or alias (e.g. it's moved or maybe parent ), you can prepend the name of the form followed by a dot, as shown in the last example.
ConstantsYou use constants for the values that you compare with fields. Constants are either strings, or numbers.String ConstantsString constants are always delimited by single-quotes. You can use backslash\ to include the following special characters:
\d means \d (unless the string is used as a regular expression, in which case it means any digit).
Numerical constantsNumbers can be any signed or unsigned integer or floating point number using standard scientific notation e.g. -1.2e-3 represents -0.0012OperatorsField specifiers and constants are combined using operators to create queries.
Putting it all togetherWhen a query is applied to a topic, the goal is to reduce to a TRUE or FALSE value that indicates whether the topic matches that query or not. If the query returns TRUE, then the topic is included in the search results. A query matches if the query returns one or more values when it is applied to the topic. So if I have a very simple query, such as"attachments" , then this will return TRUE for all topics that have one or more attachments. If I write "attachments[size>1024 AND name ~ '*.gif']" then it will return TRUE for all topics that have at least one attachment larger than 1024 bytes with a name ending in .gif .
Gotcha
ExamplesQuery examples
Search examplesFind all topics that are children of this topic in the current web%SEARCH{"parent.name = '%TOPIC%'" web="%WEB%" type="query"}%Find all topics that have an attachment called 'grunge.gif' %SEARCH{"attachments[name='grunge.gif']" type="query"}%Find all topics that have form ColourForm where the form field 'Shades' is 'green' or 'yellow' but not 'brown'
%SEARCH{"(lc(Shades)='green' OR lc(Shades)='yellow') AND NOT(lc(Shades) ~ 'brown')" type="query"}%Find all topics that have PNG attachments that have been added since 26th March 2007 %SEARCH{"attachments[name ~ '*.png' AND date >= d2n('2007-03-26')]" type="query"}%Find all topics that have a field 'Threat' set to 'Amber' and 'cold virus' somewhere in the topic text. %SEARCH{"Threat='Amber' AND text ~ '*cold virus*'" type="query"}%Find all topics newer than one week old %SEARCH{"info.date >= %CALC{"$TIMEADD($TIME(), -7, day)"}%" type="query"}%Related Topics: SearchHelp, VarSEARCH, FormattedSearch, Foswiki:System/QuerySearchPatternCookbook ![]() |