Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Section
titleUseful Examples

Here are some more examples on using queries in various use cases.

Section
titlePrefix Query

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
languagetext
ReadBy = "jd" AND Readjd = 2014*



Section
titleQuerying 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
languagetext
Tags = (("test-me" AND "continous-delivery") OR "My-Tag")



Section
titleSearch 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
languagetext
+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
languagetext
+Doctype:topic AND -TypeAncestors:Fragment



Section
titleUsing Dates

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
languagetext
$[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
titleUsing Date Ranges

Confluence provides a couple of search fields to help finding the desired documents.

Code Block
languagetext
created:[20150311 TO 20150317]
created:[20150311 TO NOW]

Ranges work with Date Functions. Use the normalized date value to define range boundaries.

Code Block
languagetext
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
titleSearch Functions

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
languagetext
$<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
languagetext
$<Start Date§>=${now()}

$<Login Name>=${currentUser()}

$<Attendee>=${currentUser("fn")}



Section
titleSupported Functions

The following functions are supported:

  • currentUser()
  • now()
  • startOfDay()
  • endOfDay()
  • startOfWeek()
  • endOfWeek()
  • startOfMonth()
  • endOfMonth()
  • startOfYear()
  • endOfYear()
Section
titleUser Functions

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 user
  • fn - 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
languagetext
currentUser()
currentUser("")
currentUser("id")

In case the full name, as provided in the user's profile is requested, use:

Code Block
languagetext
currentUser("fn")




Section
titleDate Functions

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:

NameDescription

now

The current date at the time the page is rendered.

startOfDayThe date at the first millisecond on the current day.
endOfDayThe 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.

startOfMonthThe date at the first millisecond of the first day of the month the current day is part of.
endOfMonthThe date at the last millisecond of the first day of the month the current day is part of.
startOfYearThe date at the first millisecond of the first day of the year the current day is part of.
endOfYearThe date at the last millisecond of the first day of the year the current day is part of.


Note Box
titleImplementation 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.

  • format
  • increment 

If you want to specify the increment, but not the format, use "" (empty string) as the first argument.

Version Box
titleAbbreviated Date Function Call Form
since4.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
languagetext
$<Date§> >= ${now(-2w)}



Example Box

The following calls are semantically identically.

Code Block
languagetext
$<Date§> >= ${startOfMonth()}
$<Date§> >= ${startOfMonth("")}
$<Date§> >= ${startOfMonth("", "")}

The following calls are semantically identically, the first only available in 4.1 and above.

Code Block
languagetext
$<Date§> <= ${startOfMonth(-1d)}  // 4.1 and above
$<Date§> <= ${startOfMonth("", "-1d")}


Caution Box
titleUnsupported operators: '<' and '>'

Prior to version 4.1 the operators '>' and '<' are not supported!

Please use '>=' and '<=' instead.



Section
titleFormat

Specify the format as defined for the Joda Time date formatter: DateTimeFormat.

Typically use:

FormatDescription

y

Year. Typically use "yyyy" for four digits (i.e. 2019).

MMonth. Typically use "MM" for two digits (i.e. 03 and 12).
ddDay. 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
titleRender Format

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
titleCompate 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
titleIncrement

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:

IDDescription

y

Years

MMonths
wWeeks
dDays
H

Hours

m

Minutes

For instance:

Example Box


Code Block
languagetext
+2d

5y

-10w

-2d10y



Example Box

Here are some usage examples:

Code Block
languagetext
$<Date§> >= ${now("", "-2w")}
$<Date§> >= ${endOfMonth("", "1w")}
$<Date§> >= ${startOfMonth("", "+3d")}

Using date ranges:

Code Block
languagetext
Date§: [${now("", "-6w")} TO ${now("", "-4w")}]

$<Date§> >= ${now("", "-6w")} AND $<Date§> <= ${now("", "-4w")}



Version Box
titleAbbreviated Date Function Call Form
since4.1

Since version 4.1 the abbreviated form without format argument is also supported.

Instead of

Code Block
languagetext
$<Date§> >= ${now("", "-2w")}
$<Date§> >= ${endOfMonth("", "1w")}
$<Date§> >= ${startOfMonth("", "+3d")}

simply write

Code Block
languagetext
$<Date§> >= ${now(-2w)}
$<Date§> >= ${endOfMonth(1w)}
$<Date§> >= ${startOfMonth(+3d)}

Note that there are no double quotes around the increment specification.






Section
titleUsing Checkboxes

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
titleUsing Not

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
languagetext
+ID:[* TO *] AND -ID:6555694


Section
titleSearching 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
languagetext
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
languagetext
Tags = "logging" NOT ID = 3704077

This does not do the trick (the syntax is wrong):

Code Block
languagetext
collapsetrue
Tags = "logging" AND ID NOT 3704077





...