6.6.5.2 jcr:contains Function

jcr:contains($scope as node(),
$exp as xs:string) as xs:boolean

This function is used to embed a statement in a full-text search language. It is functionally equivalent to the SQL CONTAINS function (for level 2 implementations) described in 8.5.4.5 CONTAINS.

The first parameter defines the scope of the contains predicate. It can be either “.” (meaning this node, i.e., the node-set defined by the current location step) or it can be an XML attribute name (and therefore a content repository property), for example @my:property, specifying a particular property of the node-set defined by the current location step). If the scope is “.” then all properties of the current node set for which the implementation maintains an index are searched. If a specific property is specified then only the value of that property is searched (if the property is not indexed then the function will return false).

As described in 6.6.3.3 Property Constraint, support for the jcr:contains() function is required to work at the node level in those repositories which support full text searching. In other words only support for “.” is required. Support for property specific full-text search is optional.

The EBNF for the second parameter is:

searchexp ::= [-]term {whitespace [OR]
whitespace [-]term}

term ::= word | '"' word {whitespace word} '"'

word ::= /* A string containing no whitespace */

whitespace ::= /* A string of only whitespace*/


At minimum, all implementations must support the simple search-engine syntax defined by exp in the EBNF above. This syntax is based on the syntax of search engines like Google.

The semantics of the simple search expression are as follows:

For example, the query “Find all nodes with some property that contains the text ‘JSR 170’ ” is expressed as:

//*[jcr:contains(., 'JSR 170')]

the optionally supported query “Find all nodes with a property called myapp:title that contain the text ‘JSR 170’ ” is expressed as:

//*[jcr:contains(@myapp:title, 'JSR 170')]

The relevance score for each node may be returned in (one or more) score columns (jcr:score or jcr:score(...)) however the details of how the score is calculated are implementation-specific (see 8.5.2.4 Pseudo-property, 6.6.5.2 jcr:contains Function and 8.5.4.5 CONTAINS).

An implementation may choose to support other embedded full-text search languages other than the simple search engine style shown here.