Search in sources :

Example 1 with SearchContextHighlight

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;
}
Also used : SearchContextHighlight(org.elasticsearch.search.fetch.subphase.highlight.SearchContextHighlight) SubSearchContext(org.elasticsearch.search.internal.SubSearchContext)

Example 2 with SearchContextHighlight

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));
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) BytesArray(org.elasticsearch.common.bytes.BytesArray) SearchContext(org.elasticsearch.search.internal.SearchContext) SearchContextHighlight(org.elasticsearch.search.fetch.subphase.highlight.SearchContextHighlight) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Aggregations

SearchContextHighlight (org.elasticsearch.search.fetch.subphase.highlight.SearchContextHighlight)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 BytesArray (org.elasticsearch.common.bytes.BytesArray)1 SearchContext (org.elasticsearch.search.internal.SearchContext)1 SubSearchContext (org.elasticsearch.search.internal.SubSearchContext)1