Changes

Jump to navigation Jump to search
92 bytes removed ,  18:34, 1 December 2023
m
Text replacement - "<syntaxhighlight lang="xquery">" to "<pre lang='xquery'>"
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|ft:search|$db as xs:string, $terms as item()*|text()*}}<br/pre>{{Func|ft:search|( $db as xs:string, $terms as item()*, $options as map(*)?| := map { }) as text()*}}</pre>|-valign="top"
| '''Summary'''
|Returns all text nodes from the full-text index of the database {{Code|$db}} that contain the specified {{Code|$terms}}.<br/>The options used for tokenizing the input and building the full-text will also be applied to the search terms. As an example, if the index terms have been stemmed, the search string will be stemmed as well.
** {{Code|max}}: specify the maximum distance in terms of ''units''. The default is {{Code|∞}}.
** {{Code|unit}}: can be {{Code|words}}, {{Code|sentences}} or {{Code|paragraphs}}. The default is {{Code|words}}.
|-valign="top"
| '''Errors'''
|{{Error|db:get|Database Module#Errors}} The addressed database does not exist or could not be opened.<br/>{{Error|db:no-index|Database Module#Errors}} the index is not available.<br/>{{Error|options|#Errors}} the fuzzy and wildcard option cannot be both specified.
|-valign="top"
| '''Examples'''
|
* Return all text nodes of the database {{Code|DB}} that contain the numbers {{Code|2010}} and {{Code|2020}}:<br/><code>ft:search("DB", ("2010", "2020"), map { 'mode': 'all' })</code>
* Return text nodes that contain the terms {{Code|A}} and {{Code|B|}} in a distance of at most 5 words:
<syntaxhighlight pre lang="'xquery"'>
ft:search("db", ("A", "B"), map {
"mode": "all words",
}
})
</syntaxhighlightpre>
* Iterate over three databases and return all elements containing terms similar to {{Code|Hello World}} in the text nodes:
<syntaxhighlight pre lang="'xquery"'>
let $terms := "Hello Worlds"
let $fuzzy := true()
let $dbname := 'DB' || $db
return ft:search($dbname, $terms, map { 'fuzzy': $fuzzy })/..
</syntaxhighlightpre>
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|ft:tokens|$db as xs:string|element(value)*}}<br/pre>{{Func|ft:tokens|( $db as xs:string, $prefix as xs:string| := ()) as element(value)*}}</pre>|-valign="top"
| '''Summary'''
|Returns all full-text tokens stored in the index of the database {{Code|$db}}, along with their numbers of occurrences.<br/>If {{Code|$prefix}} is specified, the returned nodes will be refined to the strings starting with that prefix. The prefix will be tokenized according to the full-text used for creating the index.
|-valign="top"
| '''Errors'''
|{{Error|db:get|Database Module#Errors}} The addressed database does not exist or could not be opened.<br/>{{Error|db:no-index|Database Module#Errors}} the full-text index is not available.
|-valign="top"
| '''Examples'''
|Returns the number of occurrences for a single, specific index entry:
<syntaxhighlight pre lang="'xquery"'>
let $term := ft:tokenize($term)
return number(ft:tokens('db', $term)[. = $term]/@count)
</syntaxhighlightpre>
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|ft:contains|$input as item()*, $terms as item()*|xs:boolean}}<br/pre>{{Func|ft:contains|( $input as item()*, $terms as item()*, $options as map(*)?| := map { }) as xs:boolean}}</pre>|-valign="top"
| '''Summary'''
|Checks if the specified {{Code|$input}} items contain the specified {{Code|$terms}}.<br/>The function does the same as the [[Full-Text]] expression {{Code|contains text}}, but options can be specified more dynamically. The {{Code|$options}} are the same as for {{Function||ft:search}}, and the following ones exist:
* {{Code|stemming}}: determines is tokens are stemmed. Allowed values are {{Code|true}} and {{Code|false}}. By default, stemming is turned off.
* {{Code|language}}: determines the language. This option is relevant for stemming tokens. All language codes are supported. The default language is {{Code|en}}.
|-valign="top"
| '''Errors'''
|{{Error|options|#Errors}} specified options are conflicting.
|-valign="top"
| '''Examples'''
|
* Checks if {{Code|jack}} or {{Code|john}} occurs in the input string {{Code|John Doe}}:
<syntaxhighlight pre lang="'xquery"'>
ft:contains("John Doe", ("jack", "john"), map { "mode": "any" })
</syntaxhighlightpre>
* Calls the function with stemming turned on and off:
<syntaxhighlight pre lang="'xquery"'>
(true(), false()) ! ft:contains("Häuser", "Haus", map { 'stemming': ., 'language':'de' })
</syntaxhighlightpre>
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>ft:count|( $nodes as node()*|) as xs:integer}}</pre>|-valign="top"
| '''Summary'''
|Returns the number of occurrences of the search terms specified in a full-text expression.
|-valign="top"
| '''Examples'''
|
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>ft:score|( $item as item()*|) as xs:double*}}</pre>|-valign="top"
| '''Summary'''
|Returns the score values (0.0 - 1.0) that have been attached to the specified items. {{Code|0}} is returned a value if no score was attached.
|-valign="top"
| '''Examples'''
|
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|ft:tokenize|$string as xs:string?|xs:string*}}<br/pre>{{Func|ft:tokenize|( $string as xs:string?, $options as map(*)?| := map { }) as xs:string*}}</pre>|-valign="top"
| '''Summary'''
|Tokenizes the given {{Code|$string}}, using the current default full-text options or the {{Code|$options}} specified as second argument, and returns a sequence with the tokenized string. The following options are available:
* {{Code|language}}: determines the language. This option is relevant for stemming tokens. All language codes are supported. The default language is {{Code|en}}.
The {{Code|$options}} argument can be used to control full-text processing.
|-valign="top"
| '''Examples'''
|
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|ft:normalize|$string as xs:string?|xs:string}}<br/pre>{{Func|ft:normalize|( $string as xs:string?, $options as map(*)?| := map { }) as xs:string}}</pre>|-valign="top"
| '''Summary'''
|Normalizes the given {{Code|$string}}, using the current default full-text options or the {{Code|$options}} specified as second argument. The function accepts the same arguments as {{Function||ft:tokenize}}; special characters and separators will be preserved.
|-valign="top"
| '''Examples'''
|
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|ft:thesaurus|$node as node(), $term as xs:string|xs:string*}}<br/pre>{{Func|ft:thesaurus|( $node as node(), $term as xs:string, $options as map(*)?| := map { }) as xs:string*}}<br/pre>|-valign="top"
| '''Summary'''
|Looks up a {{Code|$term}} in a [[Full-Text#Thesaurus|Thesaurus Structure]] supplied by {{Code|$node}}. The following {{Code|$options}} exist:
* {{Code|relationship}}: determines the relationship between terms
* {{Code|levels}}: determines the maximum number of levels to traverse
|-valign="top"
| '''Examples'''
| Returns {{Code|happy}} and {{Code|lucky}}:
<syntaxhighlight pre lang="'xquery"'>
ft:thesaurus(
<thesaurus>
'happy'
)
</syntaxhighlightpre>
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|ft:mark|$nodes as node()*|node()*}}<br /pre>{{Func|ft:mark|( $nodes as node()*, $name as xs:string| := ()) as node()*}}</pre>|-valign="top"
| '''Summary'''
|Puts a marker element around the resulting {{Code|$nodes}} of a full-text request.<br />The default name of the marker element is {{Code|mark}}. An alternative name can be chosen via the optional {{Code|$name}} argument.<br />Please note that:
* The full-text expression that computes the token positions must be specified as argument of the <code>ft:mark()</code> function, as all position information is lost in subsequent processing steps. You may need to specify more than one full-text expression if you want to use the function in a FLWOR expression, as shown in Example 2.
* The supplied node must be a [[Database Module#Database Node|Database Node]]. As shown in Example 3, {{Code|update}} or {{Code|transform}} can be utilized to convert a fragment to the required internal representation.
|-valign="top"
| '''Examples'''
|'''Example 1''': The following query returns {{Code|&lt;XML&gt;&lt;mark&gt;hello&lt;/mark&gt; world&lt;/XML&gt;}}, if one text node of the database {{Code|DB}} has the value "hello world":
<syntaxhighlight pre lang="'xquery"'>
ft:mark(db:get('DB')//*[text() contains text 'hello'])
</syntaxhighlightpre>
'''Example 2''': The following expression loops through the first ten full-text results and marks the results in a second expression:
<syntaxhighlight pre lang="'xquery"'>
let $start := 1
let $end := 10
let $term := 'welcome'
let $test := function($node) { $node/text() contains text { $term } }for $ft in (db:get('DB')//*[text$test(.) contains text { $term }])[position() = $start to $end]return element hit { ft:mark($ft[text$test(.) contains text { $term }])}</syntaxhighlightpre>
'''Example 3''': The following expression returns <code>&lt;xml>hello &lt;b&gt;word&lt;/b&gt;&lt;/xml&gt;</code>:
<syntaxhighlight pre lang="'xquery"'>
copy $p := <xml>hello world</xml>
modify ()
return ft:mark($p[text() contains text 'word'], 'b')
</syntaxhighlightpre>
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|ft:extract|$nodes as node()*|node()*}}<br /pre>{{Func|ft:extract|( $nodes as node()*, $name as xs:string|node()*}}<br />{{Func|ft :extract|$nodes as node= ()*, $name as xs:string, $length as xs:integer| := ()) as node()*}}</pre>|-valign="top"
| '''Summary'''
|Extracts and returns relevant parts of full-text results. It puts a marker element around the resulting {{Code|$nodes}} of a full-text index request and chops irrelevant sections of the result.<br />The default element name of the marker element is {{Code|mark}}. An alternative element name can be chosen via the optional {{Code|$name}} argument.<br />The default length of the returned text is {{Code|150}} characters. An alternative length can be specified via the optional {{Code|$length}} argument. Note that the effective text length may differ from the specified text due to formatting and readibility issues.<br />For more details on this function, please have a look at {{Function||ft:mark}}.|-valign="top"
| '''Examples'''
|
* The following query may return {{Code|&lt;XML&gt;...&lt;b&gt;hello&lt;/b&gt;...&lt;XML&gt;}} if a text node of the database {{Code|DB}} contains the string "hello world":
<syntaxhighlight pre lang="'xquery"'>
ft:extract(db:get('DB')//*[text() contains text 'hello'], 'b', 1)
</syntaxhighlightpre>
|}
! width="110"|Code
|Description
|-valign="top"
|{{Code|options}}
|Both wildcards and fuzzy search have been specified as search options.
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu