You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by mi...@apache.org on 2008/09/07 21:22:41 UTC
svn commit: r692921 [2/2] - in /lucene/java/trunk:
contrib/analyzers/src/java/org/apache/lucene/analysis/br/
contrib/analyzers/src/java/org/apache/lucene/analysis/cn/
contrib/analyzers/src/java/org/apache/lucene/analysis/cz/
contrib/analyzers/src/java/...
Modified: lucene/java/trunk/src/java/org/apache/lucene/queryParser/QueryParser.jj
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/queryParser/QueryParser.jj?rev=692921&r1=692920&r2=692921&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/queryParser/QueryParser.jj (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/queryParser/QueryParser.jj Sun Sep 7 12:22:40 2008
@@ -143,7 +143,7 @@
private Operator operator = OR_OPERATOR;
boolean lowercaseExpandedTerms = true;
- boolean useOldRangeQuery= false;
+ boolean useOldRangeQuery= false;
boolean allowLeadingWildcard = false;
boolean enablePositionIncrements = false;
@@ -188,7 +188,7 @@
public Query parse(String query) throws ParseException {
ReInit(new FastCharStream(new StringReader(query)));
try {
- // TopLevelQuery is a Query followed by the end-of-input (EOF)
+ // TopLevelQuery is a Query followed by the end-of-input (EOF)
Query res = TopLevelQuery(field);
return res!=null ? res : newBooleanQuery(false);
}
@@ -203,28 +203,28 @@
throw new ParseException("Cannot parse '" +query+ "': too many boolean clauses");
}
}
-
+
/**
* @return Returns the analyzer.
*/
public Analyzer getAnalyzer() {
return analyzer;
}
-
+
/**
* @return Returns the field.
*/
public String getField() {
return field;
}
-
+
/**
* Get the minimal similarity for fuzzy queries.
*/
public float getFuzzyMinSim() {
return fuzzyMinSim;
}
-
+
/**
* Set the minimum similarity for fuzzy queries.
* Default is 0.5f.
@@ -232,7 +232,7 @@
public void setFuzzyMinSim(float fuzzyMinSim) {
this.fuzzyMinSim = fuzzyMinSim;
}
-
+
/**
* Get the prefix length for fuzzy queries.
* @return Returns the fuzzyPrefixLength.
@@ -240,7 +240,7 @@
public int getFuzzyPrefixLength() {
return fuzzyPrefixLength;
}
-
+
/**
* Set the prefix length for fuzzy queries. Default is 0.
* @param fuzzyPrefixLength The fuzzyPrefixLength to set.
@@ -344,7 +344,7 @@
public boolean getLowercaseExpandedTerms() {
return lowercaseExpandedTerms;
}
-
+
/**
* By default QueryParser uses new ConstantScoreRangeQuery in preference to RangeQuery
* for range queries. This implementation is generally preferable because it
@@ -365,7 +365,6 @@
public boolean getUseOldRangeQuery() {
return useOldRangeQuery;
}
-
/**
* Set locale used by date range parsing.
@@ -391,7 +390,7 @@
public void setDateResolution(DateTools.Resolution dateResolution) {
this.dateResolution = dateResolution;
}
-
+
/**
* Sets the date resolution used by RangeQueries for a specific field.
*
@@ -402,12 +401,12 @@
if (fieldName == null) {
throw new IllegalArgumentException("Field cannot be null.");
}
-
+
if (fieldToDateResolution == null) {
// lazily initialize HashMap
fieldToDateResolution = new HashMap();
}
-
+
fieldToDateResolution.put(fieldName, dateResolution);
}
@@ -421,28 +420,35 @@
if (fieldName == null) {
throw new IllegalArgumentException("Field cannot be null.");
}
-
+
if (fieldToDateResolution == null) {
// no field specific date resolutions set; return default date resolution instead
return this.dateResolution;
}
-
+
DateTools.Resolution resolution = (DateTools.Resolution) fieldToDateResolution.get(fieldName);
if (resolution == null) {
// no date resolutions set for the given field; return default date resolution instead
resolution = this.dateResolution;
}
-
+
return resolution;
}
+ /**
+ * @deprecated use {@link #addClause(List, int, int, Query)} instead.
+ */
protected void addClause(Vector clauses, int conj, int mods, Query q) {
+ addClause((List) clauses, conj, mods, q);
+ }
+
+ protected void addClause(List clauses, int conj, int mods, Query q) {
boolean required, prohibited;
// If this term is introduced by AND, make the preceding term required,
// unless it's already prohibited
if (clauses.size() > 0 && conj == CONJ_AND) {
- BooleanClause c = (BooleanClause) clauses.elementAt(clauses.size()-1);
+ BooleanClause c = (BooleanClause) clauses.get(clauses.size()-1);
if (!c.isProhibited())
c.setOccur(BooleanClause.Occur.MUST);
}
@@ -452,7 +458,7 @@
// unless it's prohibited (that means we leave -a OR b but +a OR b-->a OR b)
// notice if the input is a OR b, first term is parsed as required; without
// this modification a OR b would parsed as +a OR b
- BooleanClause c = (BooleanClause) clauses.elementAt(clauses.size()-1);
+ BooleanClause c = (BooleanClause) clauses.get(clauses.size()-1);
if (!c.isProhibited())
c.setOccur(BooleanClause.Occur.SHOULD);
}
@@ -477,11 +483,11 @@
required = (!prohibited && conj != CONJ_OR);
}
if (required && !prohibited)
- clauses.addElement(newBooleanClause(q, BooleanClause.Occur.MUST));
+ clauses.add(newBooleanClause(q, BooleanClause.Occur.MUST));
else if (!required && !prohibited)
- clauses.addElement(newBooleanClause(q, BooleanClause.Occur.SHOULD));
+ clauses.add(newBooleanClause(q, BooleanClause.Occur.SHOULD));
else if (!required && prohibited)
- clauses.addElement(newBooleanClause(q, BooleanClause.Occur.MUST_NOT));
+ clauses.add(newBooleanClause(q, BooleanClause.Occur.MUST_NOT));
else
throw new RuntimeException("Clause cannot be both required and prohibited");
}
@@ -495,7 +501,7 @@
// PhraseQuery, or nothing based on the term count
TokenStream source = analyzer.tokenStream(field, new StringReader(queryText));
- Vector v = new Vector();
+ List list = new ArrayList();
final org.apache.lucene.analysis.Token reusableToken = new org.apache.lucene.analysis.Token();
org.apache.lucene.analysis.Token nextToken;
int positionCount = 0;
@@ -510,7 +516,7 @@
}
if (nextToken == null)
break;
- v.addElement(nextToken.clone());
+ list.add(nextToken.clone());
if (nextToken.getPositionIncrement() != 0)
positionCount += nextToken.getPositionIncrement();
else
@@ -523,18 +529,18 @@
// ignore
}
- if (v.size() == 0)
+ if (list.size() == 0)
return null;
- else if (v.size() == 1) {
- nextToken = (org.apache.lucene.analysis.Token) v.elementAt(0);
+ else if (list.size() == 1) {
+ nextToken = (org.apache.lucene.analysis.Token) list.get(0);
return newTermQuery(new Term(field, nextToken.term()));
} else {
if (severalTokensAtSamePosition) {
if (positionCount == 1) {
// no phrase query:
BooleanQuery q = newBooleanQuery(true);
- for (int i = 0; i < v.size(); i++) {
- nextToken = (org.apache.lucene.analysis.Token) v.elementAt(i);
+ for (int i = 0; i < list.size(); i++) {
+ nextToken = (org.apache.lucene.analysis.Token) list.get(i);
Query currentQuery = newTermQuery(
new Term(field, nextToken.term()));
q.add(currentQuery, BooleanClause.Occur.SHOULD);
@@ -544,11 +550,11 @@
else {
// phrase query:
MultiPhraseQuery mpq = newMultiPhraseQuery();
- mpq.setSlop(phraseSlop);
+ mpq.setSlop(phraseSlop);
List multiTerms = new ArrayList();
int position = -1;
- for (int i = 0; i < v.size(); i++) {
- nextToken = (org.apache.lucene.analysis.Token) v.elementAt(i);
+ for (int i = 0; i < list.size(); i++) {
+ nextToken = (org.apache.lucene.analysis.Token) list.get(i);
if (nextToken.getPositionIncrement() > 0 && multiTerms.size() > 0) {
if (enablePositionIncrements) {
mpq.add((Term[])multiTerms.toArray(new Term[0]),position);
@@ -572,8 +578,8 @@
PhraseQuery pq = newPhraseQuery();
pq.setSlop(phraseSlop);
int position = -1;
- for (int i = 0; i < v.size(); i++) {
- nextToken = (org.apache.lucene.analysis.Token) v.elementAt(i);
+ for (int i = 0; i < list.size(); i++) {
+ nextToken = (org.apache.lucene.analysis.Token) list.get(i);
if (enablePositionIncrements) {
position += nextToken.getPositionIncrement();
pq.add(new Term(field, nextToken.term()),position);
@@ -594,8 +600,8 @@
*
* @exception ParseException throw in overridden method to disallow
*/
- protected Query getFieldQuery(String field, String queryText, int slop)
- throws ParseException {
+ protected Query getFieldQuery(String field, String queryText, int slop)
+ throws ParseException {
Query query = getFieldQuery(field, queryText);
if (query instanceof PhraseQuery) {
@@ -764,13 +770,31 @@
* Can be overridden by extending classes, to modify query being
* returned.
*
- * @param clauses Vector that contains {@link BooleanClause} instances
+ * @param clauses List that contains {@link BooleanClause} instances
* to join.
*
* @return Resulting {@link Query} object.
* @exception ParseException throw in overridden method to disallow
+ * @deprecated use {@link #getBooleanQuery(List)} instead
*/
protected Query getBooleanQuery(Vector clauses) throws ParseException {
+ return getBooleanQuery((List) clauses, false);
+ }
+
+ /**
+ * Factory method for generating query, given a set of clauses.
+ * By default creates a boolean query composed of clauses passed in.
+ *
+ * Can be overridden by extending classes, to modify query being
+ * returned.
+ *
+ * @param clauses List that contains {@link BooleanClause} instances
+ * to join.
+ *
+ * @return Resulting {@link Query} object.
+ * @exception ParseException throw in overridden method to disallow
+ */
+ protected Query getBooleanQuery(List clauses) throws ParseException {
return getBooleanQuery(clauses, false);
}
@@ -781,22 +805,43 @@
* Can be overridden by extending classes, to modify query being
* returned.
*
- * @param clauses Vector that contains {@link BooleanClause} instances
+ * @param clauses List that contains {@link BooleanClause} instances
* to join.
* @param disableCoord true if coord scoring should be disabled.
*
* @return Resulting {@link Query} object.
* @exception ParseException throw in overridden method to disallow
+ * @deprecated use {@link #getBooleanQuery(List, boolean)} instead
*/
protected Query getBooleanQuery(Vector clauses, boolean disableCoord)
throws ParseException
{
+ return getBooleanQuery((List) clauses, disableCoord);
+ }
+
+ /**
+ * Factory method for generating query, given a set of clauses.
+ * By default creates a boolean query composed of clauses passed in.
+ *
+ * Can be overridden by extending classes, to modify query being
+ * returned.
+ *
+ * @param clauses List that contains {@link BooleanClause} instances
+ * to join.
+ * @param disableCoord true if coord scoring should be disabled.
+ *
+ * @return Resulting {@link Query} object.
+ * @exception ParseException throw in overridden method to disallow
+ */
+ protected Query getBooleanQuery(List clauses, boolean disableCoord)
+ throws ParseException
+ {
if (clauses.size()==0) {
return null; // all clause words were filtered away by the analyzer.
}
BooleanQuery query = newBooleanQuery(disableCoord);
for (int i = 0; i < clauses.size(); i++) {
- query.add((BooleanClause)clauses.elementAt(i));
+ query.add((BooleanClause)clauses.get(i));
}
return query;
}
@@ -870,7 +915,6 @@
return newPrefixQuery(t);
}
-
/**
* Factory method for generating a query (similar to
* {@link #getWildcardQuery}). Called when parser parses
@@ -896,29 +940,29 @@
* removed, or kept only once if there was a double escape.
*
* Supports escaped unicode characters, e. g. translates
- * <code>\u0041</code> to <code>A</code>.
+ * <code>\\u0041</code> to <code>A</code>.
*
*/
private String discardEscapeChar(String input) throws ParseException {
// Create char array to hold unescaped char sequence
char[] output = new char[input.length()];
-
+
// The length of the output can be less than the input
// due to discarded escape chars. This variable holds
// the actual length of the output
int length = 0;
-
+
// We remember whether the last processed character was
// an escape character
boolean lastCharWasEscapeChar = false;
-
+
// The multiplier the current unicode digit must be multiplied with.
// E. g. the first digit must be multiplied with 16^3, the second with 16^2...
int codePointMultiplier = 0;
-
+
// Used to calculate the codepoint of the escaped unicode character
int codePoint = 0;
-
+
for (int i = 0; i < input.length(); i++) {
char curChar = input.charAt(i);
if (codePointMultiplier > 0) {
@@ -932,9 +976,9 @@
if (curChar == 'u') {
// found an escaped unicode character
codePointMultiplier = 16 * 16 * 16;
- } else {
+ } else {
// this character was escaped
- output[length] = curChar;
+ output[length] = curChar;
length++;
}
lastCharWasEscapeChar = false;
@@ -947,18 +991,18 @@
}
}
}
-
+
if (codePointMultiplier > 0) {
throw new ParseException("Truncated unicode escape sequence.");
}
-
+
if (lastCharWasEscapeChar) {
throw new ParseException("Term can not end with escape character.");
}
-
+
return new String(output, 0, length);
}
-
+
/** Returns the numeric value of the hexadecimal character */
private static final int hexToInt(char c) throws ParseException {
if ('0' <= c && c <= '9') {
@@ -971,7 +1015,7 @@
throw new ParseException("None-hex character in unicode escape sequence: " + c);
}
}
-
+
/**
* Returns a String where those characters that QueryParser
* expects to be escaped are escaped by a preceding <code>\</code>.
@@ -1108,7 +1152,7 @@
Query Query(String field) :
{
- Vector clauses = new Vector();
+ List clauses = new ArrayList();
Query q, firstQuery=null;
int conj, mods;
}
Modified: lucene/java/trunk/src/java/org/apache/lucene/search/PhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/PhraseQuery.java?rev=692921&r1=692920&r2=692921&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/PhraseQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/PhraseQuery.java Sun Sep 7 12:22:40 2008
@@ -19,7 +19,6 @@
import java.io.IOException;
import java.util.Set;
-import java.util.Vector;
import java.util.ArrayList;
import org.apache.lucene.index.Term;
Modified: lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java?rev=692921&r1=692920&r2=692921&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java Sun Sep 7 12:22:40 2008
@@ -24,7 +24,8 @@
import java.io.RandomAccessFile;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import java.util.Hashtable;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.lucene.index.IndexFileNameFilter;
@@ -58,7 +59,7 @@
* instance from the cache. See LUCENE-776
* for some relevant discussion.
*/
- private static final Hashtable DIRECTORIES = new Hashtable();
+ private static final Map DIRECTORIES = new HashMap();
private static boolean disableLocks = false;
Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestDoc.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestDoc.java?rev=692921&r1=692920&r2=692921&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestDoc.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestDoc.java Sun Sep 7 12:22:40 2008
@@ -186,7 +186,7 @@
merger.closeReaders();
if (useCompoundFile) {
- Vector filesToDelete = merger.createCompoundFile(merged + ".cfs");
+ List filesToDelete = merger.createCompoundFile(merged + ".cfs");
for (Iterator iter = filesToDelete.iterator(); iter.hasNext();)
directory.deleteFile((String) iter.next());
}
Modified: lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java?rev=692921&r1=692920&r2=692921&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java Sun Sep 7 12:22:40 2008
@@ -19,8 +19,10 @@
import java.io.File;
import java.io.IOException;
-import java.util.Enumeration;
-import java.util.Hashtable;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
import org.apache.lucene.analysis.WhitespaceAnalyzer;
import org.apache.lucene.document.Document;
@@ -60,8 +62,8 @@
assertTrue("# calls to makeLock is 0 (after instantiating IndexWriter)",
lf.makeLockCount >= 1);
- for(Enumeration e = lf.locksCreated.keys(); e.hasMoreElements();) {
- String lockName = (String) e.nextElement();
+ for(Iterator e = lf.locksCreated.keySet().iterator(); e.hasNext();) {
+ String lockName = (String) e.next();
MockLockFactory.MockLock lock = (MockLockFactory.MockLock) lf.locksCreated.get(lockName);
assertTrue("# calls to Lock.obtain is 0 (after instantiating IndexWriter)",
lock.lockAttempts > 0);
@@ -522,7 +524,7 @@
public class MockLockFactory extends LockFactory {
public boolean lockPrefixSet;
- public Hashtable locksCreated = new Hashtable();
+ public Map locksCreated = Collections.synchronizedMap(new HashMap());
public int makeLockCount = 0;
public void setLockPrefix(String lockPrefix) {