Loading TOC...

cts:element-word-query

cts:element-word-query(
   $element-name as xs:QName*,
   $text as xs:string*,
   [$options as xs:string*],
   [$weight as xs:double?]
) as cts:element-word-query

Summary

Returns a query matching elements by name with text content containing a given phrase. Searches only through immediate text node children of the specified element as well as any text node children of child elements defined in the Admin Interface as element-word-query-throughs or phrase-throughs; does not search through any other children of the specified element.

Parameters
$element-name One or more element QNames to match. When multiple QNames are specified, the query matches if any QName matches.
$text Some words or phrases to match. When multiple strings are specified, the query matches if any string matches.
$options Options to this query. The default is ().

Options include:

"case-sensitive"
A case-sensitive query.
"case-insensitive"
A case-insensitive query.
"diacritic-sensitive"
A diacritic-sensitive query.
"diacritic-insensitive"
A diacritic-insensitive query.
"punctuation-sensitive"
A punctuation-sensitive query.
"punctuation-insensitive"
A punctuation-insensitive query.
"whitespace-sensitive"
A whitespace-sensitive query.
"whitespace-insensitive"
A whitespace-insensitive query.
"stemmed"
A stemmed query.
"unstemmed"
An unstemmed query.
"wildcarded"
A wildcarded query.
"unwildcarded"
An unwildcarded query.
"exact"
An exact match query. Shorthand for "case-sensitive", "diacritic-sensitive", "punctuation-sensitive", "whitespace-sensitive", "unstemmed", and "unwildcarded".
"lang=iso639code"
Specifies the language of the query. The iso639code code portion is case-insensitive, and uses the languages specified by ISO 639. The default is specified in the database configuration.
"distance-weight=number"
A weight applied based on the minimum distance between matches of this query. Higher weights add to the importance of proximity (as opposed to term matches) when the relevance order is calculated. The default value is 0.0 (no impact of proximity). The weight should be less than or equal to the absolute value of 16 (between -16 and 16); weights greater than 16 will have the same effect as a weight of 16. This parameter has no effect if the word positions index is not enabled. This parameter has no effect on searches that use score-simple, score-random, or score-zero (because those scoring algorithms do not consider term frequency, proximity is irrelevant).
"min-occurs=number"
Specifies the minimum number of occurrences required. If fewer that this number of words occur, the fragment does not match. The default is 1.
"max-occurs=number"
Specifies the maximum number of occurrences required. If more than this number of words occur, the fragment does not match. The default is unbounded.
"synonym"
Specifies that all of the terms in the $text parameter are considered synonyms for scoring purposes. The result is that occurances of more than one of the synonyms are scored as if there are more occurance of the same term (as opposed to having a separate term that contributes to score).
$weight A weight for this query. Higher weights move search results up in the relevance order. The default is 1.0. The weight should be less than or equal to the absolute value of 16 (between -16 and 16); weights greater than 16 will have the same effect as a weight of 16. Weights less than the absolute value of 0.0625 (between -0.0625 and 0.0625) are rounded to 0, which means that they do not contribute to the score.

Usage Notes

If neither "case-sensitive" nor "case-insensitive" is present, $text is used to determine case sensitivity. If $text contains no uppercase, it specifies "case-insensitive". If $text contains uppercase, it specifies "case-sensitive".

If neither "diacritic-sensitive" nor "diacritic-insensitive" is present, $text is used to determine diacritic sensitivity. If $text contains no diacritics, it specifies "diacritic-insensitive". If $text contains diacritics, it specifies "diacritic-sensitive".

If neither "punctuation-sensitive" nor "punctuation-insensitive" is present, $text is used to determine punctuation sensitivity. If $text contains no punctuation, it specifies "punctuation-insensitive". If $text contains punctuation, it specifies "punctuation-sensitive".

If neither "whitespace-sensitive" nor "whitespace-insensitive" is present, the query is "whitespace-insensitive".

If neither "stemmed" nor "unstemmed" is present, the database configuration determines stemming. If the database has "stemmed searches" enabled, it specifies "stemmed". Otherwise it specifies "unstemmed".

If neither "wildcarded" nor "unwildcarded" is present, the database configuration and $text determine wildcarding. If the database has any wildcard indexes enabled ("three character searches", "two character searches", "one character searches", or "trailing wildcard searches") and if $text contains either of the wildcard characters '?' or '*', it specifies "wildcarded". Otherwise it specifies "unwildcarded".

If neither "stemmed" nor "unstemmed" is present, then the database configuration determines if a query is run as "stemmed" (stemmed searches enabled) or "unstemmed" (word searches enabled and stemmed searches disabled). If the query is a wildcard query and is also a phrase query (contains two or more terms), then any wildcard terms in the query will be "unstemmed".

Negative "min-occurs" or "max-occurs" values will be treated as 0 and non-integral values will be rounded down. An error will be raised if the "min-occurs" value is greater than the "max-occurs" value.

Relevance adjustment for the "distance-weight" option depends on the closest proximity of any two matches of the query. For example,

  cts:element-word-query(xs:QName("p"),("dog","cat"),("distance-weight=10"))
  
will adjust relevance based on the distance between the closest pair of matches of either "dog" or "cat" within an element named "p" (the pair may consist only of matches of "dog", only of matches of "cat", or a match of "dog" and a match of "cat").

Example

  cts:search(//module,
    cts:element-word-query(
      xs:QName("function"), 
      "MarkLogic Corporation"))
  
=> .. relevance-ordered sequence of 'module' elements ancestors (or self) of elements with QName 'function' and text content containing the phrase 'MarkLogic Corporation'.

Example

  cts:search(//module,
    cts:element-word-query(
      xs:QName("function"), 
        "MarkLogic Corporation", "case-sensitive"))
  
=> .. relevance-ordered sequence of 'module' elements ancestors (or self) of elements with QName 'function' and text content containing the phrase 'MarkLogic Corporation', or any other case-shift, like 'MarkLogic Corporation'.

Example

  cts:search(//module,
    cts:and-query((
      cts:element-word-query(
        xs:QName("function"), 
        "MarkLogic Corporation",
        ("case-insensitive", "punctuation-insensitive"), 0.5),
      cts:element-word-query(
        xs:QName("title"), 
        "faster"))))
  
=> .. relevance-ordered sequence of 'module' element ancestors (or self) of both: (a) 'function' elements with text content containing the phrase 'MarkLogic Corporation', ignoring embedded punctuation, AND (b) 'title' elements containing the word 'faster', with the results of the first sub-query query given weight 0.5, and the results of the second sub-query given the default weight 1.0. As a result, the title term 'faster' counts more towards the relevance score.

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.