diff --git a/lucene/contrib/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FastVectorHighlighter.java b/lucene/contrib/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FastVectorHighlighter.java index 54072b92520..9a3ffcfe377 100644 --- a/lucene/contrib/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FastVectorHighlighter.java +++ b/lucene/contrib/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FastVectorHighlighter.java @@ -77,6 +77,8 @@ public class FastVectorHighlighter { * @return the created {@link FieldQuery} object */ public FieldQuery getFieldQuery( Query query ) { + // TODO: should we deprecate this? + // because if there is no reader, then we cannot rewrite MTQ. try { return new FieldQuery( query, null, phraseHighlight, fieldMatch ); } catch (IOException e) { diff --git a/lucene/contrib/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldQuery.java b/lucene/contrib/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldQuery.java index 7df3635d530..a402d415fae 100644 --- a/lucene/contrib/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldQuery.java +++ b/lucene/contrib/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldQuery.java @@ -102,7 +102,7 @@ public class FieldQuery { if( !flatQueries.contains( sourceQuery ) ) flatQueries.add( sourceQuery ); } - else if (sourceQuery instanceof MultiTermQuery) { + else if (sourceQuery instanceof MultiTermQuery && reader != null) { MultiTermQuery copy = (MultiTermQuery) sourceQuery.clone(); copy.setRewriteMethod(new MultiTermQuery.TopTermsScoringBooleanQueryRewrite(MAX_MTQ_TERMS)); BooleanQuery mtqTerms = (BooleanQuery) copy.rewrite(reader); diff --git a/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java b/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java index 977e846f830..eef991e9ce2 100644 --- a/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java +++ b/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java @@ -364,7 +364,7 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf // FVH cannot process hl.requireFieldMatch parameter per-field basis params.getBool( HighlightParams.FIELD_MATCH, false ) ); fvh.setPhraseLimit(params.getInt(HighlightParams.PHRASE_LIMIT, Integer.MAX_VALUE)); - FieldQuery fieldQuery = fvh.getFieldQuery( query ); + FieldQuery fieldQuery = fvh.getFieldQuery( query, searcher.getIndexReader() ); // Highlight each document DocIterator iterator = docs.iterator();