LUCENE-7263: Make queryparser/xml/CoreParser's SpanQueryBuilderFactory accessible to deriving classes. (Daniel Collins via Christine Poerschke)

This commit is contained in:
Christine Poerschke 2016-05-03 10:05:02 +01:00
parent 0a0037517b
commit 72ce1faecd
2 changed files with 21 additions and 13 deletions

View File

@ -120,6 +120,9 @@ Other
* LUCENE-7210: Make TestCore*Parser's analyzer choice override-able * LUCENE-7210: Make TestCore*Parser's analyzer choice override-able
(Christine Poerschke, Daniel Collins) (Christine Poerschke, Daniel Collins)
* LUCENE-7263: Make queryparser/xml/CoreParser's SpanQueryBuilderFactory
accessible to deriving classes. (Daniel Collins via Christine Poerschke)
======================= Lucene 6.0.0 ======================= ======================= Lucene 6.0.0 =======================
System Requirements System Requirements

View File

@ -36,6 +36,7 @@ public class CoreParser implements QueryBuilder {
protected Analyzer analyzer; protected Analyzer analyzer;
protected QueryParser parser; protected QueryParser parser;
protected QueryBuilderFactory queryFactory; protected QueryBuilderFactory queryFactory;
final protected SpanQueryBuilderFactory spanFactory;
/** /**
@ -62,6 +63,8 @@ public class CoreParser implements QueryBuilder {
this.parser = parser; this.parser = parser;
queryFactory = new QueryBuilderFactory(); queryFactory = new QueryBuilderFactory();
spanFactory = new SpanQueryBuilderFactory();
queryFactory.addBuilder("TermQuery", new TermQueryBuilder()); queryFactory.addBuilder("TermQuery", new TermQueryBuilder());
queryFactory.addBuilder("TermsQuery", new TermsQueryBuilder(analyzer)); queryFactory.addBuilder("TermsQuery", new TermsQueryBuilder(analyzer));
queryFactory.addBuilder("MatchAllDocsQuery", new MatchAllDocsQueryBuilder()); queryFactory.addBuilder("MatchAllDocsQuery", new MatchAllDocsQueryBuilder());
@ -77,34 +80,32 @@ public class CoreParser implements QueryBuilder {
} }
queryFactory.addBuilder("ConstantScoreQuery", new ConstantScoreQueryBuilder(queryFactory)); queryFactory.addBuilder("ConstantScoreQuery", new ConstantScoreQueryBuilder(queryFactory));
SpanQueryBuilderFactory sqof = new SpanQueryBuilderFactory(); SpanNearBuilder snb = new SpanNearBuilder(spanFactory);
spanFactory.addBuilder("SpanNear", snb);
SpanNearBuilder snb = new SpanNearBuilder(sqof);
sqof.addBuilder("SpanNear", snb);
queryFactory.addBuilder("SpanNear", snb); queryFactory.addBuilder("SpanNear", snb);
BoostingTermBuilder btb = new BoostingTermBuilder(); BoostingTermBuilder btb = new BoostingTermBuilder();
sqof.addBuilder("BoostingTermQuery", btb); spanFactory.addBuilder("BoostingTermQuery", btb);
queryFactory.addBuilder("BoostingTermQuery", btb); queryFactory.addBuilder("BoostingTermQuery", btb);
SpanTermBuilder snt = new SpanTermBuilder(); SpanTermBuilder snt = new SpanTermBuilder();
sqof.addBuilder("SpanTerm", snt); spanFactory.addBuilder("SpanTerm", snt);
queryFactory.addBuilder("SpanTerm", snt); queryFactory.addBuilder("SpanTerm", snt);
SpanOrBuilder sot = new SpanOrBuilder(sqof); SpanOrBuilder sot = new SpanOrBuilder(spanFactory);
sqof.addBuilder("SpanOr", sot); spanFactory.addBuilder("SpanOr", sot);
queryFactory.addBuilder("SpanOr", sot); queryFactory.addBuilder("SpanOr", sot);
SpanOrTermsBuilder sots = new SpanOrTermsBuilder(analyzer); SpanOrTermsBuilder sots = new SpanOrTermsBuilder(analyzer);
sqof.addBuilder("SpanOrTerms", sots); spanFactory.addBuilder("SpanOrTerms", sots);
queryFactory.addBuilder("SpanOrTerms", sots); queryFactory.addBuilder("SpanOrTerms", sots);
SpanFirstBuilder sft = new SpanFirstBuilder(sqof); SpanFirstBuilder sft = new SpanFirstBuilder(spanFactory);
sqof.addBuilder("SpanFirst", sft); spanFactory.addBuilder("SpanFirst", sft);
queryFactory.addBuilder("SpanFirst", sft); queryFactory.addBuilder("SpanFirst", sft);
SpanNotBuilder snot = new SpanNotBuilder(sqof); SpanNotBuilder snot = new SpanNotBuilder(spanFactory);
sqof.addBuilder("SpanNot", snot); spanFactory.addBuilder("SpanNot", snot);
queryFactory.addBuilder("SpanNot", snot); queryFactory.addBuilder("SpanNot", snot);
} }
@ -116,6 +117,10 @@ public class CoreParser implements QueryBuilder {
queryFactory.addBuilder(nodeName, builder); queryFactory.addBuilder(nodeName, builder);
} }
public void addSpanBuilder(String nodeName, SpanQueryBuilder builder) {
spanFactory.addBuilder(nodeName, builder);
}
static Document parseXML(InputStream pXmlFile) throws ParserException { static Document parseXML(InputStream pXmlFile) throws ParserException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = null; DocumentBuilder db = null;