Method GetBestFragments
GetBestFragments(Analyzer, String, String, Int32)
Highlights chosen terms in a text, extracting the most relevant sections. This is a convenience method that calls GetBestFragments(TokenStream, String, Int32)
Declaration
public string[] GetBestFragments(Analyzer analyzer, string fieldName, string text, int maxNumFragments)
Parameters
Type | Name | Description |
---|---|---|
Analyzer | analyzer | the analyzer that will be used to split |
System.String | fieldName | the name of the field being highlighted (used by analyzer) |
System.String | text | text to highlight terms in |
System.Int32 | maxNumFragments | the maximum number of fragments. |
Returns
Type | Description |
---|---|
System.String[] | highlighted text fragments (between 0 and |
Exceptions
Type | Condition |
---|---|
InvalidTokenOffsetsException | thrown if any token's EndOffset exceeds the provided text's length |
GetBestFragments(TokenStream, String, Int32)
Highlights chosen terms in a text, extracting the most relevant sections. The document text is analysed in chunks to record hit statistics across the document. After accumulating stats, the fragments with the highest scores are returned as an array of strings in order of score (contiguous fragments are merged into one in their original order to improve readability)
Declaration
public string[] GetBestFragments(TokenStream tokenStream, string text, int maxNumFragments)
Parameters
Type | Name | Description |
---|---|---|
TokenStream | tokenStream | |
System.String | text | text to highlight terms in |
System.Int32 | maxNumFragments | the maximum number of fragments. |
Returns
Type | Description |
---|---|
System.String[] | highlighted text fragments (between 0 and |
Exceptions
Type | Condition |
---|---|
InvalidTokenOffsetsException | thrown if any token's EndOffset exceeds the provided text's length |
GetBestFragments(TokenStream, String, Int32, String)
Highlights terms in the text
, extracting the most relevant sections
and concatenating the chosen fragments with a separator (typically "...").
The document text is analysed in chunks to record hit statistics
across the document. After accumulating stats, the fragments with the highest scores
are returned in order as "separator" delimited strings.
Declaration
public virtual string GetBestFragments(TokenStream tokenStream, string text, int maxNumFragments, string separator)
Parameters
Type | Name | Description |
---|---|---|
TokenStream | tokenStream | |
System.String | text | text to highlight terms in |
System.Int32 | maxNumFragments | the maximum number of fragments. |
System.String | separator | the separator used to intersperse the document fragments (typically "...") |
Returns
Type | Description |
---|---|
System.String | highlighted text |
Exceptions
Type | Condition |
---|---|
InvalidTokenOffsetsException | thrown if any token's EndOffset exceeds the provided text's length |