Revert and fix "LUCENE-7293: don't try to highlight GeoPoint queries"

This commit is contained in:
Uwe Schindler 2016-05-21 00:28:50 +02:00
parent 9e793672e4
commit 25e913211b
5 changed files with 21 additions and 36 deletions

View File

@ -118,7 +118,7 @@ Bug Fixes
phrase queries. (Eva Popenda, Alan Woodward)
* LUCENE-7293: Don't try to highlight GeoPoint queries (Britta Weber,
Nick Knize, Mike McCandless)
Nick Knize, Mike McCandless, Uwe Schindler)
Documentation

View File

@ -167,7 +167,6 @@
<path id="classpath">
<pathelement path="${memory.jar}"/>
<pathelement path="${spatial.jar}"/>
<pathelement path="${highlighter.jar}"/>
<pathelement path="${analyzers-common.jar}"/>
<pathelement path="${queryparser.jar}"/>
@ -278,7 +277,7 @@
<echo>Benchmark output in JIRA table format is in file: ${shingle.jira.output.file}</echo>
</target>
<target name="init" depends="module-build.init,jar-memory,jar-highlighter,jar-spatial,jar-analyzers-common,jar-queryparser,jar-facet,jar-spatial-extras,jar-codecs,jar-join"/>
<target name="init" depends="module-build.init,jar-memory,jar-highlighter,jar-analyzers-common,jar-queryparser,jar-facet,jar-spatial-extras,jar-codecs,jar-join"/>
<target name="compile-test" depends="copy-alg-files-for-testing,module-build.compile-test"/>
<target name="copy-alg-files-for-testing" description="copy .alg files as resources for testing">

View File

@ -31,13 +31,12 @@
<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-spatial,jar-queries,jar-join,jar-analyzers-common,common.compile-core" />
<target name="compile-core" depends="jar-memory,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}">

View File

@ -62,10 +62,9 @@ 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;
@ -212,7 +211,7 @@ public class WeightedSpanTermExtractor {
//nothing
} else if (query instanceof CustomScoreQuery){
extract(((CustomScoreQuery) query).getSubQuery(), boost, terms);
} else if (query instanceof GeoPointInBBoxQuery) {
} else if (isQueryUnsupported(query.getClass())) {
// nothing
} else {
Query origQuery = query;
@ -236,6 +235,18 @@ public class WeightedSpanTermExtractor {
}
}
protected boolean isQueryUnsupported(Class<? extends Query> clazz) {
// spatial queries do not support highlighting:
if (clazz.getName().startsWith("org.apache.lucene.spatial.")) {
return true;
}
// spatial3d queries are also not supported:
if (clazz.getName().startsWith("org.apache.lucene.spatial3d.")) {
return true;
}
return false;
}
protected void extractUnknownQuery(Query query,
Map<String, WeightedSpanTerm> terms) throws IOException {

View File

@ -16,6 +16,8 @@
*/
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;
@ -27,8 +29,6 @@ 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,22 +53,21 @@ 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.OpenMode;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
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.Builder;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.PhraseQuery.Builder;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.RegexpQuery;
@ -88,7 +87,6 @@ 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;
@ -165,28 +163,6 @@ 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");