Changes

Jump to navigation Jump to search
58 bytes added ,  11:21, 1 June 2021
no edit summary
All functions and errors in this module are assigned to the <code><nowiki>http://basex.org/modules/ft</nowiki></code> namespace, which is statically bound to the {{Code|ft}} prefix.<br/>
=Database Functions=
==ft:search==
</syntaxhighlight>
|}
 
==ft:tokens==
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|ft:tokens|$db as xs:string|element(value)*}}<br/>{{Func|ft:tokens|$db as xs:string, $prefix as xs:string|element(value)*}}
|-
| '''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.
|-
| '''Errors'''
|{{Error|db:open|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.
|-
| '''Examples'''
|Returns the number of occurrences for a single, specific index entry:
<syntaxhighlight lang="xquery">
let $term := ft:tokenize($term)
return number(ft:tokens('db', $term)[. = $term]/@count)
</syntaxhighlight>
|}
 
=General Functions=
==ft:contains==
|}
==ft:markcount== {| width='100%'|-| width='120' | '''Signatures'''|{{Func|ft:mark|$nodes as node()*|node()*}}<br />{{Func|ft:mark|$nodes as node()*, $name as xs:string|node()*}}|-| '''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.|-| '''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 lang="xquery">ft:mark(db:open('DB')//*[text() contains text 'hello'])</syntaxhighlight>'''Example 2''': The following expression loops through the first ten full-text results and marks the results in a second expression:<syntaxhighlight lang="xquery">let $start := 1let $end := 10let $term := 'welcome'for $ft in (db:open('DB')//*[text() contains text { $term }])[position() = $start to $end]return element hit { ft:mark($ft[text() contains text { $term }])}</syntaxhighlight>'''Example 3''': The following expression returns <code>&lt;xml>hello &lt;b&gt;word&lt;/b&gt;&lt;/xml&gt;</code>:<syntaxhighlight lang="xquery">copy $p := <xml>hello world</xml>modify ()return ft:mark($p[text() contains text 'word'], 'b')</syntaxhighlight>|} ==ft:extract== {| width='100%'|-| width='120' | '''Signatures'''|{{Func|ft:extract|$nodes as node()*|node()*}}<br />{{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|node()*}}|-| '''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 [[#ft:mark|ft:mark]].|-| '''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 lang="xquery">ft:extract(db:open('DB')//*[text() contains text 'hello'], 'b', 1)</syntaxhighlight>|}
==ft:count==
{| width='100%'
|-
|
* {{Code|ft:score('a' contains text 'a')}} returns the {{Code|xs:double}} value {{Code|1}}.
|}
 
==ft:tokens==
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|ft:tokens|$db as xs:string|element(value)*}}<br/>{{Func|ft:tokens|$db as xs:string, $prefix as xs:string|element(value)*}}
|-
| '''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.
|-
| '''Errors'''
|{{Error|db:open|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.
|-
| '''Examples'''
|Returns the number of occurrences for a single, specific index entry:
<syntaxhighlight lang="xquery">
let $term := ft:tokenize($term)
return number(ft:tokens('db', $term)[. = $term]/@count)
</syntaxhighlight>
|}
|
* <code>ft:tokenize("Häuser am Meer", map { 'case': 'sensitive' })</code> returns the string {{Code|Hauser am Meer}}.
|}
 
=Highlighting Functions=
 
==ft:mark==
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|ft:mark|$nodes as node()*|node()*}}<br />{{Func|ft:mark|$nodes as node()*, $name as xs:string|node()*}}
|-
| '''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.
|-
| '''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 lang="xquery">
ft:mark(db:open('DB')//*[text() contains text 'hello'])
</syntaxhighlight>
'''Example 2''': The following expression loops through the first ten full-text results and marks the results in a second expression:
<syntaxhighlight lang="xquery">
let $start := 1
let $end := 10
let $term := 'welcome'
for $ft in (db:open('DB')//*[text() contains text { $term }])[position() = $start to $end]
return element hit {
ft:mark($ft[text() contains text { $term }])
}
</syntaxhighlight>
'''Example 3''': The following expression returns <code>&lt;xml>hello &lt;b&gt;word&lt;/b&gt;&lt;/xml&gt;</code>:
<syntaxhighlight lang="xquery">
copy $p := <xml>hello world</xml>
modify ()
return ft:mark($p[text() contains text 'word'], 'b')
</syntaxhighlight>
|}
 
==ft:extract==
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|ft:extract|$nodes as node()*|node()*}}<br />{{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|node()*}}
|-
| '''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 [[#ft:mark|ft:mark]].
|-
| '''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 lang="xquery">
ft:extract(db:open('DB')//*[text() contains text 'hello'], 'b', 1)
</syntaxhighlight>
|}
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu