FAQ
dnaber 2004/12/14 15:02:54

Modified: src/java/org/apache/lucene/queryParser QueryParser.java
QueryParser.jj
src/test/org/apache/lucene/queryParser TestQueryParser.java
Log:
The terms of fuzzy and range queries are lowercased by default now. setLowercaseWildcardTerms deprecated, introducing setLowercaseExpandedTerms instead.

Revision Changes Path
1.23 +33 -10 jakarta-lucene/src/java/org/apache/lucene/queryParser/QueryParser.java

Index: QueryParser.java
===================================================================
RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/queryParser/QueryParser.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- QueryParser.java 23 Nov 2004 23:13:34 -0000 1.22
+++ QueryParser.java 14 Dec 2004 23:02:53 -0000 1.23
@@ -73,7 +73,7 @@
/** The actual operator that parser uses to combine query terms */
private Operator operator = OR_OPERATOR;

- boolean lowercaseWildcardTerms = true;
+ boolean lowercaseExpandedTerms = true;

Analyzer analyzer;
String field;
@@ -242,18 +242,34 @@
}

/**
- * Whether terms of wildcard and prefix queries are to be automatically
+ * Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically
* lower-cased or not. Default is <code>true</code>.
+ * @deprecated use {@link #setLowercaseExpandedTerms(boolean)} instead
*/
- public void setLowercaseWildcardTerms(boolean lowercaseWildcardTerms) {
- this.lowercaseWildcardTerms = lowercaseWildcardTerms;
+ public void setLowercaseWildcardTerms(boolean lowercaseExpandedTerms) {
+ this.lowercaseExpandedTerms = lowercaseExpandedTerms;
}

/**
- * @see #setLowercaseWildcardTerms(boolean)
+ * Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically
+ * lower-cased or not. Default is <code>true</code>.
+ */
+ public void setLowercaseExpandedTerms(boolean lowercaseExpandedTerms) {
+ this.lowercaseExpandedTerms = lowercaseExpandedTerms;
+ }
+
+ /**
+ * @deprecated use {@link #getLowercaseExpandedTerms()} instead
*/
public boolean getLowercaseWildcardTerms() {
- return lowercaseWildcardTerms;
+ return lowercaseExpandedTerms;
+ }
+
+ /**
+ * @see #setLowercaseExpandedTerms(boolean)
+ */
+ public boolean getLowercaseExpandedTerms() {
+ return lowercaseExpandedTerms;
}

/**
@@ -473,6 +489,10 @@
String part2,
boolean inclusive) throws ParseException
{
+ if (lowercaseExpandedTerms) {
+ part1 = part1.toLowerCase();
+ part2 = part2.toLowerCase();
+ }
try {
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
df.setLenient(true);
@@ -533,8 +553,8 @@
*/
protected Query getWildcardQuery(String field, String termStr) throws ParseException
{
- if (lowercaseWildcardTerms) {
- termStr = termStr.toLowerCase();
+ if (lowercaseExpandedTerms) {
+ termStr = termStr.toLowerCase();
}
Term t = new Term(field, termStr);
return new WildcardQuery(t);
@@ -565,8 +585,8 @@
*/
protected Query getPrefixQuery(String field, String termStr) throws ParseException
{
- if (lowercaseWildcardTerms) {
- termStr = termStr.toLowerCase();
+ if (lowercaseExpandedTerms) {
+ termStr = termStr.toLowerCase();
}
Term t = new Term(field, termStr);
return new PrefixQuery(t);
@@ -592,6 +612,9 @@
*/
protected Query getFuzzyQuery(String field, String termStr, float minSimilarity) throws ParseException
{
+ if (lowercaseExpandedTerms) {
+ termStr = termStr.toLowerCase();
+ }
Term t = new Term(field, termStr);
return new FuzzyQuery(t, minSimilarity, fuzzyPrefixLength);
}



1.57 +33 -10 jakarta-lucene/src/java/org/apache/lucene/queryParser/QueryParser.jj

Index: QueryParser.jj
===================================================================
RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/queryParser/QueryParser.jj,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
--- QueryParser.jj 23 Nov 2004 23:13:34 -0000 1.56
+++ QueryParser.jj 14 Dec 2004 23:02:53 -0000 1.57
@@ -96,7 +96,7 @@
/** The actual operator that parser uses to combine query terms */
private Operator operator = OR_OPERATOR;

- boolean lowercaseWildcardTerms = true;
+ boolean lowercaseExpandedTerms = true;

Analyzer analyzer;
String field;
@@ -265,18 +265,34 @@
}

/**
- * Whether terms of wildcard and prefix queries are to be automatically
+ * Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically
* lower-cased or not. Default is <code>true</code>.
+ * @deprecated use {@link #setLowercaseExpandedTerms(boolean)} instead
*/
- public void setLowercaseWildcardTerms(boolean lowercaseWildcardTerms) {
- this.lowercaseWildcardTerms = lowercaseWildcardTerms;
+ public void setLowercaseWildcardTerms(boolean lowercaseExpandedTerms) {
+ this.lowercaseExpandedTerms = lowercaseExpandedTerms;
}

/**
- * @see #setLowercaseWildcardTerms(boolean)
+ * Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically
+ * lower-cased or not. Default is <code>true</code>.
+ */
+ public void setLowercaseExpandedTerms(boolean lowercaseExpandedTerms) {
+ this.lowercaseExpandedTerms = lowercaseExpandedTerms;
+ }
+
+ /**
+ * @deprecated use {@link #getLowercaseExpandedTerms()} instead
*/
public boolean getLowercaseWildcardTerms() {
- return lowercaseWildcardTerms;
+ return lowercaseExpandedTerms;
+ }
+
+ /**
+ * @see #setLowercaseExpandedTerms(boolean)
+ */
+ public boolean getLowercaseExpandedTerms() {
+ return lowercaseExpandedTerms;
}

/**
@@ -496,6 +512,10 @@
String part2,
boolean inclusive) throws ParseException
{
+ if (lowercaseExpandedTerms) {
+ part1 = part1.toLowerCase();
+ part2 = part2.toLowerCase();
+ }
try {
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
df.setLenient(true);
@@ -556,8 +576,8 @@
*/
protected Query getWildcardQuery(String field, String termStr) throws ParseException
{
- if (lowercaseWildcardTerms) {
- termStr = termStr.toLowerCase();
+ if (lowercaseExpandedTerms) {
+ termStr = termStr.toLowerCase();
}
Term t = new Term(field, termStr);
return new WildcardQuery(t);
@@ -588,8 +608,8 @@
*/
protected Query getPrefixQuery(String field, String termStr) throws ParseException
{
- if (lowercaseWildcardTerms) {
- termStr = termStr.toLowerCase();
+ if (lowercaseExpandedTerms) {
+ termStr = termStr.toLowerCase();
}
Term t = new Term(field, termStr);
return new PrefixQuery(t);
@@ -615,6 +635,9 @@
*/
protected Query getFuzzyQuery(String field, String termStr, float minSimilarity) throws ParseException
{
+ if (lowercaseExpandedTerms) {
+ termStr = termStr.toLowerCase();
+ }
Term t = new Term(field, termStr);
return new FuzzyQuery(t, minSimilarity, fuzzyPrefixLength);
}



1.34 +27 -1 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.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- TestQueryParser.java 23 Nov 2004 23:14:31 -0000 1.33
+++ TestQueryParser.java 14 Dec 2004 23:02:53 -0000 1.34
@@ -129,7 +129,7 @@
public void assertWildcardQueryEquals(String query, boolean lowercase, String result)
throws Exception {
QueryParser qp = getParser(null);
- qp.setLowercaseWildcardTerms(lowercase);
+ qp.setLowercaseExpandedTerms(lowercase);
Query q = qp.parse(query);
String s = q.toString("field");
if (!s.equals(result)) {
@@ -138,6 +138,16 @@
}
}

+ public void assertWildcardQueryEquals(String query, String result) throws Exception {
+ QueryParser qp = getParser(null);
+ 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 {
if (a == null)
@@ -272,21 +282,37 @@
* lower-cased with propery parser configuration
*/
// First prefix queries:
+ // by default, convert to lowercase:
+ assertWildcardQueryEquals("Term*", true, "term*");
+ // explicitly set lowercase:
assertWildcardQueryEquals("term*", true, "term*");
assertWildcardQueryEquals("Term*", true, "term*");
assertWildcardQueryEquals("TERM*", true, "term*");
+ // explicitly disable lowercase conversion:
assertWildcardQueryEquals("term*", false, "term*");
assertWildcardQueryEquals("Term*", false, "Term*");
assertWildcardQueryEquals("TERM*", false, "TERM*");
// Then 'full' wildcard queries:
+ // by default, convert to lowercase:
+ assertWildcardQueryEquals("Te?m", "te?m");
+ // explicitly set lowercase:
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");
+ // explicitly disable lowercase conversion:
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");
+// Fuzzy queries:
+ assertWildcardQueryEquals("Term~", "term~0.5");
+ assertWildcardQueryEquals("Term~", true, "term~0.5");
+ assertWildcardQueryEquals("Term~", false, "Term~0.5");
+// Range queries:
+ assertWildcardQueryEquals("[A TO C]", "[a TO c]");
+ assertWildcardQueryEquals("[A TO C]", true, "[a TO c]");
+ assertWildcardQueryEquals("[A TO C]", false, "[A TO C]");
}

public void testQPA() throws Exception {




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

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdev @
categorieslucene
postedDec 14, '04 at 11:02p
activeDec 14, '04 at 11:02p
posts1
users1
websitelucene.apache.org

1 user in discussion

Dnaber: 1 post

People

Translate

site design / logo © 2021 Grokbase