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 ma...@apache.org on 2009/10/24 23:23:37 UTC
svn commit: r829454 [4/8] - in /lucene/java/branches/flex_1458: ./ contrib/
contrib/analyzers/common/src/java/org/apache/lucene/analysis/ar/
contrib/analyzers/common/src/java/org/apache/lucene/analysis/br/
contrib/analyzers/common/src/java/org/apache/l...
Modified: lucene/java/branches/flex_1458/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.jj
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.jj?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.jj (original)
+++ lucene/java/branches/flex_1458/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.jj Sat Oct 24 21:23:15 2009
@@ -49,7 +49,6 @@
import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.WildcardQuery;
-import org.apache.lucene.util.Parameter;
import org.apache.lucene.util.AttributeSource;
/**
@@ -128,13 +127,7 @@
int fuzzyPrefixLength = FuzzyQuery.defaultPrefixLength;
Locale locale = Locale.getDefault();
- static final class Operator extends Parameter {
- private Operator(String name) {
- super(name);
- }
- static final Operator OR = new Operator("OR");
- static final Operator AND = new Operator("AND");
- }
+ static enum Operator { OR, AND }
/** Constructs a query parser.
* @param f the default field for query terms.
Modified: lucene/java/branches/flex_1458/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParserTokenManager.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParserTokenManager.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParserTokenManager.java (original)
+++ lucene/java/branches/flex_1458/contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParserTokenManager.java Sat Oct 24 21:23:15 2009
@@ -23,7 +23,6 @@
import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.WildcardQuery;
-import org.apache.lucene.util.Parameter;
import org.apache.lucene.util.AttributeSource;
/** Token Manager. */
Modified: lucene/java/branches/flex_1458/contrib/misc/src/test/org/apache/lucene/index/TestTermVectorAccessor.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/misc/src/test/org/apache/lucene/index/TestTermVectorAccessor.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/misc/src/test/org/apache/lucene/index/TestTermVectorAccessor.java (original)
+++ lucene/java/branches/flex_1458/contrib/misc/src/test/org/apache/lucene/index/TestTermVectorAccessor.java Sat Oct 24 21:23:15 2009
@@ -6,6 +6,7 @@
import org.apache.lucene.document.Field;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.util.Version;
import java.util.Collections;
/*
@@ -29,7 +30,7 @@
public void test() throws Exception {
Directory dir = new RAMDirectory();
- IndexWriter iw = new IndexWriter(dir, new StandardAnalyzer(Collections.EMPTY_SET), true, IndexWriter.MaxFieldLength.UNLIMITED);
+ IndexWriter iw = new IndexWriter(dir, new StandardAnalyzer(Version.LUCENE_CURRENT, Collections.emptySet()), true, IndexWriter.MaxFieldLength.UNLIMITED);
Document doc;
Modified: lucene/java/branches/flex_1458/contrib/misc/src/test/org/apache/lucene/queryParser/analyzing/TestAnalyzingQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/misc/src/test/org/apache/lucene/queryParser/analyzing/TestAnalyzingQueryParser.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/misc/src/test/org/apache/lucene/queryParser/analyzing/TestAnalyzingQueryParser.java (original)
+++ lucene/java/branches/flex_1458/contrib/misc/src/test/org/apache/lucene/queryParser/analyzing/TestAnalyzingQueryParser.java Sat Oct 24 21:23:15 2009
@@ -28,6 +28,7 @@
import org.apache.lucene.analysis.standard.StandardFilter;
import org.apache.lucene.analysis.standard.StandardTokenizer;
import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.util.Version;
/**
* @version $Revision$, $Date$
@@ -97,7 +98,7 @@
}
private String parseWithAnalyzingQueryParser(String s, Analyzer a) throws ParseException {
- AnalyzingQueryParser qp = new AnalyzingQueryParser("field", a);
+ AnalyzingQueryParser qp = new AnalyzingQueryParser(Version.LUCENE_CURRENT, "field", a);
org.apache.lucene.search.Query q = qp.parse(s);
return q.toString("field");
}
@@ -109,7 +110,7 @@
}
public TokenStream tokenStream(String fieldName, Reader reader) {
- TokenStream result = new StandardTokenizer(reader);
+ TokenStream result = new StandardTokenizer(Version.LUCENE_CURRENT, reader);
result = new StandardFilter(result);
result = new ASCIIFoldingFilter(result);
result = new LowerCaseFilter(result);
Modified: lucene/java/branches/flex_1458/contrib/misc/src/test/org/apache/lucene/queryParser/complexPhrase/TestComplexPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/misc/src/test/org/apache/lucene/queryParser/complexPhrase/TestComplexPhraseQuery.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/misc/src/test/org/apache/lucene/queryParser/complexPhrase/TestComplexPhraseQuery.java (original)
+++ lucene/java/branches/flex_1458/contrib/misc/src/test/org/apache/lucene/queryParser/complexPhrase/TestComplexPhraseQuery.java Sat Oct 24 21:23:15 2009
@@ -33,10 +33,11 @@
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.util.Version;
public class TestComplexPhraseQuery extends TestCase {
- Analyzer analyzer = new StandardAnalyzer();
+ Analyzer analyzer = new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT);
DocData docsContent[] = { new DocData("john smith", "1"),
new DocData("johathon smith", "2"),
@@ -71,7 +72,7 @@
}
private void checkBadQuery(String qString) {
- QueryParser qp = new ComplexPhraseQueryParser(defaultFieldName, analyzer);
+ QueryParser qp = new ComplexPhraseQueryParser(Version.LUCENE_CURRENT, defaultFieldName, analyzer);
Throwable expected = null;
try {
qp.parse(qString);
@@ -84,7 +85,7 @@
private void checkMatches(String qString, String expectedVals)
throws Exception {
- QueryParser qp = new ComplexPhraseQueryParser(defaultFieldName, analyzer);
+ QueryParser qp = new ComplexPhraseQueryParser(Version.LUCENE_CURRENT, defaultFieldName, analyzer);
qp.setFuzzyPrefixLength(1); // usually a good idea
Query q = qp.parse(qString);
Modified: lucene/java/branches/flex_1458/contrib/misc/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/misc/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/misc/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java (original)
+++ lucene/java/branches/flex_1458/contrib/misc/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java Sat Oct 24 21:23:15 2009
@@ -44,6 +44,7 @@
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashSet;
+import java.util.Collections;
public class TestPrecedenceQueryParser extends LocalizedTestCase {
@@ -233,7 +234,7 @@
assertQueryEquals("+title:(dog OR cat) -author:\"bob dole\"", null,
"+(title:dog title:cat) -author:\"bob dole\"");
- PrecedenceQueryParser qp = new PrecedenceQueryParser("field", new StandardAnalyzer());
+ PrecedenceQueryParser qp = new PrecedenceQueryParser("field", new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
// make sure OR is the default:
assertEquals(PrecedenceQueryParser.OR_OPERATOR, qp.getDefaultOperator());
qp.setDefaultOperator(PrecedenceQueryParser.AND_OPERATOR);
@@ -267,7 +268,7 @@
assertQueryEquals("term 1.0 1 2", null, "term");
assertQueryEquals("term term1 term2", null, "term term term");
- Analyzer a = new StandardAnalyzer();
+ Analyzer a = new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT);
assertQueryEquals("3", a, "3");
assertQueryEquals("term 1.0 1 2", a, "term 1.0 1 2");
assertQueryEquals("term term1 term2", a, "term term1 term2");
@@ -505,7 +506,7 @@
public void testBoost()
throws Exception {
- StandardAnalyzer oneStopAnalyzer = new StandardAnalyzer(new String[]{"on"});
+ StandardAnalyzer oneStopAnalyzer = new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT, Collections.singleton("on"));
PrecedenceQueryParser qp = new PrecedenceQueryParser("field", oneStopAnalyzer);
Query q = qp.parse("on^1.0");
assertNotNull(q);
@@ -518,7 +519,7 @@
q = qp.parse("\"on\"^1.0");
assertNotNull(q);
- q = getParser(new StandardAnalyzer()).parse("the^3");
+ q = getParser(new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT)).parse("the^3");
assertNotNull(q);
}
Modified: lucene/java/branches/flex_1458/contrib/queries/src/java/org/apache/lucene/search/similar/MoreLikeThis.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/queries/src/java/org/apache/lucene/search/similar/MoreLikeThis.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/queries/src/java/org/apache/lucene/search/similar/MoreLikeThis.java (original)
+++ lucene/java/branches/flex_1458/contrib/queries/src/java/org/apache/lucene/search/similar/MoreLikeThis.java Sat Oct 24 21:23:15 2009
@@ -49,6 +49,7 @@
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.PriorityQueue;
+import org.apache.lucene.util.Version;
/**
@@ -162,7 +163,7 @@
* Default analyzer to parse source doc with.
* @see #getAnalyzer
*/
- public static final Analyzer DEFAULT_ANALYZER = new StandardAnalyzer();
+ public static final Analyzer DEFAULT_ANALYZER = new StandardAnalyzer(Version.LUCENE_CURRENT);
/**
* Ignore terms with less than this frequency in the source doc.
Modified: lucene/java/branches/flex_1458/contrib/queries/src/test/org/apache/lucene/search/DuplicateFilterTest.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/queries/src/test/org/apache/lucene/search/DuplicateFilterTest.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/queries/src/test/org/apache/lucene/search/DuplicateFilterTest.java (original)
+++ lucene/java/branches/flex_1458/contrib/queries/src/test/org/apache/lucene/search/DuplicateFilterTest.java Sat Oct 24 21:23:15 2009
@@ -42,7 +42,7 @@
protected void setUp() throws Exception
{
directory = new RAMDirectory();
- IndexWriter writer = new IndexWriter(directory, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
+ IndexWriter writer = new IndexWriter(directory, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.UNLIMITED);
//Add series of docs with filterable fields : url, text and dates flags
addDoc(writer, "http://lucene.apache.org", "lucene 1.4.3 available", "20040101");
Modified: lucene/java/branches/flex_1458/contrib/queries/src/test/org/apache/lucene/search/similar/TestMoreLikeThis.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/queries/src/test/org/apache/lucene/search/similar/TestMoreLikeThis.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/queries/src/test/org/apache/lucene/search/similar/TestMoreLikeThis.java (original)
+++ lucene/java/branches/flex_1458/contrib/queries/src/test/org/apache/lucene/search/similar/TestMoreLikeThis.java Sat Oct 24 21:23:15 2009
@@ -43,7 +43,7 @@
protected void setUp() throws Exception {
directory = new RAMDirectory();
- IndexWriter writer = new IndexWriter(directory, new StandardAnalyzer(),
+ IndexWriter writer = new IndexWriter(directory, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT),
true, MaxFieldLength.UNLIMITED);
// Add series of docs with specific information for MoreLikeThis
Modified: lucene/java/branches/flex_1458/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ParametricQueryNode.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ParametricQueryNode.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ParametricQueryNode.java (original)
+++ lucene/java/branches/flex_1458/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ParametricQueryNode.java Sat Oct 24 21:23:15 2009
@@ -30,25 +30,12 @@
private CompareOperator operator;
public enum CompareOperator {
- LE, LT, GE, GT, EQ, NE;
-
- public String toString() {
- if (LE.equals(this)) {
- return "<=";
- } else if (LT.equals(this)) {
- return "<";
- } else if (GE.equals(this)) {
- return ">=";
- } else if (GT.equals(this)) {
- return ">";
- } else if (EQ.equals(this)) {
- return "=";
- } else if (NE.equals(this)) {
- return "!=";
- } else {
- throw new IllegalArgumentException("Unknown operator");
- }
- }
+ LE { public String toString() { return "<="; } },
+ LT { public String toString() { return "<"; } },
+ GE { public String toString() { return ">="; } },
+ GT { public String toString() { return ">"; } },
+ EQ { public String toString() { return "="; } },
+ NE { public String toString() { return "!="; } };
}
/**
Modified: lucene/java/branches/flex_1458/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ProximityQueryNode.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ProximityQueryNode.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ProximityQueryNode.java (original)
+++ lucene/java/branches/flex_1458/contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ProximityQueryNode.java Sat Oct 24 21:23:15 2009
@@ -36,33 +36,11 @@
private static final long serialVersionUID = 9018220596680832916L;
public enum Type {
- PARAGRAPH, SENTENCE, NUMBER;
+ PARAGRAPH { CharSequence toQueryString() { return "WITHIN PARAGRAPH"; } },
+ SENTENCE { CharSequence toQueryString() { return "WITHIN SENTENCE"; } },
+ NUMBER { CharSequence toQueryString() { return "WITHIN"; } };
- CharSequence toQueryString() {
- switch (this) {
- case PARAGRAPH:
- return "WITHIN PARAGRAPH";
- case SENTENCE:
- return "WITHIN SENTENCE";
- case NUMBER:
- return "WITHIN";
- default:
- return "WITHIN SENTENCE";
- }
- }
-
- public String toString() {
- switch (this) {
- case PARAGRAPH:
- return "PARAGRAPH";
- case SENTENCE:
- return "SENTENCE";
- case NUMBER:
- return "NUMBER";
- default:
- return "NUMBER";
- }
- }
+ abstract CharSequence toQueryString();
}
// utility class
Modified: lucene/java/branches/flex_1458/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/QueryParserWrapper.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/QueryParserWrapper.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/QueryParserWrapper.java (original)
+++ lucene/java/branches/flex_1458/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/QueryParserWrapper.java Sat Oct 24 21:23:15 2009
@@ -52,7 +52,6 @@
import org.apache.lucene.search.FuzzyQuery;
import org.apache.lucene.search.MultiTermQuery;
import org.apache.lucene.search.Query;
-import org.apache.lucene.util.Parameter;
/**
* This class performs the query parsing using the new query parser
@@ -71,17 +70,7 @@
* The default operator for parsing queries. Use
* {@link QueryParserWrapper#setDefaultOperator} to change it.
*/
- static public final class Operator extends Parameter {
- private static final long serialVersionUID = 3550299139196880290L;
-
- private Operator(String name) {
- super(name);
- }
-
- static public final Operator OR = new Operator("OR");
-
- static public final Operator AND = new Operator("AND");
- }
+ static public enum Operator { OR, AND }
// the nested class:
/** Alternative form of QueryParser.Operator.AND */
Modified: lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiAnalyzerQPHelper.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiAnalyzerQPHelper.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiAnalyzerQPHelper.java (original)
+++ lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiAnalyzerQPHelper.java Sat Oct 24 21:23:15 2009
@@ -34,6 +34,7 @@
import org.apache.lucene.queryParser.standard.StandardQueryParser;
import org.apache.lucene.queryParser.standard.config.DefaultOperatorAttribute.Operator;
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.Version;
/**
* This test case is a copy of the core Lucene query parser test, it was adapted
@@ -154,7 +155,7 @@
}
public TokenStream tokenStream(String fieldName, Reader reader) {
- TokenStream result = new StandardTokenizer(reader);
+ TokenStream result = new StandardTokenizer(Version.LUCENE_CURRENT, reader);
result = new TestFilter(result);
result = new LowerCaseFilter(result);
return result;
@@ -222,7 +223,7 @@
}
public TokenStream tokenStream(String fieldName, Reader reader) {
- TokenStream result = new StandardTokenizer(reader);
+ TokenStream result = new StandardTokenizer(Version.LUCENE_CURRENT, reader);
result = new TestPosIncrementFilter(result);
result = new LowerCaseFilter(result);
return result;
Modified: lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiAnalyzerWrapper.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiAnalyzerWrapper.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiAnalyzerWrapper.java (original)
+++ lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiAnalyzerWrapper.java Sat Oct 24 21:23:15 2009
@@ -33,6 +33,7 @@
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.standard.QueryParserWrapper;
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.Version;
/**
* This test case is a copy of the core Lucene query parser test, it was adapted
@@ -148,7 +149,7 @@
}
public TokenStream tokenStream(String fieldName, Reader reader) {
- TokenStream result = new StandardTokenizer(reader);
+ TokenStream result = new StandardTokenizer(Version.LUCENE_CURRENT, reader);
result = new TestFilter(result);
result = new LowerCaseFilter(result);
return result;
@@ -216,7 +217,7 @@
}
public TokenStream tokenStream(String fieldName, Reader reader) {
- TokenStream result = new StandardTokenizer(reader);
+ TokenStream result = new StandardTokenizer(Version.LUCENE_CURRENT, reader);
result = new TestPosIncrementFilter(result);
result = new LowerCaseFilter(result);
return result;
Modified: lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQPHelper.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQPHelper.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQPHelper.java (original)
+++ lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQPHelper.java Sat Oct 24 21:23:15 2009
@@ -83,7 +83,7 @@
String[] fields = { "b", "t" };
StandardQueryParser mfqp = new StandardQueryParser();
mfqp.setMultiFields(fields);
- mfqp.setAnalyzer(new StandardAnalyzer());
+ mfqp.setAnalyzer(new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
Query q = mfqp.parse("one", null);
assertEquals("b:one t:one", q.toString());
@@ -153,7 +153,7 @@
StandardQueryParser mfqp = new StandardQueryParser();
mfqp.setMultiFields(fields);
mfqp.setFieldsBoost(boosts);
- mfqp.setAnalyzer(new StandardAnalyzer());
+ mfqp.setAnalyzer(new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
// Check for simple
Query q = mfqp.parse("one", null);
@@ -181,24 +181,24 @@
public void testStaticMethod1() throws QueryNodeException {
String[] fields = { "b", "t" };
String[] queries = { "one", "two" };
- Query q = QueryParserUtil.parse(queries, fields, new StandardAnalyzer());
+ Query q = QueryParserUtil.parse(queries, fields, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
assertEquals("b:one t:two", q.toString());
String[] queries2 = { "+one", "+two" };
- q = QueryParserUtil.parse(queries2, fields, new StandardAnalyzer());
+ q = QueryParserUtil.parse(queries2, fields, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
assertEquals("(+b:one) (+t:two)", q.toString());
String[] queries3 = { "one", "+two" };
- q = QueryParserUtil.parse(queries3, fields, new StandardAnalyzer());
+ q = QueryParserUtil.parse(queries3, fields, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
assertEquals("b:one (+t:two)", q.toString());
String[] queries4 = { "one +more", "+two" };
- q = QueryParserUtil.parse(queries4, fields, new StandardAnalyzer());
+ q = QueryParserUtil.parse(queries4, fields, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
assertEquals("(b:one +b:more) (+t:two)", q.toString());
String[] queries5 = { "blah" };
try {
- q = QueryParserUtil.parse(queries5, fields, new StandardAnalyzer());
+ q = QueryParserUtil.parse(queries5, fields, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
fail();
} catch (IllegalArgumentException e) {
// expected exception, array length differs
@@ -222,15 +222,15 @@
BooleanClause.Occur[] flags = { BooleanClause.Occur.MUST,
BooleanClause.Occur.MUST_NOT };
Query q = QueryParserUtil.parse("one", fields, flags,
- new StandardAnalyzer());
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
assertEquals("+b:one -t:one", q.toString());
- q = QueryParserUtil.parse("one two", fields, flags, new StandardAnalyzer());
+ q = QueryParserUtil.parse("one two", fields, flags, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
assertEquals("+(b:one b:two) -(t:one t:two)", q.toString());
try {
BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST };
- q = QueryParserUtil.parse("blah", fields, flags2, new StandardAnalyzer());
+ q = QueryParserUtil.parse("blah", fields, flags2, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
fail();
} catch (IllegalArgumentException e) {
// expected exception, array length differs
@@ -243,19 +243,19 @@
BooleanClause.Occur.MUST_NOT };
StandardQueryParser parser = new StandardQueryParser();
parser.setMultiFields(fields);
- parser.setAnalyzer(new StandardAnalyzer());
+ parser.setAnalyzer(new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
Query q = QueryParserUtil.parse("one", fields, flags,
- new StandardAnalyzer());// , fields, flags, new
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));// , fields, flags, new
// StandardAnalyzer());
assertEquals("+b:one -t:one", q.toString());
- q = QueryParserUtil.parse("one two", fields, flags, new StandardAnalyzer());
+ q = QueryParserUtil.parse("one two", fields, flags, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
assertEquals("+(b:one b:two) -(t:one t:two)", q.toString());
try {
BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST };
- q = QueryParserUtil.parse("blah", fields, flags2, new StandardAnalyzer());
+ q = QueryParserUtil.parse("blah", fields, flags2, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
fail();
} catch (IllegalArgumentException e) {
// expected exception, array length differs
@@ -268,13 +268,13 @@
BooleanClause.Occur[] flags = { BooleanClause.Occur.MUST,
BooleanClause.Occur.MUST_NOT, BooleanClause.Occur.SHOULD };
Query q = QueryParserUtil.parse(queries, fields, flags,
- new StandardAnalyzer());
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
assertEquals("+f1:one -f2:two f3:three", q.toString());
try {
BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST };
q = QueryParserUtil
- .parse(queries, fields, flags2, new StandardAnalyzer());
+ .parse(queries, fields, flags2, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
fail();
} catch (IllegalArgumentException e) {
// expected exception, array length differs
@@ -287,13 +287,13 @@
BooleanClause.Occur[] flags = { BooleanClause.Occur.MUST,
BooleanClause.Occur.MUST_NOT };
Query q = QueryParserUtil.parse(queries, fields, flags,
- new StandardAnalyzer());
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
assertEquals("+b:one -t:two", q.toString());
try {
BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST };
q = QueryParserUtil
- .parse(queries, fields, flags2, new StandardAnalyzer());
+ .parse(queries, fields, flags2, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
fail();
} catch (IllegalArgumentException e) {
// expected exception, array length differs
@@ -319,7 +319,7 @@
}
public void testStopWordSearching() throws Exception {
- Analyzer analyzer = new StandardAnalyzer();
+ Analyzer analyzer = new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT);
Directory ramDir = new RAMDirectory();
IndexWriter iw = new IndexWriter(ramDir, analyzer, true,
IndexWriter.MaxFieldLength.LIMITED);
@@ -345,7 +345,7 @@
* Return empty tokens for field "f1".
*/
private static class AnalyzerReturningNull extends Analyzer {
- StandardAnalyzer stdAnalyzer = new StandardAnalyzer();
+ StandardAnalyzer stdAnalyzer = new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT);
public AnalyzerReturningNull() {
}
Modified: lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQueryParserWrapper.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQueryParserWrapper.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQueryParserWrapper.java (original)
+++ lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQueryParserWrapper.java Sat Oct 24 21:23:15 2009
@@ -78,7 +78,7 @@
public void testSimple() throws Exception {
String[] fields = { "b", "t" };
MultiFieldQueryParserWrapper mfqp = new MultiFieldQueryParserWrapper(
- fields, new StandardAnalyzer());
+ fields, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
Query q = mfqp.parse("one");
assertEquals("b:one t:one", q.toString());
@@ -146,7 +146,7 @@
boosts.put("t", Float.valueOf(10));
String[] fields = { "b", "t" };
MultiFieldQueryParserWrapper mfqp = new MultiFieldQueryParserWrapper(
- fields, new StandardAnalyzer(), boosts);
+ fields, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT), boosts);
// Check for simple
Query q = mfqp.parse("one");
@@ -175,28 +175,28 @@
String[] fields = { "b", "t" };
String[] queries = { "one", "two" };
Query q = MultiFieldQueryParserWrapper.parse(queries, fields,
- new StandardAnalyzer());
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
assertEquals("b:one t:two", q.toString());
String[] queries2 = { "+one", "+two" };
q = MultiFieldQueryParserWrapper.parse(queries2, fields,
- new StandardAnalyzer());
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
assertEquals("(+b:one) (+t:two)", q.toString());
String[] queries3 = { "one", "+two" };
q = MultiFieldQueryParserWrapper.parse(queries3, fields,
- new StandardAnalyzer());
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
assertEquals("b:one (+t:two)", q.toString());
String[] queries4 = { "one +more", "+two" };
q = MultiFieldQueryParserWrapper.parse(queries4, fields,
- new StandardAnalyzer());
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
assertEquals("(b:one +b:more) (+t:two)", q.toString());
String[] queries5 = { "blah" };
try {
q = MultiFieldQueryParserWrapper.parse(queries5, fields,
- new StandardAnalyzer());
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
fail();
} catch (IllegalArgumentException e) {
// expected exception, array length differs
@@ -220,17 +220,17 @@
BooleanClause.Occur[] flags = { BooleanClause.Occur.MUST,
BooleanClause.Occur.MUST_NOT };
Query q = MultiFieldQueryParserWrapper.parse("one", fields, flags,
- new StandardAnalyzer());
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
assertEquals("+b:one -t:one", q.toString());
q = MultiFieldQueryParserWrapper.parse("one two", fields, flags,
- new StandardAnalyzer());
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
assertEquals("+(b:one b:two) -(t:one t:two)", q.toString());
try {
BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST };
q = MultiFieldQueryParserWrapper.parse("blah", fields, flags2,
- new StandardAnalyzer());
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
fail();
} catch (IllegalArgumentException e) {
// expected exception, array length differs
@@ -244,20 +244,20 @@
BooleanClause.Occur[] flags = { BooleanClause.Occur.MUST,
BooleanClause.Occur.MUST_NOT };
MultiFieldQueryParserWrapper parser = new MultiFieldQueryParserWrapper(
- fields, new StandardAnalyzer());
+ fields, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
Query q = MultiFieldQueryParserWrapper.parse("one", fields, flags,
- new StandardAnalyzer());// , fields, flags, new StandardAnalyzer());
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));// , fields, flags, new StandardAnalyzer());
assertEquals("+b:one -t:one", q.toString());
q = MultiFieldQueryParserWrapper.parse("one two", fields, flags,
- new StandardAnalyzer());
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
assertEquals("+(b:one b:two) -(t:one t:two)", q.toString());
try {
BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST };
q = MultiFieldQueryParserWrapper.parse("blah", fields, flags2,
- new StandardAnalyzer());
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
fail();
} catch (IllegalArgumentException e) {
// expected exception, array length differs
@@ -270,13 +270,13 @@
BooleanClause.Occur[] flags = { BooleanClause.Occur.MUST,
BooleanClause.Occur.MUST_NOT, BooleanClause.Occur.SHOULD };
Query q = MultiFieldQueryParserWrapper.parse(queries, fields, flags,
- new StandardAnalyzer());
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
assertEquals("+f1:one -f2:two f3:three", q.toString());
try {
BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST };
q = MultiFieldQueryParserWrapper.parse(queries, fields, flags2,
- new StandardAnalyzer());
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
fail();
} catch (IllegalArgumentException e) {
// expected exception, array length differs
@@ -289,13 +289,13 @@
BooleanClause.Occur[] flags = { BooleanClause.Occur.MUST,
BooleanClause.Occur.MUST_NOT };
Query q = MultiFieldQueryParserWrapper.parse(queries, fields, flags,
- new StandardAnalyzer());
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
assertEquals("+b:one -t:two", q.toString());
try {
BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST };
q = MultiFieldQueryParserWrapper.parse(queries, fields, flags2,
- new StandardAnalyzer());
+ new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
fail();
} catch (IllegalArgumentException e) {
// expected exception, array length differs
@@ -319,7 +319,7 @@
}
public void testStopWordSearching() throws Exception {
- Analyzer analyzer = new StandardAnalyzer();
+ Analyzer analyzer = new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT);
Directory ramDir = new RAMDirectory();
IndexWriter iw = new IndexWriter(ramDir, analyzer, true,
IndexWriter.MaxFieldLength.LIMITED);
@@ -343,7 +343,7 @@
* Return empty tokens for field "f1".
*/
private static class AnalyzerReturningNull extends Analyzer {
- StandardAnalyzer stdAnalyzer = new StandardAnalyzer();
+ StandardAnalyzer stdAnalyzer = new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT);
public AnalyzerReturningNull() {
}
Modified: lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java (original)
+++ lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java Sat Oct 24 21:23:15 2009
@@ -30,6 +30,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Collections;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.KeywordAnalyzer;
@@ -77,6 +78,7 @@
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.util.LocalizedTestCase;
+import org.apache.lucene.util.Version;
/**
* This test case is a copy of the core Lucene query parser test, it was adapted
@@ -410,7 +412,7 @@
assertQueryEquals("term 1.0 1 2", null, "term");
assertQueryEquals("term term1 term2", null, "term term term");
- Analyzer a = new StandardAnalyzer();
+ Analyzer a = new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT);
assertQueryEquals("3", a, "3");
assertQueryEquals("term 1.0 1 2", a, "term 1.0 1 2");
assertQueryEquals("term term1 term2", a, "term term1 term2");
@@ -896,8 +898,7 @@
}
public void testBoost() throws Exception {
- StandardAnalyzer oneStopAnalyzer = new StandardAnalyzer(
- new String[] { "on" });
+ StandardAnalyzer oneStopAnalyzer = new StandardAnalyzer(Version.LUCENE_CURRENT, Collections.singleton("on"));
StandardQueryParser qp = new StandardQueryParser();
qp.setAnalyzer(oneStopAnalyzer);
@@ -913,7 +914,7 @@
assertNotNull(q);
StandardQueryParser qp2 = new StandardQueryParser();
- qp2.setAnalyzer(new StandardAnalyzer());
+ qp2.setAnalyzer(new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
q = qp2.parse("the^3", "field");
// "the" is a stop word so the result is an empty query:
@@ -1069,7 +1070,7 @@
public void testStopwords() throws Exception {
StandardQueryParser qp = new StandardQueryParser();
qp.setAnalyzer(
- new StopAnalyzer(new String[] { "the", "foo" }));
+ new StopAnalyzer(Version.LUCENE_CURRENT, StopFilter.makeStopSet("the", "foo" )));
Query result = qp.parse("a:the OR a:foo", "a");
assertNotNull("result is null and it shouldn't be", result);
@@ -1090,31 +1091,24 @@
}
public void testPositionIncrement() throws Exception {
- boolean dflt = StopFilter.getEnablePositionIncrementsDefault();
- StopFilter.setEnablePositionIncrementsDefault(true);
- try {
- StandardQueryParser qp = new StandardQueryParser();
- qp.setAnalyzer(
- new StopAnalyzer(new String[] { "the", "in", "are", "this" }));
-
- qp.setEnablePositionIncrements(true);
+ StandardQueryParser qp = new StandardQueryParser();
+ qp.setAnalyzer(
+ new StopAnalyzer(Version.LUCENE_CURRENT, StopFilter.makeStopSet("the", "in", "are", "this" )));
- String qtxt = "\"the words in poisitions pos02578 are stopped in this phrasequery\"";
- // 0 2 5 7 8
- int expectedPositions[] = { 1, 3, 4, 6, 9 };
- PhraseQuery pq = (PhraseQuery) qp.parse(qtxt, "a");
- // System.out.println("Query text: "+qtxt);
- // System.out.println("Result: "+pq);
- Term t[] = pq.getTerms();
- int pos[] = pq.getPositions();
- for (int i = 0; i < t.length; i++) {
- // System.out.println(i+". "+t[i]+" pos: "+pos[i]);
- assertEquals("term " + i + " = " + t[i] + " has wrong term-position!",
- expectedPositions[i], pos[i]);
- }
+ qp.setEnablePositionIncrements(true);
- } finally {
- StopFilter.setEnablePositionIncrementsDefault(dflt);
+ String qtxt = "\"the words in poisitions pos02578 are stopped in this phrasequery\"";
+ // 0 2 5 7 8
+ int expectedPositions[] = { 1, 3, 4, 6, 9 };
+ PhraseQuery pq = (PhraseQuery) qp.parse(qtxt, "a");
+ // System.out.println("Query text: "+qtxt);
+ // System.out.println("Result: "+pq);
+ Term t[] = pq.getTerms();
+ int pos[] = pq.getPositions();
+ for (int i = 0; i < t.length; i++) {
+ // System.out.println(i+". "+t[i]+" pos: "+pos[i]);
+ assertEquals("term " + i + " = " + t[i] + " has wrong term-position!",
+ expectedPositions[i], pos[i]);
}
}
Modified: lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java (original)
+++ lucene/java/branches/flex_1458/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java Sat Oct 24 21:23:15 2009
@@ -28,6 +28,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
+import java.util.Collections;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.KeywordAnalyzer;
@@ -72,6 +73,7 @@
import org.apache.lucene.search.WildcardQuery;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.LocalizedTestCase;
+import org.apache.lucene.util.Version;
/**
* This test case is a copy of the core Lucene query parser test, it was adapted
@@ -375,7 +377,7 @@
"+(title:dog title:cat) -author:\"bob dole\"");
QueryParserWrapper qp = new QueryParserWrapper("field",
- new StandardAnalyzer());
+ new StandardAnalyzer(Version.LUCENE_CURRENT));
// make sure OR is the default:
assertEquals(QueryParserWrapper.OR_OPERATOR, qp.getDefaultOperator());
qp.setDefaultOperator(QueryParserWrapper.AND_OPERATOR);
@@ -406,7 +408,7 @@
assertQueryEquals("term 1.0 1 2", null, "term");
assertQueryEquals("term term1 term2", null, "term term term");
- Analyzer a = new StandardAnalyzer();
+ Analyzer a = new StandardAnalyzer(Version.LUCENE_CURRENT);
assertQueryEquals("3", a, "3");
assertQueryEquals("term 1.0 1 2", a, "term 1.0 1 2");
assertQueryEquals("term term1 term2", a, "term term1 term2");
@@ -882,8 +884,7 @@
}
public void testBoost() throws Exception {
- StandardAnalyzer oneStopAnalyzer = new StandardAnalyzer(
- new String[] { "on" });
+ StandardAnalyzer oneStopAnalyzer = new StandardAnalyzer(Version.LUCENE_CURRENT, Collections.singleton("on"));
QueryParserWrapper qp = new QueryParserWrapper("field", oneStopAnalyzer);
Query q = qp.parse("on^1.0");
assertNotNull(q);
@@ -897,7 +898,7 @@
assertNotNull(q);
QueryParserWrapper qp2 = new QueryParserWrapper("field",
- new StandardAnalyzer());
+ new StandardAnalyzer(Version.LUCENE_CURRENT));
q = qp2.parse("the^3");
// "the" is a stop word so the result is an empty query:
assertNotNull(q);
@@ -1047,8 +1048,7 @@
}
public void testStopwords() throws Exception {
- QueryParserWrapper qp = new QueryParserWrapper("a", new StopAnalyzer(
- new String[] { "the", "foo" }));
+ QueryParserWrapper qp = new QueryParserWrapper("a", new StopAnalyzer(Version.LUCENE_CURRENT, StopFilter.makeStopSet("the", "foo")));
Query result = qp.parse("a:the OR a:foo");
assertNotNull("result is null and it shouldn't be", result);
assertTrue("result is not a BooleanQuery", result instanceof BooleanQuery);
@@ -1067,28 +1067,20 @@
}
public void testPositionIncrement() throws Exception {
- boolean dflt = StopFilter.getEnablePositionIncrementsDefault();
- StopFilter.setEnablePositionIncrementsDefault(true);
- try {
- QueryParserWrapper qp = new QueryParserWrapper("a", new StopAnalyzer(
- new String[] { "the", "in", "are", "this" }));
- qp.setEnablePositionIncrements(true);
- String qtxt = "\"the words in poisitions pos02578 are stopped in this phrasequery\"";
- // 0 2 5 7 8
- int expectedPositions[] = { 1, 3, 4, 6, 9 };
- PhraseQuery pq = (PhraseQuery) qp.parse(qtxt);
- // System.out.println("Query text: "+qtxt);
- // System.out.println("Result: "+pq);
- Term t[] = pq.getTerms();
- int pos[] = pq.getPositions();
- for (int i = 0; i < t.length; i++) {
- // System.out.println(i+". "+t[i]+" pos: "+pos[i]);
- assertEquals("term " + i + " = " + t[i] + " has wrong term-position!",
- expectedPositions[i], pos[i]);
- }
-
- } finally {
- StopFilter.setEnablePositionIncrementsDefault(dflt);
+ QueryParserWrapper qp = new QueryParserWrapper("a", new StopAnalyzer(Version.LUCENE_CURRENT, StopFilter.makeStopSet("the", "in", "are", "this")));
+ qp.setEnablePositionIncrements(true);
+ String qtxt = "\"the words in poisitions pos02578 are stopped in this phrasequery\"";
+ // 0 2 5 7 8
+ int expectedPositions[] = { 1, 3, 4, 6, 9 };
+ PhraseQuery pq = (PhraseQuery) qp.parse(qtxt);
+ // System.out.println("Query text: "+qtxt);
+ // System.out.println("Result: "+pq);
+ Term t[] = pq.getTerms();
+ int pos[] = pq.getPositions();
+ for (int i = 0; i < t.length; i++) {
+ // System.out.println(i+". "+t[i]+" pos: "+pos[i]);
+ assertEquals("term " + i + " = " + t[i] + " has wrong term-position!",
+ expectedPositions[i], pos[i]);
}
}
Modified: lucene/java/branches/flex_1458/contrib/regex/src/test/org/apache/lucene/search/regex/TestSpanRegexQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/regex/src/test/org/apache/lucene/search/regex/TestSpanRegexQuery.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/regex/src/test/org/apache/lucene/search/regex/TestSpanRegexQuery.java (original)
+++ lucene/java/branches/flex_1458/contrib/regex/src/test/org/apache/lucene/search/regex/TestSpanRegexQuery.java Sat Oct 24 21:23:15 2009
@@ -109,14 +109,14 @@
Field.Index.ANALYZED_NO_NORMS));
// creating first index writer
- IndexWriter writerA = new IndexWriter(indexStoreA, new StandardAnalyzer(),
+ IndexWriter writerA = new IndexWriter(indexStoreA, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT),
true, IndexWriter.MaxFieldLength.LIMITED);
writerA.addDocument(lDoc);
writerA.optimize();
writerA.close();
// creating second index writer
- IndexWriter writerB = new IndexWriter(indexStoreB, new StandardAnalyzer(),
+ IndexWriter writerB = new IndexWriter(indexStoreB, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT),
true, IndexWriter.MaxFieldLength.LIMITED);
writerB.addDocument(lDoc2);
writerB.optimize();
Modified: lucene/java/branches/flex_1458/contrib/snowball/src/java/org/apache/lucene/analysis/snowball/SnowballAnalyzer.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/snowball/src/java/org/apache/lucene/analysis/snowball/SnowballAnalyzer.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/snowball/src/java/org/apache/lucene/analysis/snowball/SnowballAnalyzer.java (original)
+++ lucene/java/branches/flex_1458/contrib/snowball/src/java/org/apache/lucene/analysis/snowball/SnowballAnalyzer.java Sat Oct 24 21:23:15 2009
@@ -19,6 +19,7 @@
import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.standard.*;
+import org.apache.lucene.util.Version;
import java.io.IOException;
import java.io.Reader;
@@ -30,20 +31,25 @@
* Available stemmers are listed in org.tartarus.snowball.ext. The name of a
* stemmer is the part of the class name before "Stemmer", e.g., the stemmer in
* {@link org.tartarus.snowball.ext.EnglishStemmer} is named "English".
+ *
+ * <p><b>NOTE</b>: This class uses the same {@link Version}
+ * dependent settings as {@link StandardAnalyzer}.</p>
*/
public class SnowballAnalyzer extends Analyzer {
private String name;
private Set stopSet;
+ private final Version matchVersion;
/** Builds the named analyzer with no stop words. */
- public SnowballAnalyzer(String name) {
+ public SnowballAnalyzer(Version matchVersion, String name) {
this.name = name;
setOverridesTokenStreamMethod(SnowballAnalyzer.class);
+ this.matchVersion = matchVersion;
}
/** Builds the named analyzer with the given stop words. */
- public SnowballAnalyzer(String name, String[] stopWords) {
- this(name);
+ public SnowballAnalyzer(Version matchVersion, String name, String[] stopWords) {
+ this(matchVersion, name);
stopSet = StopFilter.makeStopSet(stopWords);
}
@@ -51,11 +57,12 @@
StandardFilter}, a {@link LowerCaseFilter}, a {@link StopFilter},
and a {@link SnowballFilter} */
public TokenStream tokenStream(String fieldName, Reader reader) {
- TokenStream result = new StandardTokenizer(reader);
+ TokenStream result = new StandardTokenizer(matchVersion, reader);
result = new StandardFilter(result);
result = new LowerCaseFilter(result);
if (stopSet != null)
- result = new StopFilter(result, stopSet);
+ result = new StopFilter(StopFilter.getEnablePositionIncrementsVersionDefault(matchVersion),
+ result, stopSet);
result = new SnowballFilter(result, name);
return result;
}
@@ -80,11 +87,12 @@
SavedStreams streams = (SavedStreams) getPreviousTokenStream();
if (streams == null) {
streams = new SavedStreams();
- streams.source = new StandardTokenizer(reader);
+ streams.source = new StandardTokenizer(matchVersion, reader);
streams.result = new StandardFilter(streams.source);
streams.result = new LowerCaseFilter(streams.result);
if (stopSet != null)
- streams.result = new StopFilter(streams.result, stopSet);
+ streams.result = new StopFilter(StopFilter.getEnablePositionIncrementsVersionDefault(matchVersion),
+ streams.result, stopSet);
streams.result = new SnowballFilter(streams.result, name);
setPreviousTokenStream(streams);
} else {
Modified: lucene/java/branches/flex_1458/contrib/snowball/src/test/org/apache/lucene/analysis/snowball/TestSnowball.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/snowball/src/test/org/apache/lucene/analysis/snowball/TestSnowball.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/snowball/src/test/org/apache/lucene/analysis/snowball/TestSnowball.java (original)
+++ lucene/java/branches/flex_1458/contrib/snowball/src/test/org/apache/lucene/analysis/snowball/TestSnowball.java Sat Oct 24 21:23:15 2009
@@ -31,17 +31,18 @@
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
import org.apache.lucene.analysis.tokenattributes.TermAttribute;
import org.apache.lucene.analysis.tokenattributes.TypeAttribute;
+import org.apache.lucene.util.Version;
public class TestSnowball extends BaseTokenStreamTestCase {
public void testEnglish() throws Exception {
- Analyzer a = new SnowballAnalyzer("English");
+ Analyzer a = new SnowballAnalyzer(Version.LUCENE_CURRENT, "English");
assertAnalyzesTo(a, "he abhorred accents",
new String[]{"he", "abhor", "accent"});
}
public void testReusableTokenStream() throws Exception {
- Analyzer a = new SnowballAnalyzer("English");
+ Analyzer a = new SnowballAnalyzer(Version.LUCENE_CURRENT, "English");
assertAnalyzesToReuse(a, "he abhorred accents",
new String[]{"he", "abhor", "accent"});
assertAnalyzesToReuse(a, "she abhorred him",
@@ -53,7 +54,7 @@
*/
private class SnowballSubclassAnalyzer extends SnowballAnalyzer {
public SnowballSubclassAnalyzer(String name) {
- super(name);
+ super(Version.LUCENE_CURRENT, name);
}
public TokenStream tokenStream(String fieldName, Reader reader) {
Modified: lucene/java/branches/flex_1458/contrib/swing/src/java/org/apache/lucene/swing/models/ListSearcher.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/swing/src/java/org/apache/lucene/swing/models/ListSearcher.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/swing/src/java/org/apache/lucene/swing/models/ListSearcher.java (original)
+++ lucene/java/branches/flex_1458/contrib/swing/src/java/org/apache/lucene/swing/models/ListSearcher.java Sat Oct 24 21:23:15 2009
@@ -38,6 +38,7 @@
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.util.Version;
/**
* See table searcher explanation.
@@ -167,7 +168,7 @@
//build a query based on the fields, searchString and cached analyzer
//NOTE: This is an area for improvement since the MultiFieldQueryParser
// has some weirdness.
- MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, analyzer);
+ MultiFieldQueryParser parser = new MultiFieldQueryParser(Version.LUCENE_CURRENT, fields, analyzer);
Query query =parser.parse(searchString);
//reset this list model with the new results
resetSearchResults(is, query);
Modified: lucene/java/branches/flex_1458/contrib/swing/src/java/org/apache/lucene/swing/models/TableSearcher.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/swing/src/java/org/apache/lucene/swing/models/TableSearcher.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/swing/src/java/org/apache/lucene/swing/models/TableSearcher.java (original)
+++ lucene/java/branches/flex_1458/contrib/swing/src/java/org/apache/lucene/swing/models/TableSearcher.java Sat Oct 24 21:23:15 2009
@@ -35,7 +35,7 @@
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.swing.models.ListSearcher.CountingCollector;
-
+import org.apache.lucene.util.Version;
/**
* This is a TableModel that encapsulates Lucene
@@ -244,7 +244,7 @@
//build a query based on the fields, searchString and cached analyzer
//NOTE: This is an area for improvement since the MultiFieldQueryParser
// has some weirdness.
- MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, analyzer);
+ MultiFieldQueryParser parser = new MultiFieldQueryParser(Version.LUCENE_CURRENT, fields, analyzer);
Query query = parser.parse(searchString);
//reset this table model with the new results
resetSearchResults(is, query);
Modified: lucene/java/branches/flex_1458/contrib/wordnet/src/java/org/apache/lucene/wordnet/SynExpand.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/wordnet/src/java/org/apache/lucene/wordnet/SynExpand.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/wordnet/src/java/org/apache/lucene/wordnet/SynExpand.java (original)
+++ lucene/java/branches/flex_1458/contrib/wordnet/src/java/org/apache/lucene/wordnet/SynExpand.java Sat Oct 24 21:23:15 2009
@@ -42,6 +42,7 @@
import org.apache.lucene.search.Searcher;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.util.Version;
/**
@@ -77,7 +78,7 @@
String query = args[1];
String field = "contents";
- Query q = expand( query, searcher, new StandardAnalyzer(), field, 0.9f);
+ Query q = expand( query, searcher, new StandardAnalyzer(Version.LUCENE_CURRENT), field, 0.9f);
System.out.println( "Query: " + q.toString( field));
@@ -112,7 +113,7 @@
final Set already = new HashSet(); // avoid dups
List top = new LinkedList(); // needs to be separately listed..
final String field = ( f == null) ? "contents" : f;
- if ( a == null) a = new StandardAnalyzer();
+ if ( a == null) a = new StandardAnalyzer(Version.LUCENE_CURRENT);
// [1] Parse query into separate words so that when we expand we can avoid dups
TokenStream ts = a.tokenStream( field, new StringReader( query));
Modified: lucene/java/branches/flex_1458/contrib/wordnet/src/java/org/apache/lucene/wordnet/Syns2Index.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/wordnet/src/java/org/apache/lucene/wordnet/Syns2Index.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/wordnet/src/java/org/apache/lucene/wordnet/Syns2Index.java (original)
+++ lucene/java/branches/flex_1458/contrib/wordnet/src/java/org/apache/lucene/wordnet/Syns2Index.java Sat Oct 24 21:23:15 2009
@@ -36,6 +36,7 @@
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.util.Version;
/**
* Convert the prolog file wn_s.pl from the <a href="http://www.cogsci.princeton.edu/2.0/WNprolog-2.0.tar.gz">WordNet prolog download</a>
@@ -88,7 +89,7 @@
/**
*
*/
- private static final Analyzer ana = new StandardAnalyzer();
+ private static final Analyzer ana = new StandardAnalyzer(Version.LUCENE_CURRENT);
/**
* Takes arg of prolog file name and index directory.
@@ -164,8 +165,8 @@
String num = line.substring(0, comma);
int q1 = line.indexOf('\'');
line = line.substring(q1 + 1);
- int q2 = line.indexOf('\'');
- String word = line.substring(0, q2).toLowerCase();
+ int q2 = line.lastIndexOf('\'');
+ String word = line.substring(0, q2).toLowerCase().replace("''", "'");
// make sure is a normal word
if (! isDecent(word))
Modified: lucene/java/branches/flex_1458/contrib/xml-query-parser/src/demo/java/org/apache/lucene/xmlparser/webdemo/FormBasedXmlQueryDemo.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/xml-query-parser/src/demo/java/org/apache/lucene/xmlparser/webdemo/FormBasedXmlQueryDemo.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/xml-query-parser/src/demo/java/org/apache/lucene/xmlparser/webdemo/FormBasedXmlQueryDemo.java (original)
+++ lucene/java/branches/flex_1458/contrib/xml-query-parser/src/demo/java/org/apache/lucene/xmlparser/webdemo/FormBasedXmlQueryDemo.java Sat Oct 24 21:23:15 2009
@@ -51,7 +51,7 @@
private QueryTemplateManager queryTemplateManager;
private CorePlusExtensionsParser xmlParser;
private IndexSearcher searcher;
- private Analyzer analyzer=new StandardAnalyzer();
+ private Analyzer analyzer=new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT);
public void init(ServletConfig config) throws ServletException {
super.init(config);
Modified: lucene/java/branches/flex_1458/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BoostingTermBuilder.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BoostingTermBuilder.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BoostingTermBuilder.java (original)
+++ lucene/java/branches/flex_1458/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BoostingTermBuilder.java Sat Oct 24 21:23:15 2009
@@ -3,7 +3,8 @@
import org.apache.lucene.index.Term;
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.search.spans.SpanTermQuery;
-import org.apache.lucene.search.payloads.BoostingTermQuery;
+import org.apache.lucene.search.payloads.PayloadTermQuery;
+import org.apache.lucene.search.payloads.AveragePayloadFunction;
import org.apache.lucene.xmlparser.DOMUtils;
import org.apache.lucene.xmlparser.ParserException;
import org.w3c.dom.Element;
@@ -35,7 +36,7 @@
{
String fieldName=DOMUtils.getAttributeWithInheritanceOrFail(e,"fieldName");
String value=DOMUtils.getNonBlankTextOrFail(e);
- BoostingTermQuery btq = new BoostingTermQuery(new Term(fieldName,value));
+ PayloadTermQuery btq = new PayloadTermQuery(new Term(fieldName,value), new AveragePayloadFunction());
btq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
return btq;
Modified: lucene/java/branches/flex_1458/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/UserInputQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/UserInputQueryBuilder.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/UserInputQueryBuilder.java (original)
+++ lucene/java/branches/flex_1458/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/UserInputQueryBuilder.java Sat Oct 24 21:23:15 2009
@@ -8,6 +8,7 @@
import org.apache.lucene.xmlparser.ParserException;
import org.apache.lucene.xmlparser.QueryBuilder;
import org.w3c.dom.Element;
+import org.apache.lucene.util.Version;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -88,7 +89,7 @@
*/
protected QueryParser createQueryParser(String fieldName, Analyzer analyzer)
{
- return new QueryParser(fieldName,analyzer);
+ return new QueryParser(Version.LUCENE_CURRENT, fieldName,analyzer);
}
}
Modified: lucene/java/branches/flex_1458/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java (original)
+++ lucene/java/branches/flex_1458/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java Sat Oct 24 21:23:15 2009
@@ -39,7 +39,8 @@
CoreParser builder;
static Directory dir;
- Analyzer analyzer=new StandardAnalyzer();
+ // TODO: change to CURRENT and rewrite test (this needs to set QueryParser.enablePositionIncrements, too, for work with CURRENT):
+ Analyzer analyzer=new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_24);
IndexReader reader;
private IndexSearcher searcher;
Modified: lucene/java/branches/flex_1458/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestQueryTemplateManager.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestQueryTemplateManager.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestQueryTemplateManager.java (original)
+++ lucene/java/branches/flex_1458/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestQueryTemplateManager.java Sat Oct 24 21:23:15 2009
@@ -42,7 +42,7 @@
public class TestQueryTemplateManager extends TestCase {
CoreParser builder;
- Analyzer analyzer=new StandardAnalyzer();
+ Analyzer analyzer=new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT);
private IndexSearcher searcher;
//A collection of documents' field values for use in our tests
Modified: lucene/java/branches/flex_1458/src/demo/org/apache/lucene/demo/SearchFiles.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/demo/org/apache/lucene/demo/SearchFiles.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/demo/org/apache/lucene/demo/SearchFiles.java (original)
+++ lucene/java/branches/flex_1458/src/demo/org/apache/lucene/demo/SearchFiles.java Sat Oct 24 21:23:15 2009
@@ -127,7 +127,7 @@
} else {
in = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
}
- QueryParser parser = new QueryParser(field, analyzer);
+ QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, field, analyzer);
while (true) {
if (queries == null) // prompt the user
System.out.println("Enter query: ");
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/Analyzer.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/Analyzer.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/Analyzer.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/Analyzer.java Sat Oct 24 21:23:15 2009
@@ -84,25 +84,18 @@
}
}
- protected boolean overridesTokenStreamMethod;
+ /** @deprecated */
+ protected boolean overridesTokenStreamMethod = false;
/** @deprecated This is only present to preserve
* back-compat of classes that subclass a core analyzer
* and override tokenStream but not reusableTokenStream */
- protected void setOverridesTokenStreamMethod(Class baseClass) {
-
- final Class[] params = new Class[2];
- params[0] = String.class;
- params[1] = Reader.class;
-
+ protected void setOverridesTokenStreamMethod(Class<? extends Analyzer> baseClass) {
try {
- Method m = this.getClass().getMethod("tokenStream", params);
- if (m != null) {
- overridesTokenStreamMethod = m.getDeclaringClass() != baseClass;
- } else {
- overridesTokenStreamMethod = false;
- }
+ Method m = this.getClass().getMethod("tokenStream", String.class, Reader.class);
+ overridesTokenStreamMethod = m.getDeclaringClass() != baseClass;
} catch (NoSuchMethodException nsme) {
+ // cannot happen, as baseClass is subclass of Analyzer through generics
overridesTokenStreamMethod = false;
}
}
@@ -121,8 +114,7 @@
* @param fieldName Fieldable name being indexed.
* @return position increment gap, added to the next token emitted from {@link #tokenStream(String,Reader)}
*/
- public int getPositionIncrementGap(String fieldName)
- {
+ public int getPositionIncrementGap(String fieldName) {
return 0;
}
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/BaseCharFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/BaseCharFilter.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/BaseCharFilter.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/BaseCharFilter.java Sat Oct 24 21:23:15 2009
@@ -49,8 +49,8 @@
return currentOff;
}
for (int i = pcmList.size() - 1; i >= 0; i--) {
- if (currentOff >= ((OffCorrectMap) pcmList.get(i)).off) {
- return currentOff + ((OffCorrectMap) pcmList.get(i)).cumulativeDiff;
+ if (currentOff >= pcmList.get(i).off) {
+ return currentOff + pcmList.get(i).cumulativeDiff;
}
}
return currentOff;
@@ -58,7 +58,7 @@
protected int getLastCumulativeDiff() {
return pcmList == null || pcmList.isEmpty() ?
- 0 : ((OffCorrectMap)pcmList.get(pcmList.size() - 1)).cumulativeDiff;
+ 0 : pcmList.get(pcmList.size() - 1).cumulativeDiff;
}
protected void addOffCorrectMap(int off, int cumulativeDiff) {
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/StopAnalyzer.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/StopAnalyzer.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/StopAnalyzer.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/StopAnalyzer.java Sat Oct 24 21:23:15 2009
@@ -22,147 +22,81 @@
import java.io.Reader;
import java.util.Arrays;
import java.util.Set;
+import java.util.List;
-/** Filters {@link LetterTokenizer} with {@link LowerCaseFilter} and {@link StopFilter}. */
+import org.apache.lucene.util.Version;
+
+/** Filters {@link LetterTokenizer} with {@link LowerCaseFilter} and {@link StopFilter}.
+ *
+ * <a name="version"/>
+ * <p>You must specify the required {@link Version}
+ * compatibility when creating StopAnalyzer:
+ * <ul>
+ * <li> As of 2.9, position increments are preserved
+ * </ul>
+*/
public final class StopAnalyzer extends Analyzer {
- private final Set/*<String>*/ stopWords;
- // @deprecated
- private final boolean useDefaultStopPositionIncrement;
+ private final Set<?> stopWords;
private final boolean enablePositionIncrements;
-
- /** An array containing some common English words that are not usually useful
- for searching.
- @deprecated Use {@link #ENGLISH_STOP_WORDS_SET} instead */
- public static final String[] ENGLISH_STOP_WORDS = {
- "a", "an", "and", "are", "as", "at", "be", "but", "by",
- "for", "if", "in", "into", "is", "it",
- "no", "not", "of", "on", "or", "such",
- "that", "the", "their", "then", "there", "these",
- "they", "this", "to", "was", "will", "with"
- };
/** An unmodifiable set containing some common English words that are not usually useful
for searching.*/
- public static final Set/*<String>*/ ENGLISH_STOP_WORDS_SET;
+ public static final Set<?> ENGLISH_STOP_WORDS_SET;
static {
- final String[] stopWords = new String[]{
- "a", "an", "and", "are", "as", "at", "be", "but", "by",
- "for", "if", "in", "into", "is", "it",
- "no", "not", "of", "on", "or", "such",
- "that", "the", "their", "then", "there", "these",
- "they", "this", "to", "was", "will", "with"
- };
- final CharArraySet stopSet = new CharArraySet(stopWords.length, false);
- stopSet.addAll(Arrays.asList(stopWords));
- ENGLISH_STOP_WORDS_SET = CharArraySet.unmodifiableSet(stopSet);
+ final List<String> stopWords = Arrays.asList(
+ "a", "an", "and", "are", "as", "at", "be", "but", "by",
+ "for", "if", "in", "into", "is", "it",
+ "no", "not", "of", "on", "or", "such",
+ "that", "the", "their", "then", "there", "these",
+ "they", "this", "to", "was", "will", "with"
+ );
+ final CharArraySet stopSet = new CharArraySet(stopWords.size(), false);
+ stopSet.addAll(stopWords);
+ ENGLISH_STOP_WORDS_SET = CharArraySet.unmodifiableSet(stopSet);
}
/** Builds an analyzer which removes words in
- * ENGLISH_STOP_WORDS.
- * @deprecated Use {@link #StopAnalyzer(boolean)} instead */
- public StopAnalyzer() {
- stopWords = ENGLISH_STOP_WORDS_SET;
- useDefaultStopPositionIncrement = true;
- enablePositionIncrements = false;
- }
-
- /** Builds an analyzer which removes words in
- * ENGLISH_STOP_WORDS.
- * @param enablePositionIncrements See {@link
- * StopFilter#setEnablePositionIncrements} */
- public StopAnalyzer(boolean enablePositionIncrements) {
+ * {@link #ENGLISH_STOP_WORDS_SET}.
+ * @param matchVersion See <a href="#version">above</a>
+ */
+ public StopAnalyzer(Version matchVersion) {
stopWords = ENGLISH_STOP_WORDS_SET;
- this.enablePositionIncrements = enablePositionIncrements;
- useDefaultStopPositionIncrement = false;
- }
-
- /** Builds an analyzer with the stop words from the given set.
- * @deprecated Use {@link #StopAnalyzer(Set, boolean)} instead */
- public StopAnalyzer(Set stopWords) {
- this.stopWords = stopWords;
- useDefaultStopPositionIncrement = true;
- enablePositionIncrements = false;
+ enablePositionIncrements = StopFilter.getEnablePositionIncrementsVersionDefault(matchVersion);
}
/** Builds an analyzer with the stop words from the given set.
+ * @param matchVersion See <a href="#version">above</a>
* @param stopWords Set of stop words
* @param enablePositionIncrements See {@link
* StopFilter#setEnablePositionIncrements} */
- public StopAnalyzer(Set stopWords, boolean enablePositionIncrements) {
+ public StopAnalyzer(Version matchVersion, Set<?> stopWords) {
this.stopWords = stopWords;
- this.enablePositionIncrements = enablePositionIncrements;
- useDefaultStopPositionIncrement = false;
- }
-
- /** Builds an analyzer which removes words in the provided array.
- * @deprecated Use {@link #StopAnalyzer(Set, boolean)} instead */
- public StopAnalyzer(String[] stopWords) {
- this.stopWords = StopFilter.makeStopSet(stopWords);
- useDefaultStopPositionIncrement = true;
- enablePositionIncrements = false;
- }
-
- /** Builds an analyzer which removes words in the provided array.
- * @param stopWords Array of stop words
- * @param enablePositionIncrements See {@link
- * StopFilter#setEnablePositionIncrements}
- * @deprecated Use {@link #StopAnalyzer(Set, boolean)} instead*/
- public StopAnalyzer(String[] stopWords, boolean enablePositionIncrements) {
- this.stopWords = StopFilter.makeStopSet(stopWords);
- this.enablePositionIncrements = enablePositionIncrements;
- useDefaultStopPositionIncrement = false;
- }
-
- /** Builds an analyzer with the stop words from the given file.
- * @see WordlistLoader#getWordSet(File)
- * @deprecated Use {@link #StopAnalyzer(File, boolean)} instead */
- public StopAnalyzer(File stopwordsFile) throws IOException {
- stopWords = WordlistLoader.getWordSet(stopwordsFile);
- useDefaultStopPositionIncrement = true;
- enablePositionIncrements = false;
+ enablePositionIncrements = StopFilter.getEnablePositionIncrementsVersionDefault(matchVersion);
}
/** Builds an analyzer with the stop words from the given file.
* @see WordlistLoader#getWordSet(File)
- * @param stopwordsFile File to load stop words from
- * @param enablePositionIncrements See {@link
- * StopFilter#setEnablePositionIncrements} */
- public StopAnalyzer(File stopwordsFile, boolean enablePositionIncrements) throws IOException {
+ * @param matchVersion See <a href="#version">above</a>
+ * @param stopwordsFile File to load stop words from */
+ public StopAnalyzer(Version matchVersion, File stopwordsFile) throws IOException {
stopWords = WordlistLoader.getWordSet(stopwordsFile);
- this.enablePositionIncrements = enablePositionIncrements;
- useDefaultStopPositionIncrement = false;
+ this.enablePositionIncrements = StopFilter.getEnablePositionIncrementsVersionDefault(matchVersion);
}
/** Builds an analyzer with the stop words from the given reader.
* @see WordlistLoader#getWordSet(Reader)
- * @deprecated Use {@link #StopAnalyzer(Reader, boolean)} instead
- */
- public StopAnalyzer(Reader stopwords) throws IOException {
- stopWords = WordlistLoader.getWordSet(stopwords);
- useDefaultStopPositionIncrement = true;
- enablePositionIncrements = false;
- }
-
- /** Builds an analyzer with the stop words from the given reader.
- * @see WordlistLoader#getWordSet(Reader)
- * @param stopwords Reader to load stop words from
- * @param enablePositionIncrements See {@link
- * StopFilter#setEnablePositionIncrements} */
- public StopAnalyzer(Reader stopwords, boolean enablePositionIncrements) throws IOException {
+ * @param matchVersion See <a href="#version">above</a>
+ * @param stopwords Reader to load stop words from */
+ public StopAnalyzer(Version matchVersion, Reader stopwords) throws IOException {
stopWords = WordlistLoader.getWordSet(stopwords);
- this.enablePositionIncrements = enablePositionIncrements;
- useDefaultStopPositionIncrement = false;
+ this.enablePositionIncrements = StopFilter.getEnablePositionIncrementsVersionDefault(matchVersion);
}
/** Filters LowerCaseTokenizer with StopFilter. */
public TokenStream tokenStream(String fieldName, Reader reader) {
- if (useDefaultStopPositionIncrement) {
- return new StopFilter(new LowerCaseTokenizer(reader), stopWords);
- } else {
- return new StopFilter(enablePositionIncrements, new LowerCaseTokenizer(reader), stopWords);
- }
+ return new StopFilter(enablePositionIncrements, new LowerCaseTokenizer(reader), stopWords);
}
/** Filters LowerCaseTokenizer with StopFilter. */
@@ -175,11 +109,7 @@
if (streams == null) {
streams = new SavedStreams();
streams.source = new LowerCaseTokenizer(reader);
- if (useDefaultStopPositionIncrement) {
- streams.result = new StopFilter(streams.source, stopWords);
- } else {
- streams.result = new StopFilter(enablePositionIncrements, streams.source, stopWords);
- }
+ streams.result = new StopFilter(enablePositionIncrements, streams.source, stopWords);
setPreviousTokenStream(streams);
} else
streams.source.reset(reader);
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/StopFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/StopFilter.java?rev=829454&r1=829453&r2=829454&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/StopFilter.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/analysis/StopFilter.java Sat Oct 24 21:23:15 2009
@@ -25,6 +25,7 @@
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
import org.apache.lucene.analysis.tokenattributes.TermAttribute;
import org.apache.lucene.queryParser.QueryParser; // for javadoc
+import org.apache.lucene.util.Version;
/**
* Removes stop words from a token stream.
@@ -32,82 +33,11 @@
public final class StopFilter extends TokenFilter {
- // deprecated
- private static boolean ENABLE_POSITION_INCREMENTS_DEFAULT = false;
-
private final CharArraySet stopWords;
- private boolean enablePositionIncrements = ENABLE_POSITION_INCREMENTS_DEFAULT;
+ private boolean enablePositionIncrements = false;
private TermAttribute termAtt;
private PositionIncrementAttribute posIncrAtt;
-
- /**
- * Construct a token stream filtering the given input.
- * @deprecated Use {@link #StopFilter(boolean, TokenStream, String[])} instead
- */
- public StopFilter(TokenStream input, String [] stopWords)
- {
- this(ENABLE_POSITION_INCREMENTS_DEFAULT, input, stopWords, false);
- }
-
- /**
- * Construct a token stream filtering the given input.
- * @param enablePositionIncrements true if token positions should record the removed stop words
- * @param input input TokenStream
- * @param stopWords array of stop words
- * @deprecated Use {@link #StopFilter(boolean, TokenStream, Set)} instead.
- */
- public StopFilter(boolean enablePositionIncrements, TokenStream input, String [] stopWords)
- {
- this(enablePositionIncrements, input, stopWords, false);
- }
-
- /**
- * Constructs a filter which removes words from the input
- * TokenStream that are named in the array of words.
- * @deprecated Use {@link #StopFilter(boolean, TokenStream, String[], boolean)} instead
- */
- public StopFilter(TokenStream in, String[] stopWords, boolean ignoreCase) {
- this(ENABLE_POSITION_INCREMENTS_DEFAULT, in, stopWords, ignoreCase);
- }
-
- /**
- * Constructs a filter which removes words from the input
- * TokenStream that are named in the array of words.
- * @param enablePositionIncrements true if token positions should record the removed stop words
- * @param in input TokenStream
- * @param stopWords array of stop words
- * @param ignoreCase true if case is ignored
- * @deprecated Use {@link #StopFilter(boolean, TokenStream, Set, boolean)} instead.
- */
- public StopFilter(boolean enablePositionIncrements, TokenStream in, String[] stopWords, boolean ignoreCase) {
- super(in);
- this.stopWords = (CharArraySet)makeStopSet(stopWords, ignoreCase);
- this.enablePositionIncrements = enablePositionIncrements;
- init();
- }
-
-
- /**
- * Construct a token stream filtering the given input.
- * If <code>stopWords</code> is an instance of {@link CharArraySet} (true if
- * <code>makeStopSet()</code> was used to construct the set) it will be directly used
- * and <code>ignoreCase</code> will be ignored since <code>CharArraySet</code>
- * directly controls case sensitivity.
- * <p/>
- * If <code>stopWords</code> is not an instance of {@link CharArraySet},
- * a new CharArraySet will be constructed and <code>ignoreCase</code> will be
- * used to specify the case sensitivity of that set.
- *
- * @param input
- * @param stopWords The set of Stop Words.
- * @param ignoreCase -Ignore case when stopping.
- * @deprecated Use {@link #StopFilter(boolean, TokenStream, Set, boolean)} instead
- */
- public StopFilter(TokenStream input, Set stopWords, boolean ignoreCase)
- {
- this(ENABLE_POSITION_INCREMENTS_DEFAULT, input, stopWords, ignoreCase);
- }
/**
* Construct a token stream filtering the given input.
@@ -122,10 +52,11 @@
*
* @param enablePositionIncrements true if token positions should record the removed stop words
* @param input Input TokenStream
- * @param stopWords The set of Stop Words.
+ * @param stopWords A Set of Strings or char[] or any other toString()-able set representing the stopwords
+ * @param ignoreCase if true, all words are lower cased first
* @param ignoreCase -Ignore case when stopping.
*/
- public StopFilter(boolean enablePositionIncrements, TokenStream input, Set stopWords, boolean ignoreCase)
+ public StopFilter(boolean enablePositionIncrements, TokenStream input, Set<?> stopWords, boolean ignoreCase)
{
super(input);
if (stopWords instanceof CharArraySet) {
@@ -135,18 +66,8 @@
this.stopWords.addAll(stopWords);
}
this.enablePositionIncrements = enablePositionIncrements;
- init();
- }
-
- /**
- * Constructs a filter which removes words from the input
- * TokenStream that are named in the Set.
- *
- * @see #makeStopSet(java.lang.String[])
- * @deprecated Use {@link #StopFilter(boolean, TokenStream, Set)} instead
- */
- public StopFilter(TokenStream in, Set stopWords) {
- this(ENABLE_POSITION_INCREMENTS_DEFAULT, in, stopWords, false);
+ termAtt = addAttribute(TermAttribute.class);
+ posIncrAtt = addAttribute(PositionIncrementAttribute.class);
}
/**
@@ -155,17 +76,12 @@
*
* @param enablePositionIncrements true if token positions should record the removed stop words
* @param in Input stream
- * @param stopWords The set of Stop Words.
+ * @param stopWords A Set of Strings or char[] or any other toString()-able set representing the stopwords
* @see #makeStopSet(java.lang.String[])
*/
- public StopFilter(boolean enablePositionIncrements, TokenStream in, Set stopWords) {
+ public StopFilter(boolean enablePositionIncrements, TokenStream in, Set<?> stopWords) {
this(enablePositionIncrements, in, stopWords, false);
}
-
- public void init() {
- termAtt = addAttribute(TermAttribute.class);
- posIncrAtt = addAttribute(PositionIncrementAttribute.class);
- }
/**
* Builds a Set from an array of stop words,
@@ -175,7 +91,7 @@
*
* @see #makeStopSet(java.lang.String[], boolean) passing false to ignoreCase
*/
- public static final Set makeStopSet(String[] stopWords) {
+ public static final Set<Object> makeStopSet(String... stopWords) {
return makeStopSet(stopWords, false);
}
@@ -184,10 +100,11 @@
* appropriate for passing into the StopFilter constructor.
* This permits this stopWords construction to be cached once when
* an Analyzer is constructed.
- *
+ * @param stopWords A List of Strings or char[] or any other toString()-able list representing the stopwords
+ * @return A Set ({@link CharArraySet}) containing the words
* @see #makeStopSet(java.lang.String[], boolean) passing false to ignoreCase
*/
- public static final Set makeStopSet(List/*<String>*/ stopWords) {
+ public static final Set<Object> makeStopSet(List<?> stopWords) {
return makeStopSet(stopWords, false);
}
@@ -197,7 +114,7 @@
* @param ignoreCase If true, all words are lower cased first.
* @return a Set containing the words
*/
- public static final Set makeStopSet(String[] stopWords, boolean ignoreCase) {
+ public static final Set<Object> makeStopSet(String[] stopWords, boolean ignoreCase) {
CharArraySet stopSet = new CharArraySet(stopWords.length, ignoreCase);
stopSet.addAll(Arrays.asList(stopWords));
return stopSet;
@@ -205,11 +122,11 @@
/**
*
- * @param stopWords A List of Strings representing the stopwords
+ * @param stopWords A List of Strings or char[] or any other toString()-able list representing the stopwords
* @param ignoreCase if true, all words are lower cased first
- * @return A Set containing the words
+ * @return A Set ({@link CharArraySet}) containing the words
*/
- public static final Set makeStopSet(List/*<String>*/ stopWords, boolean ignoreCase){
+ public static final Set<Object> makeStopSet(List<?> stopWords, boolean ignoreCase){
CharArraySet stopSet = new CharArraySet(stopWords.size(), ignoreCase);
stopSet.addAll(stopWords);
return stopSet;
@@ -230,32 +147,23 @@
}
skippedPositions += posIncrAtt.getPositionIncrement();
}
- // reached EOS -- return null
+ // reached EOS -- return false
return false;
}
/**
- * @see #setEnablePositionIncrementsDefault(boolean).
- * @deprecated Please specify this when you create the StopFilter
- */
- public static boolean getEnablePositionIncrementsDefault() {
- return ENABLE_POSITION_INCREMENTS_DEFAULT;
- }
-
- /**
- * Set the default position increments behavior of every StopFilter created from now on.
- * <p>
- * Note: behavior of a single StopFilter instance can be modified
- * with {@link #setEnablePositionIncrements(boolean)}.
- * This static method allows control over behavior of classes using StopFilters internally,
- * for example {@link org.apache.lucene.analysis.standard.StandardAnalyzer StandardAnalyzer}.
- * <p>
- * Default : false.
- * @see #setEnablePositionIncrements(boolean).
- * @deprecated Please specify this when you create the StopFilter
- */
- public static void setEnablePositionIncrementsDefault(boolean defaultValue) {
- ENABLE_POSITION_INCREMENTS_DEFAULT = defaultValue;
+ * Returns version-dependent default for
+ * enablePositionIncrements. Analyzers that embed
+ * StopFilter use this method when creating the
+ * StopFilter. Prior to 2.9, this returns false. On 2.9
+ * or later, it returns true.
+ */
+ public static boolean getEnablePositionIncrementsVersionDefault(Version matchVersion) {
+ if (matchVersion.onOrAfter(Version.LUCENE_29)) {
+ return true;
+ } else {
+ return false;
+ }
}
/**