You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by cp...@apache.org on 2017/01/30 16:59:50 UTC
lucene-solr:branch_6x: LUCENE-7658: queryparser/xml CoreParser now
implements SpanQueryBuilder interface. (Daniel Collins, Christine Poerschke)
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x 0d5c3558c -> 59390ef76
LUCENE-7658: queryparser/xml CoreParser now implements SpanQueryBuilder interface. (Daniel Collins, Christine Poerschke)
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/59390ef7
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/59390ef7
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/59390ef7
Branch: refs/heads/branch_6x
Commit: 59390ef76dd83426b3dad5b2067760606e14687d
Parents: 0d5c355
Author: Christine Poerschke <cp...@apache.org>
Authored: Mon Jan 30 14:37:34 2017 +0000
Committer: Christine Poerschke <cp...@apache.org>
Committed: Mon Jan 30 16:59:17 2017 +0000
----------------------------------------------------------------------
lucene/CHANGES.txt | 3 +++
.../lucene/queryparser/xml/CoreParser.java | 18 +++++++++++++++++-
.../lucene/queryparser/xml/TestCoreParser.java | 19 +++++++++++++++++--
3 files changed, 37 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/59390ef7/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index cb0b5f3..22fa043 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -98,6 +98,9 @@ Other
* LUCENE-7666: Fix typos in lucene-join package info javadoc.
(Tom Saleeba via Christine Poerschke)
+* LUCENE-7658: queryparser/xml CoreParser now implements SpanQueryBuilder interface.
+ (Daniel Collins, Christine Poerschke)
+
======================= Lucene 6.4.1 =======================
Bug Fixes
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/59390ef7/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/CoreParser.java
----------------------------------------------------------------------
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/CoreParser.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/CoreParser.java
index 0ad7072..2d6f2a2 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/CoreParser.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/CoreParser.java
@@ -20,6 +20,7 @@ import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.queryparser.xml.builders.*;
import org.apache.lucene.search.Query;
+import org.apache.lucene.search.spans.SpanQuery;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -31,7 +32,7 @@ import java.io.InputStream;
/**
* Assembles a QueryBuilder which uses only core Lucene Query objects
*/
-public class CoreParser implements QueryBuilder {
+public class CoreParser implements QueryBuilder, SpanQueryBuilder {
protected String defaultField;
protected Analyzer analyzer;
@@ -115,6 +116,11 @@ public class CoreParser implements QueryBuilder {
return getQuery(parseXML(xmlStream).getDocumentElement());
}
+ // for test use
+ SpanQuery parseAsSpanQuery(InputStream xmlStream) throws ParserException {
+ return getSpanQuery(parseXML(xmlStream).getDocumentElement());
+ }
+
public void addQueryBuilder(String nodeName, QueryBuilder builder) {
queryFactory.addBuilder(nodeName, builder);
}
@@ -123,6 +129,11 @@ public class CoreParser implements QueryBuilder {
spanFactory.addBuilder(nodeName, builder);
}
+ public void addSpanQueryBuilder(String nodeName, SpanQueryBuilder builder) {
+ queryFactory.addBuilder(nodeName, builder);
+ spanFactory.addBuilder(nodeName, builder);
+ }
+
static Document parseXML(InputStream pXmlFile) throws ParserException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
@@ -145,4 +156,9 @@ public class CoreParser implements QueryBuilder {
public Query getQuery(Element e) throws ParserException {
return queryFactory.getQuery(e);
}
+
+ @Override
+ public SpanQuery getSpanQuery(Element e) throws ParserException {
+ return spanFactory.getSpanQuery(e);
+ }
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/59390ef7/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCoreParser.java
----------------------------------------------------------------------
diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCoreParser.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCoreParser.java
index 5f33545..758fe8b 100644
--- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCoreParser.java
+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCoreParser.java
@@ -27,6 +27,7 @@ import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.util.LuceneTestCase;
import org.junit.AfterClass;
@@ -116,6 +117,9 @@ public class TestCoreParser extends LuceneTestCase {
public void testSpanTermXML() throws Exception {
Query q = parse("SpanQuery.xml");
dumpResults("Span Query", q, 5);
+ SpanQuery sq = parseAsSpan("SpanQuery.xml");
+ dumpResults("Span Query", sq, 5);
+ assertEquals(q, sq);
}
public void testConstantScoreQueryXML() throws Exception {
@@ -227,10 +231,21 @@ public class TestCoreParser extends LuceneTestCase {
}
protected Query parse(String xmlFileName) throws ParserException, IOException {
+ return implParse(xmlFileName, false);
+ }
+
+ protected SpanQuery parseAsSpan(String xmlFileName) throws ParserException, IOException {
+ return (SpanQuery)implParse(xmlFileName, true);
+ }
+
+ private Query implParse(String xmlFileName, boolean span) throws ParserException, IOException {
try (InputStream xmlStream = TestCoreParser.class.getResourceAsStream(xmlFileName)) {
assertNotNull("Test XML file " + xmlFileName + " cannot be found", xmlStream);
- Query result = coreParser().parse(xmlStream);
- return result;
+ if (span) {
+ return coreParser().parseAsSpanQuery(xmlStream);
+ } else {
+ return coreParser().parse(xmlStream);
+ }
}
}