@@ -202,6 +202,9 @@ public ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvaluator) {
202202 List <EsPhysicalOperationProviders .ShardContext > shardContexts = toEvaluator .shardContexts ();
203203 LuceneQueryEvaluator .ShardConfig [] shardConfigs = new LuceneQueryEvaluator .ShardConfig [shardContexts .size ()];
204204
205+ Integer numSnippets = this .numSnippets == null ?DEFAULT_NUM_SNIPPETS : (Integer ) this .numSnippets .fold (FoldContext .small ());
206+ Integer snippedSize = this .snippetLength == null ? DEFAULT_SNIPPET_LENGTH : (Integer ) this .snippetLength .fold (FoldContext .small ());
207+
205208 int i = 0 ;
206209 for (EsPhysicalOperationProviders .ShardContext shardContext : shardContexts ) {
207210 SearchExecutionContext searchExecutionContext = shardContext .searchExecutionContext ();
@@ -210,6 +213,7 @@ public ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvaluator) {
210213 throw new IllegalStateException ("Missing search context, cannot extract snippets" );
211214 }
212215
216+
213217 try {
214218 // TODO: Reduce duplication between this method and TextSimilarityRerankingRankFeaturePhaseRankShardContext#prepareForFetch
215219 HighlightBuilder highlightBuilder = new HighlightBuilder ();
@@ -220,9 +224,10 @@ public ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvaluator) {
220224 highlightBuilder .field (field .sourceText ()).preTags ("" ).postTags ("" );
221225 // Return highest scoring fragments
222226 highlightBuilder .order (HighlightBuilder .Order .SCORE );
223- highlightBuilder .numOfFragments (Integer .parseInt (numSnippets .sourceText ()));
224- highlightBuilder .fragmentSize (Integer .parseInt (snippetLength .sourceText ()));
225- highlightBuilder .noMatchSize (Integer .parseInt (snippetLength .sourceText ()));
227+
228+ highlightBuilder .numOfFragments (numSnippets );
229+ highlightBuilder .fragmentSize (snippedSize );
230+ highlightBuilder .noMatchSize (snippedSize );
226231
227232 SearchHighlightContext highlightContext = highlightBuilder .build (searchExecutionContext );
228233 searchContext .highlight (highlightContext );
@@ -234,9 +239,9 @@ public ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvaluator) {
234239 + "], str ["
235240 + str .sourceText ()
236241 + "], numSnippets: ["
237- + Integer . parseInt ( numSnippets . sourceText ())
242+ + numSnippets
238243 + "], snippetLength: ["
239- + Integer . parseInt ( snippetLength . sourceText ())
244+ + snippetLength
240245 + "]" ,
241246 e
242247 );
@@ -246,10 +251,8 @@ public ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvaluator) {
246251 }
247252 // Get field name and search context from the first shard context
248253 String fieldNameStr = field .sourceText ();
249- int numFragments = numSnippets == null ? DEFAULT_NUM_SNIPPETS : Integer .parseInt (numSnippets .sourceText ());
250- int fragmentSize = snippetLength == null ? DEFAULT_SNIPPET_LENGTH : Integer .parseInt (snippetLength .sourceText ());
251254 SearchContext firstSearchContext = shardContexts .isEmpty () ? null : shardContexts .get (0 ).searchContext ();
252- return new HighlighterExpressionEvaluator .Factory (shardConfigs , fieldNameStr , numFragments , fragmentSize , firstSearchContext );
255+ return new HighlighterExpressionEvaluator .Factory (shardConfigs , fieldNameStr , numSnippets , snippedSize , firstSearchContext );
253256 }
254257
255258 @ Override
0 commit comments