Search in sources :

Example 1 with BreakIteratorBoundaryScanner

use of org.apache.lucene.search.vectorhighlight.BreakIteratorBoundaryScanner in project elasticsearch by elastic.

the class FastVectorHighlighter method getBoundaryScanner.

private static BoundaryScanner getBoundaryScanner(Field field) {
    final FieldOptions fieldOptions = field.fieldOptions();
    final Locale boundaryScannerLocale = fieldOptions.boundaryScannerLocale() != null ? fieldOptions.boundaryScannerLocale() : Locale.ROOT;
    final HighlightBuilder.BoundaryScannerType type = fieldOptions.boundaryScannerType() != null ? fieldOptions.boundaryScannerType() : HighlightBuilder.BoundaryScannerType.CHARS;
    switch(type) {
        case SENTENCE:
            if (boundaryScannerLocale != null) {
                return new BreakIteratorBoundaryScanner(BreakIterator.getSentenceInstance(boundaryScannerLocale));
            }
            return DEFAULT_SENTENCE_BOUNDARY_SCANNER;
        case WORD:
            if (boundaryScannerLocale != null) {
                return new BreakIteratorBoundaryScanner(BreakIterator.getWordInstance(boundaryScannerLocale));
            }
            return DEFAULT_WORD_BOUNDARY_SCANNER;
        case CHARS:
            if (fieldOptions.boundaryMaxScan() != SimpleBoundaryScanner.DEFAULT_MAX_SCAN || fieldOptions.boundaryChars() != SimpleBoundaryScanner.DEFAULT_BOUNDARY_CHARS) {
                return new SimpleBoundaryScanner(fieldOptions.boundaryMaxScan(), fieldOptions.boundaryChars());
            }
            return DEFAULT_SIMPLE_BOUNDARY_SCANNER;
        default:
            throw new IllegalArgumentException("Invalid boundary scanner type: " + type.toString());
    }
}
Also used : Locale(java.util.Locale) SimpleBoundaryScanner(org.apache.lucene.search.vectorhighlight.SimpleBoundaryScanner) BreakIteratorBoundaryScanner(org.apache.lucene.search.vectorhighlight.BreakIteratorBoundaryScanner) FieldOptions(org.elasticsearch.search.fetch.subphase.highlight.SearchContextHighlight.FieldOptions)

Aggregations

Locale (java.util.Locale)1 BreakIteratorBoundaryScanner (org.apache.lucene.search.vectorhighlight.BreakIteratorBoundaryScanner)1 SimpleBoundaryScanner (org.apache.lucene.search.vectorhighlight.SimpleBoundaryScanner)1 FieldOptions (org.elasticsearch.search.fetch.subphase.highlight.SearchContextHighlight.FieldOptions)1