Difference between revisions of "Full-Text Module"
Jump to navigation
Jump to search
Line 5: | Line 5: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>ft:search</b>($node as node(), $text as xs:string) as text()</code | + | |<code><b>ft:search</b>($node as node(), $text as xs:string) as text()</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Performs a 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.< | + | |Performs a 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. |
+ | |- | ||
+ | | valign='top' | '''Errors''' | ||
+ | |<b>[[XQuery Errors#BaseX Errors (BASX)|BASX0002]]</b> is raised if the context item does not represent a database node. | ||
|- | |- | ||
| valign='top' | '''Examples''' | | valign='top' | '''Examples''' | ||
− | | | + | | |
− | + | * <code>ft:search(., "QUERY")</code> returns all text nodes of the currently opened database that contain the string "QUERY". | |
− | |||
− | |||
|} | |} | ||
Line 21: | Line 22: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>ft:mark</b>($nodes as node()*) as node()*</code | + | |<code><b>ft:mark</b>($nodes as node()*) as node()*</code><code><b>ft:mark</b>($nodes as node()*, $tag as xs:string) as node()*</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |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 /> | + | |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). |
+ | |- | ||
+ | | valign='top' | '''Errors''' | ||
+ | |<b>[[XQuery Errors#BaseX Errors (BASX)|BASX0002]]</b> is raised if the context item does not represent a database node.<br /><b>[[XQuery Errors#Functions Errors (FOAR, FOCA, FOCH, FODC, FODF, FODT, FOER, FOFD, FONS, FORG, FORX)|FOCA0002]]</b> is raised if <code>$name</code> is no valid QName. | ||
|- | |- | ||
| valign='top' | '''Examples''' | | valign='top' | '''Examples''' | ||
− | |The following query returns <code><XML><mark>hello</mark> world</XML></code>, if one text node of the database <code>DB</code> has the value "hello world":< | + | | |
− | + | * The following query returns <code><XML><mark>hello</mark> world</XML></code>, if one text node of the database <code>DB</code> has the value "hello world": | |
− | + | <pre class="brush:xquery"> | |
− | + | ft:mark(db:open('DB')//*[text() contains text 'hello']) | |
− | + | </pre> | |
− | + | * The following expression returns <code><p><b>word</b></p></code>: | |
− | + | <pre class="brush:xquery"> | |
− | + | copy $p := <p>word</p> | |
+ | modify () | ||
+ | return ft:mark($p[text() contains text 'word'], 'b')</pre> | ||
|} | |} | ||
Line 41: | Line 47: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | 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 | + | |<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> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |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 /> | + | |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. |
+ | |- | ||
+ | | valign='top' | '''Errors''' | ||
+ | |<b>[[XQuery Errors#BaseX Errors (BASX)|BASX0002]]</b> is raised if the context item does not represent a database node.<br /><b>[[XQuery Errors#Functions Errors (FOAR, FOCA, FOCH, FODC, FODF, FODT, FOER, FOFD, FONS, FORG, FORX)|FOCA0002]]</b> is raised if <code>$name</code> is no valid QName. | ||
|- | |- | ||
| valign='top' | '''Examples''' | | valign='top' | '''Examples''' | ||
− | |The following query may return <code><XML>...<b>hello</b>...<XML></code> if a text node of the database <code>DB</code> contains the string "hello world":< | + | | |
− | + | * The following query may return <code><XML>...<b>hello</b>...<XML></code> if a text node of the database <code>DB</code> contains the string "hello world": | |
− | + | <pre class="brush:xquery"> | |
− | + | ft:extract(db:open('DB')//*[text() contains text 'hello'], 'b', 1) | |
− | + | </pre> | |
|} | |} | ||
Line 58: | Line 67: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>ft:score</b>($item as item()*) as xs:double*</code | + | |<code><b>ft:score</b>($item as item()*) as xs:double*</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns the score values (0.0 - 1.0) that have been attached to the specified items. <code>0</code> is returned a value if no score was attached. | + | |Returns the score values (0.0 - 1.0) that have been attached to the specified items. <code>0</code> is returned a value if no score was attached. |
|- | |- | ||
| valign='top' | '''Examples''' | | valign='top' | '''Examples''' | ||
− | | | + | | |
+ | * <code>ft:score('a' contains text 'a')</code> returns the <code>xs:double</code> value <code>1</code>. | ||
|} | |} | ||
[[Category:XQuery]] | [[Category:XQuery]] |
Revision as of 16:18, 23 April 2011
This module extends the W3C Full Text Recommendation with some useful XQuery 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 contains text
expression, can be explicitly requested from items. All functions are introduced with the ft:
prefix, which is linked to the http://www.basex.org/ft
namespace.
Contents
ft:search
Signatures | ft:search($node as node(), $text as xs:string) as text()
|
Summary | Performs a full-text index request on the specified database node and returns all text nodes that contain the string $text . 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.
|
Errors | BASX0002 is raised if the context item does not represent a database node. |
Examples |
|
ft:mark
Signatures | ft:mark($nodes as node()*) as node()* ft:mark($nodes as node()*, $tag as xs:string) as node()*
|
Summary | Puts a marker element around the resulting $nodes of a full-text index request.The default tag name of the marker element is mark . An alternative tag name can be chosen via the optional $tag argument.Note that the XML node to be transformed must be an internal "database" node. The transform expression can be used to apply the method to a main-memory fragment (see example).
|
Errors | BASX0002 is raised if the context item does not represent a database node. FOCA0002 is raised if $name is no valid QName.
|
Examples |
ft:mark(db:open('DB')//*[text() contains text 'hello'])
copy $p := <p>word</p> modify () return ft:mark($p[text() contains text 'word'], 'b') |
ft:extract
Signatures | ft:extract($nodes as node()*) as node()* ft:extract($nodes as node()*, $tag as xs:string) as node()* ft:extract($nodes as node()*, $tag as xs:string, $length as xs:integer) as node()*
|
Summary | Extracts and returns relevant parts of full-text results. It puts a marker element around the resulting $nodes of a full-text index request and chops irrelevant sections of the result.The default tag name of the marker element is mark . An alternative tag name can be chosen via the optional $tag argument.The default length of the returned text is 150 characters. An alternative length can be specified via the optional $length argument. Note that the effective text length may differ from the specified text due to formatting and readibility issues.
|
Errors | BASX0002 is raised if the context item does not represent a database node. FOCA0002 is raised if $name is no valid QName.
|
Examples |
ft:extract(db:open('DB')//*[text() contains text 'hello'], 'b', 1) |
ft:score
Signatures | ft:score($item as item()*) as xs:double*
|
Summary | Returns the score values (0.0 - 1.0) that have been attached to the specified items. 0 is returned a value if no score was attached.
|
Examples |
|