Changes

Jump to navigation Jump to search
4,996 bytes added ,  21:06, 13 December 2010
Created page with "This module extends the XQuery Full Text Recommendation with some useful functions: The index can be directly accessed, full-text results can be marked with additional elements, ..."
This module extends the XQuery Full Text Recommendation with some useful functions: The index can be directly accessed, full-text results can be marked with additional elements, or the relevant parts can be extracted. Moreover, the score value, which is generated by the <code>contains text</code> expression, can be explicitly requested from items. All functions are introduced with the <code>ft:</code> prefix.

==ft:search==
{|
|-
| valign='top' width='90' | '''Signatures'''
|<code><b>ft:search</b>($node as node(), $text as xs:string) as text()</code><br />
|-
| valign='top' | '''Summary'''
|Performs a full-text index request.
|-
| valign='top' | '''Rules'''
|This function performs an explicit full-text index request on the specified database node and returns all text nodes that contain the string <code>$text</code>. The index full-text options are used for searching, i.e., if the index terms were stemmed, the search string will be stemmed as well.<br />
|-
| valign='top' | '''Examples'''
|The expression <code>ft:search(., "QUERY")</code> returns all text nodes of the currently opened database that contain the string "QUERY".<br />
|-
| valign='top' | '''Errors'''
|<b>[BASX0002]</b> is raised if the context item does not represent a database node.<br />
|}

==ft:mark==
{|
|-
| valign='top' width='90' | '''Signatures'''
|<code><b>ft:mark</b>($nodes as node()*) as node()*</code><br /><code><b>ft:mark</b>($nodes as node()*, $tag as xs:string) as node()*</code><br />
|-
| valign='top' | '''Summary'''
|Marks results from a full-text index request.
|-
| valign='top' | '''Rules'''
|This function puts a marker element around the resulting <code>$nodes</code> of a full-text index request.<br />The default tag name of the marker element is <code>mark</code>. An alternative tag name can be chosen via the optional <code>$tag</code> argument.<br />Note that the XML node to be transformed must be an internal "database" node. The <code>transform</code> expression can be used to apply the method to a main-memory fragment (see example).<br />
|-
| valign='top' | '''Examples'''
|The following query returns <code>&lt;XML&gt;&lt;mark&gt;hello&lt;/mark&gt; world&lt;/XML&gt;</code>, if one text node of the database <code>DB</code> has the value "hello world":<br />
<code>ft:mark(db:open('DB')//*[text() contains text 'hello'])</code><br />The following expression returns <code>&lt;p&gt;&lt;b&gt;word&lt;/b&gt;&lt;/p&gt;</code>:<br />
<code>copy $p := &lt;p&gt;word&lt;/p&gt;</code><br />
<code>modify ()</code><br />
<code>return ft:mark($p[text() contains text 'word'], 'b')</code><br />
|-
| valign='top' | '''Errors'''
|<b>[BASX0002]</b> is raised if the context item does not represent a database node.<br /><b>[FOCA0002]</b> is raised if <code>$name</code> is no valid QName.<br />
|}

==ft:extract==
{|
|-
| valign='top' width='90' | '''Signatures'''
|<code><b>ft:extract</b>($nodes as node()*) as node()*</code><br /><code><b>ft:extract</b>($nodes as node()*, $tag as xs:string) as node()*</code><br /><code><b>ft:extract</b>($nodes as node()*, $tag as xs:string, $length as xs:integer) as node()*</code><br />
|-
| valign='top' | '''Summary'''
|Extracts relevant parts of full-text results.
|-
| valign='top' | '''Rules'''
|This function extracts and returns relevant parts of full-text results. It puts a marker element around the resulting <code>$nodes</code> of a full-text index request and chops irrelevant sections of the result.<br />The default tag name of the marker element is <code>mark</code>. An alternative tag name can be chosen via the optional <code>$tag</code> argument.<br />The default length of the returned text is <code>150</code> characters. An alternative length can be specified via the optional <code>$length</code> argument. Note that the effective text length may differ from the specified text due to formatting and readibility issues.<br />
|-
| valign='top' | '''Examples'''
|The following query may return <code>&lt;XML&gt;...&lt;b&gt;hello&lt;/b&gt;...&lt;XML&gt;</code> if a text node of the database <code>DB</code> contains the string "hello world":<br />
<code>ft:extract(db:open('DB')//*[text() contains text 'hello'], 'b', 1)</code><br />
|-
| valign='top' | '''Errors'''
|<b>[BASX0002]</b> is raised if the context item does not represent a database node.<br /><b>[FOCA0002]</b> is raised if <code>$name</code> is no valid QName.<br />
|}

==ft:score==
{|
|-
| valign='top' width='90' | '''Signatures'''
|<code><b>ft:score</b>($item as item()*) as xs:double*</code><br />
|-
| valign='top' | '''Summary'''
|Returns the score of items.
|-
| valign='top' | '''Rules'''
|This function returns the score values (0.0 - 1.0) that have been attached to the specified items. <code>0</code> is returned if no score was attached.<br />
|-
| valign='top' | '''Examples'''
|The expression <code>ft:score('a' contains text 'a')</code> returns the <code>xs:double</code> value <code>1</code>.<br />
|}

[[Category:XQuery]]
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu