OpenWGA 7.0 - TMLScript reference

Method :

bestFragments(itemname, fragmentSize, maxFragments [, prefix] [, suffix] [, encode])

On object Lucene
Usage Returns those parts of an items value that matched a lucene search
Description The method provides an advanced feature of lucene result highlighting which automatically provides those fragments of an items content that matched the lucene query. The fragments are returned in descending order of relevance.

You must have activated the highlighting feature on the lucene search via attribute highlight. The fragments of the last lucene search stays available until another lucene search is performed under the same user session.

This method will only work when the document of the chosen context was directly retrieved from a lucene search result.

For backward compatibility there still is a method "bestFragments()" available on TMLContext whose use is discouraged since OpenWGA 5.3.

Parameters itemname (String): Name of the item on the current context document whose fragments are retrieved

fragmentSize (Number)
: Desired number of characters in the fragments

maxFragments (Number):
Maximum number of fragments to return.

prefix (String, optional): Prefix HTML code that is put out before each term in a fragment that was matched by the lucene query, meant to highlight those terms.

suffix (String, optional): Suffix HTML code that is put out after each term in a fragment that was matched by the lucene query, meant to close tags that were opened in the prefix.

encode (String, optional): A WebTML encoding to encode the fragments before output. Accepts the encodings also available to WebTML attribute encode
Return value List of text fragments (String)
Allowed in script types
  • WebTML pages and normal WebTML actions
Examples A simple example of a lucene query with a result that puts out best fragments of item "body", while highlighting found terms in red:

    <tml:query type="lucene" db="test1" highlight="true">
    <table border="1">
                        <tml:script divider="<br>">
                             return WGA.lucene().bestfragments("body", 25, 5, "<font color='red'>", "</font>");