mirror of https://github.com/apache/lucene.git
adding <SpanPositionRange> into XML Query Parser
This commit is contained in:
parent
a4ff429ab0
commit
70162d3fb1
|
@ -93,6 +93,8 @@ Improvements
|
||||||
* LUCENE-8906: Expose Lucene50PostingsFormat.IntBlockTermState as public so that other postings formats can re-use it.
|
* LUCENE-8906: Expose Lucene50PostingsFormat.IntBlockTermState as public so that other postings formats can re-use it.
|
||||||
(Bruno Roustant)
|
(Bruno Roustant)
|
||||||
|
|
||||||
|
* SOLR-13663: Introduce <SpanPositionRange> into XML Query Parser (Alessandro Benedetti via Mikhail Khludnev)
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
|
|
||||||
* LUCENE-8922: DisjunctionMaxQuery more efficiently leverages impacts to skip
|
* LUCENE-8922: DisjunctionMaxQuery more efficiently leverages impacts to skip
|
||||||
|
|
|
@ -112,6 +112,10 @@ public class CoreParser implements QueryBuilder, SpanQueryBuilder {
|
||||||
spanFactory.addBuilder("SpanFirst", sft);
|
spanFactory.addBuilder("SpanFirst", sft);
|
||||||
queryFactory.addBuilder("SpanFirst", sft);
|
queryFactory.addBuilder("SpanFirst", sft);
|
||||||
|
|
||||||
|
SpanPositionRangeBuilder sprt = new SpanPositionRangeBuilder(spanFactory);
|
||||||
|
spanFactory.addBuilder("SpanPositionRange", sprt);
|
||||||
|
queryFactory.addBuilder("SpanPositionRange", sprt);
|
||||||
|
|
||||||
SpanNotBuilder snot = new SpanNotBuilder(spanFactory);
|
SpanNotBuilder snot = new SpanNotBuilder(spanFactory);
|
||||||
spanFactory.addBuilder("SpanNot", snot);
|
spanFactory.addBuilder("SpanNot", snot);
|
||||||
queryFactory.addBuilder("SpanNot", snot);
|
queryFactory.addBuilder("SpanNot", snot);
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.lucene.queryparser.xml.builders;
|
||||||
|
|
||||||
|
import org.apache.lucene.queryparser.xml.DOMUtils;
|
||||||
|
import org.apache.lucene.queryparser.xml.ParserException;
|
||||||
|
import org.apache.lucene.search.spans.SpanBoostQuery;
|
||||||
|
import org.apache.lucene.search.spans.SpanPositionRangeQuery;
|
||||||
|
import org.apache.lucene.search.spans.SpanQuery;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder for {@link SpanPositionRangeQuery}
|
||||||
|
*/
|
||||||
|
public class SpanPositionRangeBuilder extends SpanBuilderBase {
|
||||||
|
|
||||||
|
private final SpanQueryBuilder factory;
|
||||||
|
|
||||||
|
public SpanPositionRangeBuilder(SpanQueryBuilder factory) {
|
||||||
|
this.factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SpanQuery getSpanQuery(Element e) throws ParserException {
|
||||||
|
int start = DOMUtils.getAttribute(e, "start", 1);
|
||||||
|
int end = DOMUtils.getAttribute(e, "end", 1);
|
||||||
|
Element child = DOMUtils.getFirstChildElement(e);
|
||||||
|
SpanQuery q = factory.getSpanQuery(child);
|
||||||
|
|
||||||
|
SpanPositionRangeQuery query = new SpanPositionRangeQuery(q, start, end);
|
||||||
|
|
||||||
|
float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
|
||||||
|
return new SpanBoostQuery(query, boost);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<SpanPositionRange start="9" end="11">
|
||||||
|
<SpanTerm fieldName="contents">sugar</SpanTerm>
|
||||||
|
</SpanPositionRange>
|
|
@ -135,6 +135,15 @@ public class TestCoreParser extends LuceneTestCase {
|
||||||
assertEquals(q, sq);
|
assertEquals(q, sq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSpanPositionRangeQueryXML() throws Exception {
|
||||||
|
Query q = parse("SpanPositionRangeQuery.xml");
|
||||||
|
long h = searcher().search(q, 10).totalHits.value;
|
||||||
|
assertEquals("SpanPositionRangeQuery should produce 2 result ", 2, h);
|
||||||
|
SpanQuery sq = parseAsSpan("SpanPositionRangeQuery.xml");
|
||||||
|
dumpResults("SpanPositionRangeQuery", sq, 5);
|
||||||
|
assertEquals(q, sq);
|
||||||
|
}
|
||||||
|
|
||||||
public void testSpanNearQueryWithoutSlopXML() throws Exception {
|
public void testSpanNearQueryWithoutSlopXML() throws Exception {
|
||||||
Exception expectedException = new NumberFormatException("For input string: \"\"");
|
Exception expectedException = new NumberFormatException("For input string: \"\"");
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1042,6 +1042,7 @@ The XmlQParser implementation uses the {solr-javadocs}/solr-core/org/apache/solr
|
||||||
|<MatchAllDocsQuery> |{lucene-javadocs}/queryparser/org/apache/lucene/queryparser/xml/builders/MatchAllDocsQueryBuilder.html[MatchAllDocsQueryBuilder]
|
|<MatchAllDocsQuery> |{lucene-javadocs}/queryparser/org/apache/lucene/queryparser/xml/builders/MatchAllDocsQueryBuilder.html[MatchAllDocsQueryBuilder]
|
||||||
|<RangeQuery> |{lucene-javadocs}/queryparser/org/apache/lucene/queryparser/xml/builders/RangeQueryBuilder.html[RangeQueryBuilder]
|
|<RangeQuery> |{lucene-javadocs}/queryparser/org/apache/lucene/queryparser/xml/builders/RangeQueryBuilder.html[RangeQueryBuilder]
|
||||||
|<SpanFirst> |{lucene-javadocs}/queryparser/org/apache/lucene/queryparser/xml/builders/SpanFirstBuilder.html[SpanFirstBuilder]
|
|<SpanFirst> |{lucene-javadocs}/queryparser/org/apache/lucene/queryparser/xml/builders/SpanFirstBuilder.html[SpanFirstBuilder]
|
||||||
|
|<SpanPositionRange> |{lucene-javadocs}/queryparser/org/apache/lucene/queryparser/xml/builders/SpanPositionRangeBuilder.html[SpanPositionRangeBuilder]
|
||||||
|<SpanNear> |{lucene-javadocs}/queryparser/org/apache/lucene/queryparser/xml/builders/SpanNearBuilder.html[SpanNearBuilder]
|
|<SpanNear> |{lucene-javadocs}/queryparser/org/apache/lucene/queryparser/xml/builders/SpanNearBuilder.html[SpanNearBuilder]
|
||||||
|<SpanNot> |{lucene-javadocs}/queryparser/org/apache/lucene/queryparser/xml/builders/SpanNotBuilder.html[SpanNotBuilder]
|
|<SpanNot> |{lucene-javadocs}/queryparser/org/apache/lucene/queryparser/xml/builders/SpanNotBuilder.html[SpanNotBuilder]
|
||||||
|<SpanOr> |{lucene-javadocs}/queryparser/org/apache/lucene/queryparser/xml/builders/SpanOrBuilder.html[SpanOrBuilder]
|
|<SpanOr> |{lucene-javadocs}/queryparser/org/apache/lucene/queryparser/xml/builders/SpanOrBuilder.html[SpanOrBuilder]
|
||||||
|
|
Loading…
Reference in New Issue