@@ -202,6 +202,9 @@ public ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvaluator) {
202
202
List <EsPhysicalOperationProviders .ShardContext > shardContexts = toEvaluator .shardContexts ();
203
203
LuceneQueryEvaluator .ShardConfig [] shardConfigs = new LuceneQueryEvaluator .ShardConfig [shardContexts .size ()];
204
204
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
+
205
208
int i = 0 ;
206
209
for (EsPhysicalOperationProviders .ShardContext shardContext : shardContexts ) {
207
210
SearchExecutionContext searchExecutionContext = shardContext .searchExecutionContext ();
@@ -210,6 +213,7 @@ public ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvaluator) {
210
213
throw new IllegalStateException ("Missing search context, cannot extract snippets" );
211
214
}
212
215
216
+
213
217
try {
214
218
// TODO: Reduce duplication between this method and TextSimilarityRerankingRankFeaturePhaseRankShardContext#prepareForFetch
215
219
HighlightBuilder highlightBuilder = new HighlightBuilder ();
@@ -220,9 +224,10 @@ public ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvaluator) {
220
224
highlightBuilder .field (field .sourceText ()).preTags ("" ).postTags ("" );
221
225
// Return highest scoring fragments
222
226
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 );
226
231
227
232
SearchHighlightContext highlightContext = highlightBuilder .build (searchExecutionContext );
228
233
searchContext .highlight (highlightContext );
@@ -234,9 +239,9 @@ public ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvaluator) {
234
239
+ "], str ["
235
240
+ str .sourceText ()
236
241
+ "], numSnippets: ["
237
- + Integer . parseInt ( numSnippets . sourceText ())
242
+ + numSnippets
238
243
+ "], snippetLength: ["
239
- + Integer . parseInt ( snippetLength . sourceText ())
244
+ + snippetLength
240
245
+ "]" ,
241
246
e
242
247
);
@@ -246,10 +251,8 @@ public ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvaluator) {
246
251
}
247
252
// Get field name and search context from the first shard context
248
253
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 ());
251
254
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 );
253
256
}
254
257
255
258
@ Override
0 commit comments