Search in sources :

Example 1 with PhraseHelper

use of org.apache.lucene.search.uhighlight.PhraseHelper in project lucene-solr by apache.

the class TestUnifiedHighlighterExtensibility method testUnifiedHighlighterExtensibility.

/**
   * This test is for maintaining the extensibility of the UnifiedHighlighter
   * for customizations out of package.
   */
@Test
public void testUnifiedHighlighterExtensibility() {
    final int maxLength = 1000;
    UnifiedHighlighter uh = new UnifiedHighlighter(null, new MockAnalyzer(random())) {

        @Override
        protected Map<String, Object[]> highlightFieldsAsObjects(String[] fieldsIn, Query query, int[] docIdsIn, int[] maxPassagesIn) throws IOException {
            return super.highlightFieldsAsObjects(fieldsIn, query, docIdsIn, maxPassagesIn);
        }

        @Override
        protected OffsetSource getOffsetSource(String field) {
            return super.getOffsetSource(field);
        }

        @Override
        protected BreakIterator getBreakIterator(String field) {
            return super.getBreakIterator(field);
        }

        @Override
        protected PassageScorer getScorer(String field) {
            return super.getScorer(field);
        }

        @Override
        protected PassageFormatter getFormatter(String field) {
            return super.getFormatter(field);
        }

        @Override
        public Analyzer getIndexAnalyzer() {
            return super.getIndexAnalyzer();
        }

        @Override
        public IndexSearcher getIndexSearcher() {
            return super.getIndexSearcher();
        }

        @Override
        protected int getMaxNoHighlightPassages(String field) {
            return super.getMaxNoHighlightPassages(field);
        }

        @Override
        protected Boolean requiresRewrite(SpanQuery spanQuery) {
            return super.requiresRewrite(spanQuery);
        }

        @Override
        protected LimitedStoredFieldVisitor newLimitedStoredFieldsVisitor(String[] fields) {
            return super.newLimitedStoredFieldsVisitor(fields);
        }

        @Override
        protected List<CharSequence[]> loadFieldValues(String[] fields, DocIdSetIterator docIter, int cacheCharsThreshold) throws IOException {
            return super.loadFieldValues(fields, docIter, cacheCharsThreshold);
        }

        @Override
        protected FieldHighlighter getFieldHighlighter(String field, Query query, Set<Term> allTerms, int maxPassages) {
            // THIS IS A COPY of the superclass impl; but use CustomFieldHighlighter
            BytesRef[] terms = filterExtractedTerms(getFieldMatcher(field), allTerms);
            Set<HighlightFlag> highlightFlags = getFlags(field);
            PhraseHelper phraseHelper = getPhraseHelper(field, query, highlightFlags);
            CharacterRunAutomaton[] automata = getAutomata(field, query, highlightFlags);
            OffsetSource offsetSource = getOptimizedOffsetSource(field, terms, phraseHelper, automata);
            return new CustomFieldHighlighter(field, getOffsetStrategy(offsetSource, field, terms, phraseHelper, automata, highlightFlags), new SplittingBreakIterator(getBreakIterator(field), UnifiedHighlighter.MULTIVAL_SEP_CHAR), getScorer(field), maxPassages, getMaxNoHighlightPassages(field), getFormatter(field));
        }

        @Override
        protected FieldOffsetStrategy getOffsetStrategy(OffsetSource offsetSource, String field, BytesRef[] terms, PhraseHelper phraseHelper, CharacterRunAutomaton[] automata, Set<HighlightFlag> highlightFlags) {
            return super.getOffsetStrategy(offsetSource, field, terms, phraseHelper, automata, highlightFlags);
        }

        @Override
        public int getMaxLength() {
            return maxLength;
        }
    };
    assertEquals(uh.getMaxLength(), maxLength);
}
Also used : Set(java.util.Set) Query(org.apache.lucene.search.Query) SpanQuery(org.apache.lucene.search.spans.SpanQuery) CharacterRunAutomaton(org.apache.lucene.util.automaton.CharacterRunAutomaton) PhraseHelper(org.apache.lucene.search.uhighlight.PhraseHelper) SpanQuery(org.apache.lucene.search.spans.SpanQuery) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) UnifiedHighlighter(org.apache.lucene.search.uhighlight.UnifiedHighlighter) SplittingBreakIterator(org.apache.lucene.search.uhighlight.SplittingBreakIterator) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test)

Aggregations

Set (java.util.Set)1 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)1 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)1 Query (org.apache.lucene.search.Query)1 SpanQuery (org.apache.lucene.search.spans.SpanQuery)1 PhraseHelper (org.apache.lucene.search.uhighlight.PhraseHelper)1 SplittingBreakIterator (org.apache.lucene.search.uhighlight.SplittingBreakIterator)1 UnifiedHighlighter (org.apache.lucene.search.uhighlight.UnifiedHighlighter)1 BytesRef (org.apache.lucene.util.BytesRef)1 CharacterRunAutomaton (org.apache.lucene.util.automaton.CharacterRunAutomaton)1 Test (org.junit.Test)1