Here are some more examples on using queries in various use cases. Section |
---|
| To select all resource documents that are read by a specific user ("jd " in this example) in a given year (specified by the document property Readjd in the format yyyy-MM-dd ), use the prefix query: Code Block |
---|
| ReadBy = "jd" AND Readjd = 2014* |
|
Section |
---|
title | Querying List Values |
---|
| The Tags Property is one that is supported by all document types. It specifies a comma-separated list of values. To select on those documents by tag values, use this: Code Block |
---|
| Tags = (("test-me" AND "continous-delivery") OR "My-Tag") |
|
Section |
---|
title | Search all Topic Types that are no Fragments |
---|
| A fragment is a basic document a couple of topic types (table, example, ...) derive from. To select only documents of a type that is not a fragment or one of its subtypes, use the following: Code Block |
---|
| +TypeAncestors:[* TO *] AND -TypeAncestors:Fragment |
Note that in this case all documents have to have their topic type specific. If those that have not should also be part of the result set, use: Code Block |
---|
| +Doctype:topic AND -TypeAncestors:Fragment |
|
Section |
---|
| Since version 1.10 the projectdoc Toolbox provides normalized date value to be used with Lucene searches. If the property value is specified with the Confluence Date Autocompletion (opened with the shortcut '// '), and for the creation and last modification date, a normalized date is provided as an artificial property.
The name of this artificial property is that of the original property plus the § -sign appended. Here is an example where the creation date is check against a custom property named Last Update . Code Block |
---|
| $[Creation Date§]: [${Last Update§} TO NOW] |
There is also an artificial property value containing the date as a timestamp in milliseconds, prefixed with zeros up to 19 digits (%019d ). The name of the artificial property is constructed from the original name plus the suffix Timestamp (separated by a blank). Note that the creation timestamp is called Creation Timestamp (not Creation Date Timestamp ). Note Box |
---|
Appending the $-sign instead of the §-sign will render the text representation of the date. |
|
Section |
---|
| Confluence provides a couple of search fields to help finding the desired documents. Code Block |
---|
| created:[20150311 TO 20150317]
created:[20150311 TO NOW] |
Ranges work with Date Functions. Use the normalized date value to define range boundaries. Code Block |
---|
| Date§: [20190101 TO ${now("", "-6w")}]
Date§: [${now("", "-6w")} TO ${now("", "-4w")}] |
The Date property is recommended to be specified with the Confluence Date Autocompletion (opened with the shortcut '// '). |
Section |
---|
| A query function is a virtual function call that will replace the call with the return value of the function. Version Box |
---|
Search functions are provided since version 3.2 of the projectdoc Toolbox. |
The syntax for using search functions is: Code Block |
---|
| $<PROPERTY NAME>=${function-name(argument-list)} |
Functions can be used for a value in a Where clause parameter of a projectdoc macro. Functions cannot be used for a property name or outside the Where clause. Example Box |
---|
Here are some usage examples: Code Block |
---|
| $<Start Date§>=${now()}
$<Login Name>=${currentUser()}
$<Attendee>=${currentUser("fn")} |
|
Section |
---|
| The following functions are supported: currentUser() now() startOfDay() endOfDay() startOfWeek() endOfWeek() startOfMonth() endOfMonth() startOfYear() endOfYear()
Section |
---|
| There is only one user function that provides access to the current user of a session. The currentUser function supports the format argument. Valid formats are id (default) - login name (id) of the current userfn - Full Name of current user
If no user is currently logged in to the current session, then the format id returns "#anonymous " and the format fn returns "#Anonymous ". Example Box |
---|
The following calls will return the login name of the currently logged in user. Code Block |
---|
| currentUser()
currentUser("")
currentUser("id") |
In case the full name, as provided in the user's profile is requested, use: Code Block |
---|
| currentUser("fn") |
|
|
Section |
---|
| The date functions provide a date in the format "yyyyMMdd ". This way it can easily be compared to date properties by the use of the normalized date representation (add '§' to the name of the property like "Start Date§ "). The following functions are provided: Name | Description |
---|
now
| The current date at the time the page is rendered. | startOfDay | The date at the first millisecond on the current day. | endOfDay | The date at the last millisecond on the current day. | startOfWeek | The date at the first millisecond of the first day of the week the current day is part of. Note that currently you cannot control the definition of the first day. | endOfWeek | The date at the last millisecond of the last day of the week the current day is part of. Note that currently you cannot control the definition of the last day. | startOfMonth | The date at the first millisecond of the first day of the month the current day is part of. | endOfMonth | The date at the last millisecond of the first day of the month the current day is part of. | startOfYear | The date at the first millisecond of the first day of the year the current day is part of. | endOfYear | The date at the last millisecond of the first day of the year the current day is part of. |
Note Box |
---|
title | Implementation Details |
---|
| Note that now is calculated per macro. So in case you have multiple macros on a page, the "now" point in time is when the macro is called. For most use cases this should not make any differences. In case a call is sent some milliseconds before midnight, two macros may calculate different days. |
The date functions allow two arguments. If you want to specify the increment, but not the format, use "" (empty string) as the first argument. Version Box |
---|
title | Abbreviated Date Function Call Form |
---|
since | 4.1 |
---|
| Since version 4.1 the abbreviated form without format argument is also supported. Simply use only the second argument without double quotes. Code Block |
---|
| $<Date§> >= ${now(-2w)} |
|
Example Box |
---|
The following calls are semantically identically. Code Block |
---|
| $<Date§> >= ${startOfMonth()}
$<Date§> >= ${startOfMonth("")}
$<Date§> >= ${startOfMonth("", "")} |
The following calls are semantically identically, the first only available in 4.1 and above. Code Block |
---|
| $<Date§> <= ${startOfMonth(-1d)} // 4.1 and above
$<Date§> <= ${startOfMonth("", "-1d")} |
Caution Box |
---|
title | Unsupported operators: '<' and '>' |
---|
| Prior to version 4.1 the operators '>' and '<' are not supported! Please use '>=' and '<=' instead. |
|
Section |
---|
| Specify the format as defined for the Joda Time date formatter: DateTimeFormat. Typically use: Format | Description |
---|
y
| Year. Typically use "yyyy " for four digits (i.e. 2019 ). | M | Month. Typically use "MM " for two digits (i.e. 03 and 12 ). | dd | Day. Typically use "dd " for two digits (i.e. 01 and 15 ). | H | Hours. Typically use "HH " for two digits (i.e. 08 and 23 ). | m | Minutes. Typically use "mm " for two digits (i.e. 01 and 59 ). |
The default format is: "yyyyMMdd ". Note Box |
---|
| Note that the format is used to render the date. If the date is compared to another date the compare is not executed on the date object, but on the rendered date. Therefore the format must be comparable lexicographically. Any format would do that shows the year first, then the month (leading zero in case the month ordinal number is smaller ten, and lastly the day (again with leading zero). |
Example Box |
---|
title | Compate Date with Format |
---|
| Assume a document property named Date with a date value in text form: 17.11.2019 To match that date on November the 23rd in 2019 the function requires to subtract 6 days. Code Block |
---|
$<Date> = ${now("dd.MM.yyyy", "-6d")} |
In order to match the date value, the format must be specified. This is because the rendered dates are compared, not the parsed date objects. |
|
Section |
---|
| With the second argument to the date function you may alter the date. The format is: Code Block |
---|
(+/-)nn(y|M|w|d|h|m) |
Use + (default) or - to add or subtract from the calculated value. Provide the amount of units at 'nn'. If omitted, one is assumed. Add the unit identifier: ID | Description |
---|
y
| Years | M | Months | w | Weeks | d | Days | H | Hours | m | Minutes |
For instance: Example Box |
---|
Code Block |
---|
| +2d
5y
-10w
-2d10y |
|
Example Box |
---|
Here are some usage examples: Code Block |
---|
| $<Date§> >= ${now("", "-2w")}
$<Date§> >= ${endOfMonth("", "1w")}
$<Date§> >= ${startOfMonth("", "+3d")} |
Using date ranges: Code Block |
---|
| Date§: [${now("", "-6w")} TO ${now("", "-4w")}]
$<Date§> >= ${now("", "-6w")} AND $<Date§> <= ${now("", "-4w")} |
|
Version Box |
---|
title | Abbreviated Date Function Call Form |
---|
since | 4.1 |
---|
| Since version 4.1 the abbreviated form without format argument is also supported. Instead of Code Block |
---|
| $<Date§> >= ${now("", "-2w")}
$<Date§> >= ${endOfMonth("", "1w")}
$<Date§> >= ${startOfMonth("", "+3d")} |
simply write Code Block |
---|
| $<Date§> >= ${now(-2w)}
$<Date§> >= ${endOfMonth(1w)}
$<Date§> >= ${startOfMonth(+3d)} |
Note that there are no double quotes around the increment specification. |
|
|
|
|
Section |
---|
| You can select property values that are checkbox and use checkboxes in your where clauses. The checked checkbox has a text value of complete , an unchecked checkbox has a value of incomplete . See Tasks as Property Values for an example. |
Section |
---|
| In general Not in a query is only allowed when it follows an positive expression. To specify a document property not to have a certain value, use a range query like this: Code Block |
---|
| +ID:[* TO *] AND -ID:6555694 |
Section |
---|
title | Searching for an empty attribute using Not |
---|
| Searching all Documents having an attribute that is not set e.g. not having a parent. This is especially useful, if you want to list all root documents of a given document type (see Parent Property of projectdoc Documents for an example using the Parent Property). Code Block |
---|
*:* -Parent:[* TO *]
|
or Code Block |
---|
*:* NOT Parent:[* TO *]
|
The *:* is only needed if you have no positive criteria. A Lucene query must not start with "NOT". Tip Box |
---|
If you need to have all documents in the result that that actually have a parent, then use Code Block |
---|
| Parent:[* TO *] |
|
Note that you can only select on properties, not on sections. Caution Box |
---|
If you want to make sure that a document with a specific ID is not part of the result set, use this: Code Block |
---|
| Tags = "logging" NOT ID = 3704077 |
This does not do the trick (the syntax is wrong): Code Block |
---|
| Tags = "logging" AND ID NOT 3704077 |
|
|
|
|