Within the WHERE clause, the CONTAINS function is used to embed a statement in a full-text search language. The function takes two parameters: scope and searchexp (see EBNF above)
At minimum, all implementations must support the simple search-engine syntax defined by searchexp 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:
Terms separated by whitespace are implicitly ANDed together.
Terms may also be ORed with explicit use of the OR keyword.
AND has higher precedence than OR.
Terms may be excluded by prefixing with a – (minus sign) character. This means that the result set must not contain the excluded term.
A term may be either a single word or a phrase delimited by double quotes (“"”).
The entire text search expression (searchexp in the EBNF, above) must be delimited by single quotes (“'”).
Within the searchexp literal instances of single quote (“'”), double quote (“"”) and hyphen (“-”) must be escaped with a backslash (“\”). Backslash itself must therefore also be escaped, ending up as double backslash (“\\”).
The scope specifies the particular property that the full-text search is to be performed on. However, support for searching on particular properties is not required. Specifying '.' indicates that the full-text search is to be done on all indexed properties of the nodes specified by the rest of the query. Only support for a scope of '.' is required.
The scope of the CONTAINS clause specifying '.' is the intersection of two sets. These two sets are:
The values of those properties that are the immediate children of the nodes specified by the FROM clause and other subclauses of WHERE.
The contents of the full-text index of the repository. A repository may, for example, index only the values of STRING properties. Additionally, it may index some binary properties according to some application-specific encoding. The scope of full-text indexing is implementation specific.
For example, the query,
SELECT * FROM mynt:product WHERE
CONTAINS(., 'apples "good for you" –oranges')
would return a result containing all nodes of type mynt:product that have am indexed property whose value contains the string “apples”, the string “good for you” and does not contain the string “oranges”.
The relevance score for each matching node may be returned as in score column. The specification does not define the calculation of the score value, it is implementation specific.
An implementation may additionally support other embedded full-text search languages other than the simple search engine style shown here.
See also 6.6.3.3 Property Constraint, 6.6.5.2 jcr:contains Function and 8.5.2.4 Pseudo-property.