ElasticsearchIndexSearcher extends BaseIndexSearcher { protected SearchSearchRequest createSearchSearchRequest( SearchRequest searchRequest, SearchContext searchContext, Query query, int start, int end) { SearchSearchRequest searchSearchRequest = new SearchSearchRequest(); prepare(searchSearchRequest, searchRequest, query, searchContext); QueryConfig queryConfig = searchContext.getQueryConfig(); searchSearchRequest.setAlternateUidFieldName( queryConfig.getAlternateUidFieldName()); searchSearchRequest.setBasicFacetSelection( searchRequest.isBasicFacetSelection()); searchSearchRequest.putAllFacets(searchContext.getFacets()); searchSearchRequest.setFetchSource(searchRequest.getFetchSource()); searchSearchRequest.setFetchSourceExcludes( searchRequest.getFetchSourceExcludes()); searchSearchRequest.setFetchSourceIncludes( searchRequest.getFetchSourceIncludes()); searchSearchRequest.setGroupBy(searchContext.getGroupBy()); searchSearchRequest.setGroupByRequests( searchRequest.getGroupByRequests()); searchSearchRequest.setHighlightEnabled( queryConfig.isHighlightEnabled()); searchSearchRequest.setHighlightFieldNames( queryConfig.getHighlightFieldNames()); searchSearchRequest.setHighlightFragmentSize( queryConfig.getHighlightFragmentSize()); searchSearchRequest.setHighlightSnippetSize( queryConfig.getHighlightSnippetSize()); searchSearchRequest.setLocale(queryConfig.getLocale()); searchSearchRequest.setHighlightRequireFieldMatch( queryConfig.isHighlightRequireFieldMatch()); boolean luceneSyntax = GetterUtil.getBoolean( searchContext.getAttribute( SearchContextAttributes.ATTRIBUTE_KEY_LUCENE_SYNTAX)); searchSearchRequest.setLuceneSyntax(luceneSyntax); String preference = (String)searchContext.getAttribute( ElasticsearchSearchContextAttributes. ATTRIBUTE_KEY_SEARCH_REQUEST_PREFERENCE); if (!Validator.isBlank(preference)) { searchSearchRequest.setPreference(preference); } searchSearchRequest.setScoreEnabled(queryConfig.isScoreEnabled()); searchSearchRequest.setSelectedFieldNames( queryConfig.getSelectedFieldNames()); int size = end - start; searchSearchRequest.setSize(size); searchSearchRequest.setStart(start); searchSearchRequest.setSorts(searchContext.getSorts()); searchSearchRequest.setSorts(searchRequest.getSorts()); searchSearchRequest.setStats(searchContext.getStats()); searchSearchRequest.setTrackTotalHits( _elasticsearchConfigurationWrapper.trackTotalHits()); return searchSearchRequest; }  @Override String getQueryString(SearchContext searchContext, Query query); @Override Hits search(SearchContext searchContext, Query query); @Override long searchCount(SearchContext searchContext, Query query); @Override @Reference(target = "(search.engine.impl=Elasticsearch)", unbind = "-") void setQuerySuggester(QuerySuggester querySuggester);  }
@Test public void testSearchContextAttributes() throws SearchException { SearchContext searchContext = new SearchContext(); searchContext.setAttribute( ElasticsearchSearchContextAttributes. ATTRIBUTE_KEY_SEARCH_REQUEST_PREFERENCE, "testValue"); searchContext.setAttribute( SearchContextAttributes.ATTRIBUTE_KEY_BASIC_FACET_SELECTION, Boolean.TRUE); searchContext.setAttribute( SearchContextAttributes.ATTRIBUTE_KEY_LUCENE_SYNTAX, Boolean.TRUE); SearchSearchRequest searchSearchRequest = _elasticsearchIndexSearcher.createSearchSearchRequest( _searchRequestBuilderFactory.builder( searchContext ).build(), searchContext, Mockito.mock(Query.class), 0, 0); Assert.assertTrue(searchSearchRequest.isBasicFacetSelection()); Assert.assertTrue(searchSearchRequest.isLuceneSyntax()); Assert.assertEquals("testValue", searchSearchRequest.getPreference()); }