Apache Solr open-source search software
LUCENE-7293: don't try to highlight GeoPoint queries
Mike McCandlessaa90b88e2d21
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 5eabdb42f10..00fc633abc9 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -124,6 +124,9 @@ Bug Fixes* LUCENE-7231: WeightedSpanTermExtractor didn't deal correctly with single-termphrase queries. (Eva Popenda, Alan Woodward)+* LUCENE-7293: Don't try to highlight GeoPoint queries (Britta Weber,+ Nick Knize, Mike McCandless)+Documentation* LUCENE-7223: Improve XXXPoint javadocs to make it clear that youdiff --git a/lucene/highlighter/build.xml b/lucene/highlighter/build.xmlindex e0dfa7ef86f..e706b998a73 100644--- a/lucene/highlighter/build.xml+++ b/lucene/highlighter/build.xml@@ -31,12 +31,13 @@<path id="classpath"><pathelement path="${memory.jar}"/><pathelement path="${queries.jar}"/>+ <pathelement path="${spatial.jar}"/><pathelement path="${join.jar}"/><pathelement path="${analyzers-common.jar}"/><path refid="base.classpath"/></path>- <target name="compile-core" depends="jar-memory,jar-queries,jar-join,jar-analyzers-common,common.compile-core" />+ <target name="compile-core" depends="jar-memory,jar-spatial,jar-queries,jar-join,jar-analyzers-common,common.compile-core" /><target name="javadocs" depends="javadocs-memory,compile-core,check-javadocs-uptodate"unless="javadocs-uptodate-${name}">diff --git a/lucene/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java b/lucene/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.javaindex 89cbd11cba9..14acb9d6c70 100644--- a/lucene/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java+++ b/lucene/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java@@ -62,9 +62,10 @@ import org.apache.lucene.search.spans.SpanNearQuery;import org.apache.lucene.search.spans.SpanNotQuery;import org.apache.lucene.search.spans.SpanOrQuery;import org.apache.lucene.search.spans.SpanQuery;-import org.apache.lucene.search.spans.Spans;import org.apache.lucene.search.spans.SpanTermQuery;import org.apache.lucene.search.spans.SpanWeight;+import org.apache.lucene.search.spans.Spans;+import org.apache.lucene.spatial.geopoint.search.GeoPointInBBoxQuery;import org.apache.lucene.util.Bits;import org.apache.lucene.util.IOUtils;@@ -211,6 +212,8 @@ public class WeightedSpanTermExtractor {//nothing} else if (query instanceof CustomScoreQuery){extract(((CustomScoreQuery) query).getSubQuery(), boost, terms);+ } else if (query instanceof GeoPointInBBoxQuery) {+ // nothing} else {Query origQuery = query;final IndexReader reader = getLeafContext().reader();diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.javaindex 0a034f1ac36..c6dc8630c4c 100644--- a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java+++ b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java@@ -16,8 +16,6 @@*/package org.apache.lucene.search.highlight;-import javax.xml.parsers.DocumentBuilder;-import javax.xml.parsers.DocumentBuilderFactory;import java.io.ByteArrayInputStream;import java.io.IOException;import java.nio.charset.StandardCharsets;@@ -29,6 +27,8 @@ import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.StringTokenizer;+import javax.xml.parsers.DocumentBuilder;+import javax.xml.parsers.DocumentBuilderFactory;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.BaseTokenStreamTestCase;@@ -53,21 +53,22 @@ import org.apache.lucene.document.TextField;import org.apache.lucene.index.DirectoryReader;import org.apache.lucene.index.IndexReader;import org.apache.lucene.index.IndexWriter;-import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.index.IndexWriterConfig.OpenMode;+import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.index.Term;import org.apache.lucene.queries.CommonTermsQuery;import org.apache.lucene.queries.CustomScoreQuery;import org.apache.lucene.queries.payloads.SpanPayloadCheckQuery;import org.apache.lucene.search.BooleanClause.Occur;+import org.apache.lucene.search.BooleanClause;import org.apache.lucene.search.BooleanQuery;import org.apache.lucene.search.ConstantScoreQuery;import org.apache.lucene.search.FuzzyQuery;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.MultiPhraseQuery;import org.apache.lucene.search.MultiTermQuery;-import org.apache.lucene.search.PhraseQuery;import org.apache.lucene.search.PhraseQuery.Builder;+import org.apache.lucene.search.PhraseQuery;import org.apache.lucene.search.PrefixQuery;import org.apache.lucene.search.Query;import org.apache.lucene.search.RegexpQuery;@@ -87,6 +88,7 @@ import org.apache.lucene.search.spans.SpanNotQuery;import org.apache.lucene.search.spans.SpanOrQuery;import org.apache.lucene.search.spans.SpanQuery;import org.apache.lucene.search.spans.SpanTermQuery;+import org.apache.lucene.spatial.geopoint.search.GeoPointInBBoxQuery;import org.apache.lucene.store.Directory;import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.LuceneTestCase;@@ -163,6 +165,28 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte}+ public void testGeoPointQueryHighlight() throws Exception {+ BooleanQuery boolQuery = new BooleanQuery.Builder().add(+ new BooleanClause(new GeoPointInBBoxQuery("geo_point", -64.92354174306496+ , 61.10078883158897, -170.15625, 118.47656249999999), BooleanClause.Occur.SHOULD)).add(+ new BooleanClause(new TermQuery(new Term(FIELD_NAME, "instances")), BooleanClause.Occur.SHOULD)).build();+ CustomScoreQuery query = new CustomScoreQuery(boolQuery);++ searcher = newSearcher(reader);+ TopDocs hits = searcher.search(query, 10);+ QueryScorer scorer = new QueryScorer(query, FIELD_NAME);+ Highlighter highlighter = new Highlighter(scorer);++ final int docId0 = hits.scoreDocs[0].doc;+ Document doc = searcher.doc(docId0);+ String storedField = doc.get(FIELD_NAME);++ TokenStream stream = getAnyTokenStream(FIELD_NAME, docId0);+ Fragmenter fragmenter = new SimpleSpanFragmenter(scorer);+ highlighter.setTextFragmenter(fragmenter);+ highlighter.getBestFragment(stream, storedField);+ }+public void testQueryScorerHits() throws Exception {PhraseQuery phraseQuery = new PhraseQuery(FIELD_NAME, "very", "long");