mirror of https://github.com/apache/lucene.git
LUCENE-6945: factor out TestCorePlus(Queries|Extensions)Parser from TestParser
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1721381 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fabc3b903d
commit
3064db4d73
|
@ -190,6 +190,9 @@ Other
|
||||||
* LUCENE-6925: add ForceMergePolicy class in test-framework
|
* LUCENE-6925: add ForceMergePolicy class in test-framework
|
||||||
(Christine Poerschke)
|
(Christine Poerschke)
|
||||||
|
|
||||||
|
* LUCENE-6945: factor out TestCorePlus(Queries|Extensions)Parser from
|
||||||
|
TestParser (Christine Poerschke)
|
||||||
|
|
||||||
======================= Lucene 5.4.0 =======================
|
======================= Lucene 5.4.0 =======================
|
||||||
|
|
||||||
New Features
|
New Features
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
package org.apache.lucene.queryparser.xml;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import org.apache.lucene.search.Query;
|
||||||
|
|
||||||
|
public class TestCorePlusExtensionsParser extends TestCorePlusQueriesParser {
|
||||||
|
|
||||||
|
private CoreParser corePlusExtensionsParser;
|
||||||
|
|
||||||
|
public void testFuzzyLikeThisQueryXML() throws Exception {
|
||||||
|
Query q = parse("FuzzyLikeThisQuery.xml");
|
||||||
|
//show rewritten fuzzyLikeThisQuery - see what is being matched on
|
||||||
|
if (VERBOSE) {
|
||||||
|
System.out.println(rewrite(q));
|
||||||
|
}
|
||||||
|
dumpResults("FuzzyLikeThis", q, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
//================= Helper methods ===================================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CoreParser coreParser() {
|
||||||
|
if (corePlusExtensionsParser == null) {
|
||||||
|
corePlusExtensionsParser = new CorePlusExtensionsParser(
|
||||||
|
super.defaultField(),
|
||||||
|
super.analyzer());
|
||||||
|
}
|
||||||
|
return corePlusExtensionsParser;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
package org.apache.lucene.queryparser.xml;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import org.apache.lucene.search.Query;
|
||||||
|
|
||||||
|
public class TestCorePlusQueriesParser extends TestParser {
|
||||||
|
|
||||||
|
private CoreParser corePlusQueriesParser;
|
||||||
|
|
||||||
|
public void testLikeThisQueryXML() throws Exception {
|
||||||
|
Query q = parse("LikeThisQuery.xml");
|
||||||
|
dumpResults("like this", q, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBoostingQueryXML() throws Exception {
|
||||||
|
Query q = parse("BoostingQuery.xml");
|
||||||
|
dumpResults("boosting ", q, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
//================= Helper methods ===================================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CoreParser coreParser() {
|
||||||
|
if (corePlusQueriesParser == null) {
|
||||||
|
corePlusQueriesParser = new CorePlusQueriesParser(
|
||||||
|
super.defaultField(),
|
||||||
|
super.analyzer());
|
||||||
|
}
|
||||||
|
return corePlusQueriesParser;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -47,6 +47,7 @@ import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
public class TestParser extends LuceneTestCase {
|
public class TestParser extends LuceneTestCase {
|
||||||
|
|
||||||
|
final private static String defaultField = "contents";
|
||||||
private static Analyzer analyzer;
|
private static Analyzer analyzer;
|
||||||
private static CoreParser coreParser;
|
private static CoreParser coreParser;
|
||||||
private static Directory dir;
|
private static Directory dir;
|
||||||
|
@ -58,7 +59,7 @@ public class TestParser extends LuceneTestCase {
|
||||||
// TODO: rewrite test (this needs to set QueryParser.enablePositionIncrements, too, for work with CURRENT):
|
// TODO: rewrite test (this needs to set QueryParser.enablePositionIncrements, too, for work with CURRENT):
|
||||||
analyzer = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, true, MockTokenFilter.ENGLISH_STOPSET);
|
analyzer = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, true, MockTokenFilter.ENGLISH_STOPSET);
|
||||||
//initialize the parser
|
//initialize the parser
|
||||||
coreParser = new CorePlusExtensionsParser("contents", analyzer);
|
coreParser = new CoreParser(defaultField, analyzer);
|
||||||
|
|
||||||
BufferedReader d = new BufferedReader(new InputStreamReader(
|
BufferedReader d = new BufferedReader(new InputStreamReader(
|
||||||
TestParser.class.getResourceAsStream("reuters21578.txt"), StandardCharsets.US_ASCII));
|
TestParser.class.getResourceAsStream("reuters21578.txt"), StandardCharsets.US_ASCII));
|
||||||
|
@ -136,25 +137,6 @@ public class TestParser extends LuceneTestCase {
|
||||||
assertEquals("UserInputQueryCustomField should produce 0 result ", 0, h);
|
assertEquals("UserInputQueryCustomField should produce 0 result ", 0, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLikeThisQueryXML() throws Exception {
|
|
||||||
Query q = parse("LikeThisQuery.xml");
|
|
||||||
dumpResults("like this", q, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBoostingQueryXML() throws Exception {
|
|
||||||
Query q = parse("BoostingQuery.xml");
|
|
||||||
dumpResults("boosting ", q, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testFuzzyLikeThisQueryXML() throws Exception {
|
|
||||||
Query q = parse("FuzzyLikeThisQuery.xml");
|
|
||||||
//show rewritten fuzzyLikeThisQuery - see what is being matched on
|
|
||||||
if (VERBOSE) {
|
|
||||||
System.out.println(q.rewrite(reader));
|
|
||||||
}
|
|
||||||
dumpResults("FuzzyLikeThis", q, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBoostingTermQueryXML() throws Exception {
|
public void testBoostingTermQueryXML() throws Exception {
|
||||||
Query q = parse("BoostingTermQuery.xml");
|
Query q = parse("BoostingTermQuery.xml");
|
||||||
dumpResults("BoostingTermQuery", q, 5);
|
dumpResults("BoostingTermQuery", q, 5);
|
||||||
|
@ -187,6 +169,10 @@ public class TestParser extends LuceneTestCase {
|
||||||
|
|
||||||
//================= Helper methods ===================================
|
//================= Helper methods ===================================
|
||||||
|
|
||||||
|
protected String defaultField() {
|
||||||
|
return defaultField;
|
||||||
|
}
|
||||||
|
|
||||||
protected Analyzer analyzer() {
|
protected Analyzer analyzer() {
|
||||||
return analyzer;
|
return analyzer;
|
||||||
}
|
}
|
||||||
|
@ -195,14 +181,18 @@ public class TestParser extends LuceneTestCase {
|
||||||
return coreParser;
|
return coreParser;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Query parse(String xmlFileName) throws ParserException, IOException {
|
protected Query parse(String xmlFileName) throws ParserException, IOException {
|
||||||
InputStream xmlStream = TestParser.class.getResourceAsStream(xmlFileName);
|
InputStream xmlStream = TestParser.class.getResourceAsStream(xmlFileName);
|
||||||
Query result = coreParser().parse(xmlStream);
|
Query result = coreParser().parse(xmlStream);
|
||||||
xmlStream.close();
|
xmlStream.close();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dumpResults(String qType, Query q, int numDocs) throws IOException {
|
protected Query rewrite(Query q) throws IOException {
|
||||||
|
return q.rewrite(reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void dumpResults(String qType, Query q, int numDocs) throws IOException {
|
||||||
if (VERBOSE) {
|
if (VERBOSE) {
|
||||||
System.out.println("TEST: query=" + q);
|
System.out.println("TEST: query=" + q);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue