lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject cvs commit: jakarta-lucene/src/test/org/apache/lucene/queryParser TestQueryParser.java
Date Sun, 02 Mar 2003 02:47:01 GMT
otis        2003/03/01 18:47:01

  Modified:    src/test/org/apache/lucene/queryParser TestQueryParser.java
  Log:
  - Added tests for the new QueryParser changes.
  Contributed by: Tatu Saloranta.
  
  Revision  Changes    Path
  1.20      +47 -6     jakarta-lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java
  
  Index: TestQueryParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- TestQueryParser.java	15 Feb 2003 20:16:07 -0000	1.19
  +++ TestQueryParser.java	2 Mar 2003 02:47:01 -0000	1.20
  @@ -3,8 +3,8 @@
   /* ====================================================================
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  - * reserved.
  + * Copyright (c) 2001, 2002, 2003 The Apache Software Foundation.  All
  + * rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
  @@ -67,6 +67,11 @@
   import org.apache.lucene.analysis.standard.*;
   import org.apache.lucene.analysis.Token;
   
  +/**
  + * Tests QueryParser.
  + *
  + * @version $Id$
  + */
   public class TestQueryParser extends TestCase {
   
       public TestQueryParser(String name) {
  @@ -86,7 +91,7 @@
   	}
   
   	boolean inPhrase = false;
  -	int savedStart=0, savedEnd=0;
  +	int savedStart = 0, savedEnd = 0;
   
   	public Token next() throws IOException {
   	    if (inPhrase) {
  @@ -119,12 +124,16 @@
   	}
       }
   
  -    public Query getQuery(String query, Analyzer a) throws Exception {
  +    public QueryParser getParser(Analyzer a) throws Exception {
   	if (a == null)
   	    a = new SimpleAnalyzer();
   	QueryParser qp = new QueryParser("field", a);
   	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)
  @@ -137,6 +146,18 @@
   	}
       }
   
  +    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)
   	throws Exception
       {
  @@ -247,6 +268,26 @@
   	assertTrue(getQuery("term*^2", null) instanceof PrefixQuery);
   	assertTrue(getQuery("term~", null) instanceof FuzzyQuery);
   	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 {
  @@ -290,7 +331,7 @@
   
       public void testDateRange() throws Exception {
       String startDate = getLocalizedDate(2002, 1, 1);
  -    String endDate = getLocalizedDate(2002, 1, 4); 
  +    String endDate = getLocalizedDate(2002, 1, 4);
   	assertQueryEquals("[ " + startDate + " TO " + endDate + "]", null,
   	    "[" + getDate(startDate) + "-" + getDate(endDate) + "]");
   	assertQueryEquals("{  " + startDate + "    " + endDate + "   }", null,
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message