Removed empty fragments in highlight results

This commit is contained in:
Alberto Paro 2011-02-10 14:19:26 +01:00 committed by kimchy
parent 5ea58a3387
commit 35c339f5f3
1 changed files with 8 additions and 4 deletions

View File

@ -148,8 +148,10 @@ public class HighlightPhase implements SearchHitPhase {
for (int i = 0; i < fragments.length; i++) { for (int i = 0; i < fragments.length; i++) {
fragments[i] = fragsList.get(i).toString(); fragments[i] = fragsList.get(i).toString();
} }
if (fragments.length>0){
HighlightField highlightField = new HighlightField(field.field(), fragments); HighlightField highlightField = new HighlightField(field.field(), fragments);
highlightFields.put(highlightField.name(), highlightField); highlightFields.put(highlightField.name(), highlightField);
}
} else { } else {
FastVectorHighlighter highlighter = buildHighlighter(context, mapper, field); FastVectorHighlighter highlighter = buildHighlighter(context, mapper, field);
FieldQuery fieldQuery = buildFieldQuery(highlighter, context.query(), hitContext.reader(), field); FieldQuery fieldQuery = buildFieldQuery(highlighter, context.query(), hitContext.reader(), field);
@ -162,10 +164,12 @@ public class HighlightPhase implements SearchHitPhase {
} catch (IOException e) { } catch (IOException e) {
throw new FetchPhaseExecutionException(context, "Failed to highlight field [" + field.field() + "]", e); throw new FetchPhaseExecutionException(context, "Failed to highlight field [" + field.field() + "]", e);
} }
if (fragments.length>0){
HighlightField highlightField = new HighlightField(field.field(), fragments); HighlightField highlightField = new HighlightField(field.field(), fragments);
highlightFields.put(highlightField.name(), highlightField); highlightFields.put(highlightField.name(), highlightField);
} }
} }
}
hitContext.hit().highlightFields(highlightFields); hitContext.hit().highlightFields(highlightFields);
} finally { } finally {