![]() By having access to the node, you can create expressions that do things in the context of that node. The $cts:node variable provides access to the text node in which the match occurs. Using the $cts:node Variable to Access the Context of the Match For example, the following query finds all of the nodes that contain the word foo, and then replaces the word bar in those nodes with the word baz: for $x in cts:search(fn:doc(), "foo")īecause you can use any XQuery expression as the replace expression, you can perform some very complex search and replace operations with a relatively small amount of code. This query happens to use the same search query in the cts:search as it does in the cts:highlight, but that is not required (although it is typical of text highlighting requirements). For example, if you wanted to replace every instance of the term content database with contentbase, you could issue a query similar to the following: for $x in cts:search(//mynode, "content database")Ĭts:highlight($x, "content database", "contentbase") Queries that use cts:highlight will find all of these matches and replace them with whatever the specified expression evaluates to.Īlthough it is designed to make highlighting easy, cts:highlight can be used for much more general search and replace operations. Additionally, wildcard matches (if wildcard indexes are enabled) will match a whole range of queries. Similarly, query matches can have different capitalization than the exact word for which you actually searched. For details on stemming, see Understanding and Using Stemmed Searches. For example, run, running, and ran all match a query for run. If you have stemmed searches enabled, matches can be more than exact text matches. A cts:highlight query match, however, is anything that matches the cts:query specified as the second argument of cts:highlight. If you are trying to highlight matches from a cts:search query, exact string matches will not find all of the hits that match the query. When you use the standard XQuery string functions such as fn:replace and fn:contains to find matches, you must specify the exact string you want to match. ![]() Consulting Services Expert implementationĪll Matching Terms, Including Stemmed, and Capitalized. ![]()
0 Comments
Leave a Reply. |