mirror of https://github.com/apache/lucene.git
- Added tests for the new QueryParser changes.
Contributed by: Tatu Saloranta. git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@149956 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a3e2205e77
commit
470b5720e4
|
@ -3,8 +3,8 @@ package org.apache.lucene.queryParser;
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
* The Apache Software License, Version 1.1
|
* The Apache Software License, Version 1.1
|
||||||
*
|
*
|
||||||
* Copyright (c) 2001 The Apache Software Foundation. All rights
|
* Copyright (c) 2001, 2002, 2003 The Apache Software Foundation. All
|
||||||
* reserved.
|
* rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -67,6 +67,11 @@ import org.apache.lucene.analysis.*;
|
||||||
import org.apache.lucene.analysis.standard.*;
|
import org.apache.lucene.analysis.standard.*;
|
||||||
import org.apache.lucene.analysis.Token;
|
import org.apache.lucene.analysis.Token;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests QueryParser.
|
||||||
|
*
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
public class TestQueryParser extends TestCase {
|
public class TestQueryParser extends TestCase {
|
||||||
|
|
||||||
public TestQueryParser(String name) {
|
public TestQueryParser(String name) {
|
||||||
|
@ -119,12 +124,16 @@ public class TestQueryParser extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Query getQuery(String query, Analyzer a) throws Exception {
|
public QueryParser getParser(Analyzer a) throws Exception {
|
||||||
if (a == null)
|
if (a == null)
|
||||||
a = new SimpleAnalyzer();
|
a = new SimpleAnalyzer();
|
||||||
QueryParser qp = new QueryParser("field", a);
|
QueryParser qp = new QueryParser("field", a);
|
||||||
qp.setOperator(QueryParser.DEFAULT_OPERATOR_OR);
|
qp.setOperator(QueryParser.DEFAULT_OPERATOR_OR);
|
||||||
return qp.parse(query);
|
return qp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Query getQuery(String query, Analyzer a) throws Exception {
|
||||||
|
return getParser(a).parse(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void assertQueryEquals(String query, Analyzer a, String result)
|
public void assertQueryEquals(String query, Analyzer a, String result)
|
||||||
|
@ -137,6 +146,18 @@ public class TestQueryParser extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void assertWildcardQueryEquals(String query, boolean lowercase, String result)
|
||||||
|
throws Exception {
|
||||||
|
QueryParser qp = getParser(null);
|
||||||
|
qp.setLowercaseWildcardTerms(lowercase);
|
||||||
|
Query q = qp.parse(query);
|
||||||
|
String s = q.toString("field");
|
||||||
|
if (!s.equals(result)) {
|
||||||
|
fail("WildcardQuery /" + query + "/ yielded /" + s
|
||||||
|
+ "/, expecting /" + result + "/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Query getQueryDOA(String query, Analyzer a)
|
public Query getQueryDOA(String query, Analyzer a)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -247,6 +268,26 @@ public class TestQueryParser extends TestCase {
|
||||||
assertTrue(getQuery("term*^2", null) instanceof PrefixQuery);
|
assertTrue(getQuery("term*^2", null) instanceof PrefixQuery);
|
||||||
assertTrue(getQuery("term~", null) instanceof FuzzyQuery);
|
assertTrue(getQuery("term~", null) instanceof FuzzyQuery);
|
||||||
assertTrue(getQuery("term*germ", null) instanceof WildcardQuery);
|
assertTrue(getQuery("term*germ", null) instanceof WildcardQuery);
|
||||||
|
|
||||||
|
/* Tests to see that wild card terms are (or are not) properly
|
||||||
|
* lower-cased with propery parser configuration
|
||||||
|
*/
|
||||||
|
// First prefix queries:
|
||||||
|
assertWildcardQueryEquals("term*", true, "term*");
|
||||||
|
assertWildcardQueryEquals("Term*", true, "term*");
|
||||||
|
assertWildcardQueryEquals("TERM*", true, "term*");
|
||||||
|
assertWildcardQueryEquals("term*", false, "term*");
|
||||||
|
assertWildcardQueryEquals("Term*", false, "Term*");
|
||||||
|
assertWildcardQueryEquals("TERM*", false, "TERM*");
|
||||||
|
// Then 'full' wildcard queries:
|
||||||
|
assertWildcardQueryEquals("te?m", true, "te?m");
|
||||||
|
assertWildcardQueryEquals("Te?m", true, "te?m");
|
||||||
|
assertWildcardQueryEquals("TE?M", true, "te?m");
|
||||||
|
assertWildcardQueryEquals("Te?m*gerM", true, "te?m*germ");
|
||||||
|
assertWildcardQueryEquals("te?m", false, "te?m");
|
||||||
|
assertWildcardQueryEquals("Te?m", false, "Te?m");
|
||||||
|
assertWildcardQueryEquals("TE?M", false, "TE?M");
|
||||||
|
assertWildcardQueryEquals("Te?m*gerM", false, "Te?m*gerM");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testQPA() throws Exception {
|
public void testQPA() throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue