use of org.elasticsearch.search.fetch.subphase.highlight.SearchContextHighlight in project elasticsearch by elastic.
the class PercolatorHighlightSubFetchPhase method createSubSearchContext.
private SubSearchContext createSubSearchContext(SearchContext context, LeafReaderContext leafReaderContext, BytesReference source) {
SubSearchContext subSearchContext = new SubSearchContext(context);
subSearchContext.highlight(new SearchContextHighlight(context.highlight().fields()));
// Enforce highlighting by source, because MemoryIndex doesn't support stored fields.
subSearchContext.highlight().globalForceSource(true);
subSearchContext.lookup().source().setSegmentAndDocument(leafReaderContext, 0);
subSearchContext.lookup().source().setSource(source);
return subSearchContext;
}
use of org.elasticsearch.search.fetch.subphase.highlight.SearchContextHighlight in project elasticsearch by elastic.
the class PercolatorHighlightSubFetchPhaseTests method testHitsExecutionNeeded.
public void testHitsExecutionNeeded() {
PercolateQuery percolateQuery = new PercolateQuery("", ctx -> null, new BytesArray("{}"), new MatchAllDocsQuery(), Mockito.mock(IndexSearcher.class), new MatchAllDocsQuery());
PercolatorHighlightSubFetchPhase subFetchPhase = new PercolatorHighlightSubFetchPhase(Settings.EMPTY, emptyMap());
SearchContext searchContext = Mockito.mock(SearchContext.class);
Mockito.when(searchContext.highlight()).thenReturn(new SearchContextHighlight(Collections.emptyList()));
Mockito.when(searchContext.query()).thenReturn(new MatchAllDocsQuery());
assertThat(subFetchPhase.hitsExecutionNeeded(searchContext), is(false));
Mockito.when(searchContext.query()).thenReturn(percolateQuery);
assertThat(subFetchPhase.hitsExecutionNeeded(searchContext), is(true));
}
Aggregations