bestFragments(itemname, fragmentSize, maxFragments [, prefix] [, suffix] [, encode])
Returns those parts of an items value that matched a lucene search
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.
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
List of text fragments (String)
|Allowed in script types||
A simple example of a lucene query with a result that puts out best fragments of item "body", while highlighting found terms in red: