You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ch...@apache.org on 2011/07/13 11:04:54 UTC
svn commit: r1145916 [1/3] - in /lucene/dev/trunk/lucene/contrib: ./
queries/src/java/org/apache/lucene/search/
queries/src/java/org/apache/lucene/search/regex/
queries/src/java/org/apache/lucene/search/similar/
queries/src/test/org/apache/lucene/searc...
Author: chrism
Date: Wed Jul 13 09:04:52 2011
New Revision: 1145916
URL: http://svn.apache.org/viewvc?rev=1145916&view=rev
Log:
LUCENE-3308: Code cleanup of queries module candidate contrib/queries
Modified:
lucene/dev/trunk/lucene/contrib/CHANGES.txt
lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java
lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/BoostingQuery.java
lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/ChainedFilter.java
lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/DuplicateFilter.java
lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/FilterClause.java
lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/TermsFilter.java
lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/JakartaRegexpCapabilities.java
lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/JavaUtilRegexCapabilities.java
lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/RegexQuery.java
lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/RegexQueryCapable.java
lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/RegexTermsEnum.java
lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/similar/MoreLikeThis.java
lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/similar/MoreLikeThisQuery.java
lucene/dev/trunk/lucene/contrib/queries/src/test/org/apache/lucene/search/BooleanFilterTest.java
lucene/dev/trunk/lucene/contrib/queries/src/test/org/apache/lucene/search/DuplicateFilterTest.java
lucene/dev/trunk/lucene/contrib/queries/src/test/org/apache/lucene/search/FuzzyLikeThisQueryTest.java
lucene/dev/trunk/lucene/contrib/queries/src/test/org/apache/lucene/search/TermsFilterTest.java
lucene/dev/trunk/lucene/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/DuplicateFilterBuilder.java
Modified: lucene/dev/trunk/lucene/contrib/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/CHANGES.txt?rev=1145916&r1=1145915&r2=1145916&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/contrib/CHANGES.txt Wed Jul 13 09:04:52 2011
@@ -47,6 +47,9 @@ API Changes
Instead, use SimilarityProvider to return different SweetSpotSimilaritys
for different fields, this way all parameters (such as TF factors) can be
customized on a per-field basis. (Robert Muir)
+
+ * LUCENE-3308: DuplicateFilter keepMode and processingMode have been converted to
+ enums DuplicateFilter.KeepMode and DuplicateFilter.ProcessingMode repsectively.
Bug Fixes
Modified: lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java?rev=1145916&r1=1145915&r2=1145916&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java (original)
+++ lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java Wed Jul 13 09:04:52 2011
@@ -19,6 +19,7 @@ package org.apache.lucene.search;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.List;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexReader.AtomicReaderContext;
@@ -36,25 +37,18 @@ import org.apache.lucene.util.OpenBitSet
* The resulting Filter is AND'd with the MUST Filters
*/
-public class BooleanFilter extends Filter
-{
- ArrayList<Filter> shouldFilters = null;
- ArrayList<Filter> notFilters = null;
- ArrayList<Filter> mustFilters = null;
-
- private DocIdSetIterator getDISI(ArrayList<Filter> filters, int index, AtomicReaderContext context)
- throws IOException
- {
- return filters.get(index).getDocIdSet(context).iterator();
- }
+public class BooleanFilter extends Filter {
+
+ List<Filter> shouldFilters = null;
+ List<Filter> notFilters = null;
+ List<Filter> mustFilters = null;
/**
* Returns the a DocIdSetIterator representing the Boolean composition
* of the filters that have been added.
*/
@Override
- public DocIdSet getDocIdSet(AtomicReaderContext context) throws IOException
- {
+ public DocIdSet getDocIdSet(AtomicReaderContext context) throws IOException {
OpenBitSetDISI res = null;
final IndexReader reader = context.reader;
if (shouldFilters != null) {
@@ -73,7 +67,7 @@ public class BooleanFilter extends Filte
}
}
- if (notFilters!=null) {
+ if (notFilters != null) {
for (int i = 0; i < notFilters.size(); i++) {
if (res == null) {
res = new OpenBitSetDISI(getDISI(notFilters, i, context), reader.maxDoc());
@@ -90,7 +84,7 @@ public class BooleanFilter extends Filte
}
}
- if (mustFilters!=null) {
+ if (mustFilters != null) {
for (int i = 0; i < mustFilters.size(); i++) {
if (res == null) {
res = new OpenBitSetDISI(getDISI(mustFilters, i, context), reader.maxDoc());
@@ -105,53 +99,47 @@ public class BooleanFilter extends Filte
}
}
}
-
- if (res !=null)
- return res;
- return DocIdSet.EMPTY_DOCIDSET;
+ return res != null ? res : DocIdSet.EMPTY_DOCIDSET;
}
/**
* Adds a new FilterClause to the Boolean Filter container
* @param filterClause A FilterClause object containing a Filter and an Occur parameter
*/
- public void add(FilterClause filterClause)
- {
+ public void add(FilterClause filterClause) {
if (filterClause.getOccur().equals(Occur.MUST)) {
- if (mustFilters==null) {
- mustFilters=new ArrayList<Filter>();
+ if (mustFilters == null) {
+ mustFilters = new ArrayList<Filter>();
}
mustFilters.add(filterClause.getFilter());
- }
- if (filterClause.getOccur().equals(Occur.SHOULD)) {
- if (shouldFilters==null) {
- shouldFilters=new ArrayList<Filter>();
+ } else if (filterClause.getOccur().equals(Occur.SHOULD)) {
+ if (shouldFilters == null) {
+ shouldFilters = new ArrayList<Filter>();
}
shouldFilters.add(filterClause.getFilter());
- }
- if (filterClause.getOccur().equals(Occur.MUST_NOT)) {
- if (notFilters==null) {
- notFilters=new ArrayList<Filter>();
+ } else if (filterClause.getOccur().equals(Occur.MUST_NOT)) {
+ if (notFilters == null) {
+ notFilters = new ArrayList<Filter>();
}
notFilters.add(filterClause.getFilter());
}
}
- private boolean equalFilters(ArrayList<Filter> filters1, ArrayList<Filter> filters2)
- {
- return (filters1 == filters2) ||
- ((filters1 != null) && filters1.equals(filters2));
+ private DocIdSetIterator getDISI(List<Filter> filters, int index, AtomicReaderContext context)
+ throws IOException {
+ return filters.get(index).getDocIdSet(context).iterator();
}
@Override
- public boolean equals(Object obj)
- {
- if (this == obj)
+ public boolean equals(Object obj) {
+ if (this == obj) {
return true;
+ }
- if ((obj == null) || (obj.getClass() != this.getClass()))
+ if ((obj == null) || (obj.getClass() != this.getClass())) {
return false;
+ }
BooleanFilter other = (BooleanFilter)obj;
return equalFilters(notFilters, other.notFilters)
@@ -159,10 +147,13 @@ public class BooleanFilter extends Filte
&& equalFilters(shouldFilters, other.shouldFilters);
}
+ private boolean equalFilters(List<Filter> filters1, List<Filter> filters2) {
+ return (filters1 == filters2) || ((filters1 != null) && filters1.equals(filters2));
+ }
+
@Override
- public int hashCode()
- {
- int hash=7;
+ public int hashCode() {
+ int hash = 7;
hash = 31 * hash + (null == mustFilters ? 0 : mustFilters.hashCode());
hash = 31 * hash + (null == notFilters ? 0 : notFilters.hashCode());
hash = 31 * hash + (null == shouldFilters ? 0 : shouldFilters.hashCode());
@@ -171,8 +162,7 @@ public class BooleanFilter extends Filte
/** Prints a user-readable version of this query. */
@Override
- public String toString()
- {
+ public String toString() {
StringBuilder buffer = new StringBuilder();
buffer.append("BooleanFilter(");
appendFilters(shouldFilters, "", buffer);
@@ -182,13 +172,12 @@ public class BooleanFilter extends Filte
return buffer.toString();
}
- private void appendFilters(ArrayList<Filter> filters, String occurString, StringBuilder buffer)
- {
+ private void appendFilters(List<Filter> filters, String occurString, StringBuilder buffer) {
if (filters != null) {
- for (int i = 0; i < filters.size(); i++) {
+ for (Filter filter : filters) {
buffer.append(' ');
buffer.append(occurString);
- buffer.append(filters.get(i).toString());
+ buffer.append(filter.toString());
}
}
}
Modified: lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/BoostingQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/BoostingQuery.java?rev=1145916&r1=1145915&r2=1145916&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/BoostingQuery.java (original)
+++ lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/BoostingQuery.java Wed Jul 13 09:04:52 2011
@@ -46,9 +46,8 @@ public class BoostingQuery extends Query
public BoostingQuery(Query match, Query context, float boost) {
this.match = match;
- this.context = (Query)context.clone(); // clone before boost
+ this.context = (Query) context.clone(); // clone before boost
this.boost = boost;
-
this.context.setBoost(0.0f); // ignore context-only matches
}
@@ -96,25 +95,36 @@ public class BoostingQuery extends Query
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
+
BoostingQuery other = (BoostingQuery) obj;
- if (Float.floatToIntBits(boost) != Float.floatToIntBits(other.boost))
+ if (Float.floatToIntBits(boost) != Float.floatToIntBits(other.boost)) {
return false;
+ }
+
if (context == null) {
- if (other.context != null)
+ if (other.context != null) {
return false;
- } else if (!context.equals(other.context))
+ }
+ } else if (!context.equals(other.context)) {
return false;
+ }
+
if (match == null) {
- if (other.match != null)
+ if (other.match != null) {
return false;
- } else if (!match.equals(other.match))
+ }
+ } else if (!match.equals(other.match)) {
return false;
+ }
return true;
}
Modified: lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/ChainedFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/ChainedFilter.java?rev=1145916&r1=1145915&r2=1145916&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/ChainedFilter.java (original)
+++ lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/ChainedFilter.java Wed Jul 13 09:04:52 2011
@@ -17,16 +17,13 @@ package org.apache.lucene.search;
* limitations under the License.
*/
-import java.io.IOException;
-
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexReader.AtomicReaderContext;
-import org.apache.lucene.search.DocIdSet;
-import org.apache.lucene.search.DocIdSetIterator;
-import org.apache.lucene.search.Filter;
import org.apache.lucene.util.OpenBitSet;
import org.apache.lucene.util.OpenBitSetDISI;
+import java.io.IOException;
+
/**
* <p>
* Allows multiple {@link Filter}s to be chained.
@@ -41,218 +38,209 @@ import org.apache.lucene.util.OpenBitSet
* more efficient to place the most restrictive filters
* /least computationally-intensive filters first.
* </p>
- *
*/
-public class ChainedFilter extends Filter
-{
- public static final int OR = 0;
- public static final int AND = 1;
- public static final int ANDNOT = 2;
- public static final int XOR = 3;
- /**
- * Logical operation when none is declared. Defaults to
- * OR.
- */
- public static int DEFAULT = OR;
-
- /** The filter chain */
- private Filter[] chain = null;
-
- private int[] logicArray;
-
- private int logic = -1;
-
- /**
- * Ctor.
- * @param chain The chain of filters
- */
- public ChainedFilter(Filter[] chain)
- {
- this.chain = chain;
- }
-
- /**
- * Ctor.
- * @param chain The chain of filters
- * @param logicArray Logical operations to apply between filters
- */
- public ChainedFilter(Filter[] chain, int[] logicArray)
- {
- this.chain = chain;
- this.logicArray = logicArray;
- }
-
- /**
- * Ctor.
- * @param chain The chain of filters
- * @param logic Logical operation to apply to ALL filters
- */
- public ChainedFilter(Filter[] chain, int logic)
- {
- this.chain = chain;
- this.logic = logic;
- }
-
- /**
- * {@link Filter#getDocIdSet}.
- */
- @Override
- public DocIdSet getDocIdSet(AtomicReaderContext context) throws IOException
- {
- int[] index = new int[1]; // use array as reference to modifiable int;
- index[0] = 0; // an object attribute would not be thread safe.
- if (logic != -1)
- return getDocIdSet(context, logic, index);
- else if (logicArray != null)
- return getDocIdSet(context, logicArray, index);
- else
- return getDocIdSet(context, DEFAULT, index);
- }
-
- private DocIdSetIterator getDISI(Filter filter, AtomicReaderContext context)
- throws IOException {
- DocIdSet docIdSet = filter.getDocIdSet(context);
- if (docIdSet == null) {
- return DocIdSet.EMPTY_DOCIDSET.iterator();
- } else {
- DocIdSetIterator iter = docIdSet.iterator();
- if (iter == null) {
- return DocIdSet.EMPTY_DOCIDSET.iterator();
- } else {
- return iter;
- }
- }
- }
-
- private OpenBitSetDISI initialResult(AtomicReaderContext context, int logic, int[] index)
- throws IOException
- {
- IndexReader reader = context.reader;
- OpenBitSetDISI result;
- /**
- * First AND operation takes place against a completely false
- * bitset and will always return zero results.
- */
- if (logic == AND)
- {
- result = new OpenBitSetDISI(getDISI(chain[index[0]], context), reader.maxDoc());
- ++index[0];
- }
- else if (logic == ANDNOT)
- {
- result = new OpenBitSetDISI(getDISI(chain[index[0]], context), reader.maxDoc());
- result.flip(0,reader.maxDoc()); // NOTE: may set bits for deleted docs.
- ++index[0];
- }
- else
- {
- result = new OpenBitSetDISI(reader.maxDoc());
- }
- return result;
- }
-
- /**
- * Delegates to each filter in the chain.
- * @param reader IndexReader
- * @param logic Logical operation
- * @return DocIdSet
- */
- private DocIdSet getDocIdSet(AtomicReaderContext context, int logic, int[] index)
- throws IOException
- {
- OpenBitSetDISI result = initialResult(context, logic, index);
- for (; index[0] < chain.length; index[0]++)
- {
- doChain(result, logic, chain[index[0]].getDocIdSet(context));
- }
- return result;
- }
+public class ChainedFilter extends Filter {
- /**
- * Delegates to each filter in the chain.
- * @param reader IndexReader
- * @param logic Logical operation
- * @return DocIdSet
- */
- private DocIdSet getDocIdSet(AtomicReaderContext info, int[] logic, int[] index)
- throws IOException
- {
- if (logic.length != chain.length)
- throw new IllegalArgumentException("Invalid number of elements in logic array");
-
- OpenBitSetDISI result = initialResult(info, logic[0], index);
- for (; index[0] < chain.length; index[0]++)
- {
- doChain(result, logic[index[0]], chain[index[0]].getDocIdSet(info));
- }
- return result;
- }
-
- @Override
- public String toString()
- {
- StringBuilder sb = new StringBuilder();
- sb.append("ChainedFilter: [");
- for (int i = 0; i < chain.length; i++)
- {
- sb.append(chain[i]);
- sb.append(' ');
- }
- sb.append(']');
- return sb.toString();
+ public static final int OR = 0;
+ public static final int AND = 1;
+ public static final int ANDNOT = 2;
+ public static final int XOR = 3;
+ /**
+ * Logical operation when none is declared. Defaults to OR.
+ */
+ public static int DEFAULT = OR;
+
+ /**
+ * The filter chain
+ */
+ private Filter[] chain = null;
+
+ private int[] logicArray;
+
+ private int logic = -1;
+
+ /**
+ * Ctor.
+ *
+ * @param chain The chain of filters
+ */
+ public ChainedFilter(Filter[] chain) {
+ this.chain = chain;
+ }
+
+ /**
+ * Ctor.
+ *
+ * @param chain The chain of filters
+ * @param logicArray Logical operations to apply between filters
+ */
+ public ChainedFilter(Filter[] chain, int[] logicArray) {
+ this.chain = chain;
+ this.logicArray = logicArray;
+ }
+
+ /**
+ * Ctor.
+ *
+ * @param chain The chain of filters
+ * @param logic Logical operation to apply to ALL filters
+ */
+ public ChainedFilter(Filter[] chain, int logic) {
+ this.chain = chain;
+ this.logic = logic;
+ }
+
+ /**
+ * {@link Filter#getDocIdSet}.
+ */
+ @Override
+ public DocIdSet getDocIdSet(AtomicReaderContext context) throws IOException {
+ int[] index = new int[1]; // use array as reference to modifiable int;
+ index[0] = 0; // an object attribute would not be thread safe.
+ if (logic != -1) {
+ return getDocIdSet(context, logic, index);
+ } else if (logicArray != null) {
+ return getDocIdSet(context, logicArray, index);
+ }
+
+ return getDocIdSet(context, DEFAULT, index);
+ }
+
+ private DocIdSetIterator getDISI(Filter filter, AtomicReaderContext context)
+ throws IOException {
+ DocIdSet docIdSet = filter.getDocIdSet(context);
+ if (docIdSet == null) {
+ return DocIdSet.EMPTY_DOCIDSET.iterator();
+ } else {
+ DocIdSetIterator iter = docIdSet.iterator();
+ if (iter == null) {
+ return DocIdSet.EMPTY_DOCIDSET.iterator();
+ } else {
+ return iter;
+ }
}
+ }
- private void doChain(OpenBitSetDISI result, int logic, DocIdSet dis)
- throws IOException {
-
- if (dis instanceof OpenBitSet) {
- // optimized case for OpenBitSets
- switch (logic) {
- case OR:
- result.or((OpenBitSet) dis);
- break;
- case AND:
- result.and((OpenBitSet) dis);
- break;
- case ANDNOT:
- result.andNot((OpenBitSet) dis);
- break;
- case XOR:
- result.xor((OpenBitSet) dis);
- break;
- default:
- doChain(result, DEFAULT, dis);
- break;
- }
+ private OpenBitSetDISI initialResult(AtomicReaderContext context, int logic, int[] index)
+ throws IOException {
+ IndexReader reader = context.reader;
+ OpenBitSetDISI result;
+ /**
+ * First AND operation takes place against a completely false
+ * bitset and will always return zero results.
+ */
+ if (logic == AND) {
+ result = new OpenBitSetDISI(getDISI(chain[index[0]], context), reader.maxDoc());
+ ++index[0];
+ } else if (logic == ANDNOT) {
+ result = new OpenBitSetDISI(getDISI(chain[index[0]], context), reader.maxDoc());
+ result.flip(0, reader.maxDoc()); // NOTE: may set bits for deleted docs.
+ ++index[0];
+ } else {
+ result = new OpenBitSetDISI(reader.maxDoc());
+ }
+ return result;
+ }
+
+ /**
+ * Delegates to each filter in the chain.
+ *
+ * @param context AtomicReaderContext
+ * @param logic Logical operation
+ * @return DocIdSet
+ */
+ private DocIdSet getDocIdSet(AtomicReaderContext context, int logic, int[] index)
+ throws IOException {
+ OpenBitSetDISI result = initialResult(context, logic, index);
+ for (; index[0] < chain.length; index[0]++) {
+ doChain(result, logic, chain[index[0]].getDocIdSet(context));
+ }
+ return result;
+ }
+
+ /**
+ * Delegates to each filter in the chain.
+ *
+ * @param context AtomicReaderContext
+ * @param logic Logical operation
+ * @return DocIdSet
+ */
+ private DocIdSet getDocIdSet(AtomicReaderContext context, int[] logic, int[] index)
+ throws IOException {
+ if (logic.length != chain.length) {
+ throw new IllegalArgumentException("Invalid number of elements in logic array");
+ }
+
+ OpenBitSetDISI result = initialResult(context, logic[0], index);
+ for (; index[0] < chain.length; index[0]++) {
+ doChain(result, logic[index[0]], chain[index[0]].getDocIdSet(context));
+ }
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("ChainedFilter: [");
+ for (Filter aChain : chain) {
+ sb.append(aChain);
+ sb.append(' ');
+ }
+ sb.append(']');
+ return sb.toString();
+ }
+
+ private void doChain(OpenBitSetDISI result, int logic, DocIdSet dis)
+ throws IOException {
+
+ if (dis instanceof OpenBitSet) {
+ // optimized case for OpenBitSets
+ switch (logic) {
+ case OR:
+ result.or((OpenBitSet) dis);
+ break;
+ case AND:
+ result.and((OpenBitSet) dis);
+ break;
+ case ANDNOT:
+ result.andNot((OpenBitSet) dis);
+ break;
+ case XOR:
+ result.xor((OpenBitSet) dis);
+ break;
+ default:
+ doChain(result, DEFAULT, dis);
+ break;
+ }
+ } else {
+ DocIdSetIterator disi;
+ if (dis == null) {
+ disi = DocIdSet.EMPTY_DOCIDSET.iterator();
} else {
- DocIdSetIterator disi;
- if (dis == null) {
+ disi = dis.iterator();
+ if (disi == null) {
disi = DocIdSet.EMPTY_DOCIDSET.iterator();
- } else {
- disi = dis.iterator();
- if (disi == null) {
- disi = DocIdSet.EMPTY_DOCIDSET.iterator();
- }
}
+ }
- switch (logic) {
- case OR:
- result.inPlaceOr(disi);
- break;
- case AND:
- result.inPlaceAnd(disi);
- break;
- case ANDNOT:
- result.inPlaceNot(disi);
- break;
- case XOR:
- result.inPlaceXor(disi);
- break;
- default:
- doChain(result, DEFAULT, dis);
- break;
- }
+ switch (logic) {
+ case OR:
+ result.inPlaceOr(disi);
+ break;
+ case AND:
+ result.inPlaceAnd(disi);
+ break;
+ case ANDNOT:
+ result.inPlaceNot(disi);
+ break;
+ case XOR:
+ result.inPlaceXor(disi);
+ break;
+ default:
+ doChain(result, DEFAULT, dis);
+ break;
}
}
+ }
}
Modified: lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/DuplicateFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/DuplicateFilter.java?rev=1145916&r1=1145915&r2=1145916&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/DuplicateFilter.java (original)
+++ lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/DuplicateFilter.java Wed Jul 13 09:04:52 2011
@@ -15,150 +15,146 @@ package org.apache.lucene.search;
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import java.io.IOException;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.index.*;
import org.apache.lucene.index.IndexReader.AtomicReaderContext;
-import org.apache.lucene.index.Terms;
-import org.apache.lucene.index.DocsEnum;
-import org.apache.lucene.index.TermsEnum;
-import org.apache.lucene.index.MultiFields;
-import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.FixedBitSet;
-public class DuplicateFilter extends Filter
-{ // TODO: make duplicate filter aware of ReaderContext such that we can
+import java.io.IOException;
+
+public class DuplicateFilter extends Filter {
+ // TODO: make duplicate filter aware of ReaderContext such that we can
// filter duplicates across segments
-
- String fieldName;
-
- /**
- * KeepMode determines which document id to consider as the master, all others being
- * identified as duplicates. Selecting the "first occurrence" can potentially save on IO.
- */
- int keepMode=KM_USE_FIRST_OCCURRENCE;
- public static final int KM_USE_FIRST_OCCURRENCE=1;
- public static final int KM_USE_LAST_OCCURRENCE=2;
-
- /**
- * "Full" processing mode starts by setting all bits to false and only setting bits
- * for documents that contain the given field and are identified as none-duplicates.
-
- * "Fast" processing sets all bits to true then unsets all duplicate docs found for the
- * given field. This approach avoids the need to read TermDocs for terms that are seen
- * to have a document frequency of exactly "1" (i.e. no duplicates). While a potentially
- * faster approach , the downside is that bitsets produced will include bits set for
- * documents that do not actually contain the field given.
- *
- */
- int processingMode=PM_FULL_VALIDATION;
- public static final int PM_FULL_VALIDATION=1;
- public static final int PM_FAST_INVALIDATION=2;
-
-
-
- public DuplicateFilter(String fieldName)
- {
- this(fieldName, KM_USE_LAST_OCCURRENCE,PM_FULL_VALIDATION);
- }
-
-
- public DuplicateFilter(String fieldName, int keepMode, int processingMode)
- {
- this.fieldName = fieldName;
- this.keepMode = keepMode;
- this.processingMode = processingMode;
- }
+
+ /**
+ * KeepMode determines which document id to consider as the master, all others being
+ * identified as duplicates. Selecting the "first occurrence" can potentially save on IO.
+ */
+ public enum KeepMode {
+ KM_USE_FIRST_OCCURRENCE, KM_USE_LAST_OCCURRENCE
+ }
+
+ private KeepMode keepMode;
+
+ /**
+ * "Full" processing mode starts by setting all bits to false and only setting bits
+ * for documents that contain the given field and are identified as none-duplicates.
+ * <p/>
+ * "Fast" processing sets all bits to true then unsets all duplicate docs found for the
+ * given field. This approach avoids the need to read TermDocs for terms that are seen
+ * to have a document frequency of exactly "1" (i.e. no duplicates). While a potentially
+ * faster approach , the downside is that bitsets produced will include bits set for
+ * documents that do not actually contain the field given.
+ */
+
+ public enum ProcessingMode {
+ PM_FULL_VALIDATION, PM_FAST_INVALIDATION
+ }
+
+ private ProcessingMode processingMode;
+
+ private String fieldName;
+
+ public DuplicateFilter(String fieldName) {
+ this(fieldName, KeepMode.KM_USE_LAST_OCCURRENCE, ProcessingMode.PM_FULL_VALIDATION);
+ }
+
+ public DuplicateFilter(String fieldName, KeepMode keepMode, ProcessingMode processingMode) {
+ this.fieldName = fieldName;
+ this.keepMode = keepMode;
+ this.processingMode = processingMode;
+ }
@Override
- public DocIdSet getDocIdSet(AtomicReaderContext context) throws IOException
- {
- if(processingMode==PM_FAST_INVALIDATION)
- {
- return fastBits(context.reader);
- }
- else
- {
- return correctBits(context.reader);
- }
- }
-
+ public DocIdSet getDocIdSet(AtomicReaderContext context) throws IOException {
+ if (processingMode == ProcessingMode.PM_FAST_INVALIDATION) {
+ return fastBits(context.reader);
+ } else {
+ return correctBits(context.reader);
+ }
+ }
+
private FixedBitSet correctBits(IndexReader reader) throws IOException {
FixedBitSet bits = new FixedBitSet(reader.maxDoc()); //assume all are INvalid
final Bits liveDocs = MultiFields.getLiveDocs(reader);
Terms terms = reader.fields().terms(fieldName);
- if (terms != null) {
- TermsEnum termsEnum = terms.iterator();
- DocsEnum docs = null;
- while(true) {
- BytesRef currTerm = termsEnum.next();
- if (currTerm == null) {
- break;
- } else {
- docs = termsEnum.docs(liveDocs, docs);
- int doc = docs.nextDoc();
- if (doc != DocsEnum.NO_MORE_DOCS) {
- if (keepMode == KM_USE_FIRST_OCCURRENCE) {
- bits.set(doc);
- } else {
- int lastDoc = doc;
- while (true) {
- lastDoc = doc;
- doc = docs.nextDoc();
- if (doc == DocsEnum.NO_MORE_DOCS) {
- break;
- }
+
+ if (terms == null) {
+ return bits;
+ }
+
+ TermsEnum termsEnum = terms.iterator();
+ DocsEnum docs = null;
+ while (true) {
+ BytesRef currTerm = termsEnum.next();
+ if (currTerm == null) {
+ break;
+ } else {
+ docs = termsEnum.docs(liveDocs, docs);
+ int doc = docs.nextDoc();
+ if (doc != DocsEnum.NO_MORE_DOCS) {
+ if (keepMode == KeepMode.KM_USE_FIRST_OCCURRENCE) {
+ bits.set(doc);
+ } else {
+ int lastDoc = doc;
+ while (true) {
+ lastDoc = doc;
+ doc = docs.nextDoc();
+ if (doc == DocsEnum.NO_MORE_DOCS) {
+ break;
}
- bits.set(lastDoc);
}
+ bits.set(lastDoc);
}
}
}
}
return bits;
}
-
- private FixedBitSet fastBits(IndexReader reader) throws IOException
- {
-
- FixedBitSet bits=new FixedBitSet(reader.maxDoc());
- bits.set(0,reader.maxDoc()); //assume all are valid
+
+ private FixedBitSet fastBits(IndexReader reader) throws IOException {
+ FixedBitSet bits = new FixedBitSet(reader.maxDoc());
+ bits.set(0, reader.maxDoc()); //assume all are valid
final Bits liveDocs = MultiFields.getLiveDocs(reader);
Terms terms = reader.fields().terms(fieldName);
- if (terms != null) {
- TermsEnum termsEnum = terms.iterator();
- DocsEnum docs = null;
- while(true) {
- BytesRef currTerm = termsEnum.next();
- if (currTerm == null) {
- break;
- } else {
- if (termsEnum.docFreq() > 1) {
- // unset potential duplicates
- docs = termsEnum.docs(liveDocs, docs);
- int doc = docs.nextDoc();
- if (doc != DocsEnum.NO_MORE_DOCS) {
- if (keepMode == KM_USE_FIRST_OCCURRENCE) {
- doc = docs.nextDoc();
- }
- }
-
- int lastDoc = -1;
- while (true) {
- lastDoc = doc;
- bits.clear(lastDoc);
+
+ if (terms == null) {
+ return bits;
+ }
+
+ TermsEnum termsEnum = terms.iterator();
+ DocsEnum docs = null;
+ while (true) {
+ BytesRef currTerm = termsEnum.next();
+ if (currTerm == null) {
+ break;
+ } else {
+ if (termsEnum.docFreq() > 1) {
+ // unset potential duplicates
+ docs = termsEnum.docs(liveDocs, docs);
+ int doc = docs.nextDoc();
+ if (doc != DocsEnum.NO_MORE_DOCS) {
+ if (keepMode == KeepMode.KM_USE_FIRST_OCCURRENCE) {
doc = docs.nextDoc();
- if (doc == DocsEnum.NO_MORE_DOCS) {
- break;
- }
}
+ }
- if (keepMode==KM_USE_LAST_OCCURRENCE) {
- // restore the last bit
- bits.set(lastDoc);
+ int lastDoc = -1;
+ while (true) {
+ lastDoc = doc;
+ bits.clear(lastDoc);
+ doc = docs.nextDoc();
+ if (doc == DocsEnum.NO_MORE_DOCS) {
+ break;
}
}
+
+ if (keepMode == KeepMode.KM_USE_LAST_OCCURRENCE) {
+ // restore the last bit
+ bits.set(lastDoc);
+ }
}
}
}
@@ -166,67 +162,51 @@ public class DuplicateFilter extends Fil
return bits;
}
- public String getFieldName()
- {
- return fieldName;
- }
-
-
- public void setFieldName(String fieldName)
- {
- this.fieldName = fieldName;
- }
-
-
- public int getKeepMode()
- {
- return keepMode;
- }
-
-
- public void setKeepMode(int keepMode)
- {
- this.keepMode = keepMode;
- }
-
-
- @Override
- public boolean equals(Object obj)
- {
- if(this == obj)
- return true;
- if((obj == null) || (obj.getClass() != this.getClass()))
- return false;
- DuplicateFilter other = (DuplicateFilter)obj;
- return keepMode == other.keepMode &&
- processingMode == other.processingMode &&
- (fieldName == other.fieldName || (fieldName != null && fieldName.equals(other.fieldName)));
- }
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ public void setFieldName(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ public KeepMode getKeepMode() {
+ return keepMode;
+ }
+
+ public void setKeepMode(KeepMode keepMode) {
+ this.keepMode = keepMode;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if ((obj == null) || (obj.getClass() != this.getClass())) {
+ return false;
+ }
+ DuplicateFilter other = (DuplicateFilter) obj;
+ return keepMode == other.keepMode &&
+ processingMode == other.processingMode &&
+ fieldName != null && fieldName.equals(other.fieldName);
+ }
+ @Override
+ public int hashCode() {
+ int hash = 217;
+ hash = 31 * hash + keepMode.hashCode();
+ hash = 31 * hash + processingMode.hashCode();
+ hash = 31 * hash + fieldName.hashCode();
+ return hash;
+ }
- @Override
- public int hashCode()
- {
- int hash = 217;
- hash = 31 * hash + keepMode;
- hash = 31 * hash + processingMode;
- hash = 31 * hash + fieldName.hashCode();
- return hash;
- }
-
-
- public int getProcessingMode()
- {
- return processingMode;
- }
-
-
- public void setProcessingMode(int processingMode)
- {
- this.processingMode = processingMode;
- }
-
-
+ public ProcessingMode getProcessingMode() {
+ return processingMode;
+ }
+ public void setProcessingMode(ProcessingMode processingMode) {
+ this.processingMode = processingMode;
+ }
}
Modified: lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/FilterClause.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/FilterClause.java?rev=1145916&r1=1145915&r2=1145916&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/FilterClause.java (original)
+++ lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/FilterClause.java Wed Jul 13 09:04:52 2011
@@ -25,11 +25,10 @@ import org.apache.lucene.search.BooleanC
* (Follows the boolean logic in BooleanClause for composition
* of queries.)
*/
+public class FilterClause {
-public class FilterClause
-{
- Occur occur = null;
- Filter filter = null;
+ private final Occur occur;
+ private final Filter filter;
/**
* Create a new FilterClause
@@ -37,8 +36,7 @@ public class FilterClause
* @param occur A parameter implementation indicating SHOULD, MUST or MUST NOT
*/
- public FilterClause( Filter filter,Occur occur)
- {
+ public FilterClause(Filter filter, Occur occur) {
this.occur = occur;
this.filter = filter;
}
@@ -47,9 +45,7 @@ public class FilterClause
* Returns this FilterClause's filter
* @return A Filter object
*/
-
- public Filter getFilter()
- {
+ public Filter getFilter() {
return filter;
}
@@ -57,9 +53,7 @@ public class FilterClause
* Returns this FilterClause's occur parameter
* @return An Occur object
*/
-
- public Occur getOccur()
- {
+ public Occur getOccur() {
return occur;
}
Modified: lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/TermsFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/TermsFilter.java?rev=1145916&r1=1145915&r2=1145916&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/TermsFilter.java (original)
+++ lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/TermsFilter.java Wed Jul 13 09:04:52 2011
@@ -17,102 +17,97 @@ package org.apache.lucene.search;
* limitations under the License.
*/
+import org.apache.lucene.index.*;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.FixedBitSet;
+
import java.io.IOException;
-import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexReader.AtomicReaderContext;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.index.DocsEnum;
-import org.apache.lucene.index.Terms;
-import org.apache.lucene.index.TermsEnum;
-import org.apache.lucene.index.Fields;
-import org.apache.lucene.util.FixedBitSet;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.Bits;
-
/**
- * Constructs a filter for docs matching any of the terms added to this class.
- * Unlike a RangeFilter this can be used for filtering on multiple terms that are not necessarily in
- * a sequence. An example might be a collection of primary keys from a database query result or perhaps
- * a choice of "category" labels picked by the end user. As a filter, this is much faster than the
+ * Constructs a filter for docs matching any of the terms added to this class.
+ * Unlike a RangeFilter this can be used for filtering on multiple terms that are not necessarily in
+ * a sequence. An example might be a collection of primary keys from a database query result or perhaps
+ * a choice of "category" labels picked by the end user. As a filter, this is much faster than the
* equivalent query (a BooleanQuery with many "should" TermQueries)
- *
*/
-public class TermsFilter extends Filter
-{
- Set<Term> terms=new TreeSet<Term>();
-
- /**
- * Adds a term to the list of acceptable terms
- * @param term
- */
- public void addTerm(Term term)
- {
- terms.add(term);
- }
-
+public class TermsFilter extends Filter {
+
+ private final Set<Term> terms = new TreeSet<Term>();
+
+ /**
+ * Adds a term to the list of acceptable terms
+ *
+ * @param term
+ */
+ public void addTerm(Term term) {
+ terms.add(term);
+ }
+
/* (non-Javadoc)
* @see org.apache.lucene.search.Filter#getDocIdSet(org.apache.lucene.index.IndexReader)
- */
+ */
+
@Override
public DocIdSet getDocIdSet(AtomicReaderContext context) throws IOException {
IndexReader reader = context.reader;
- FixedBitSet result=new FixedBitSet(reader.maxDoc());
+ FixedBitSet result = new FixedBitSet(reader.maxDoc());
Fields fields = reader.fields();
+
+ if (fields == null) {
+ return result;
+ }
+
BytesRef br = new BytesRef();
Bits liveDocs = reader.getLiveDocs();
- if (fields != null) {
- String lastField = null;
- Terms termsC = null;
- TermsEnum termsEnum = null;
- DocsEnum docs = null;
- for (Iterator<Term> iter = terms.iterator(); iter.hasNext();) {
- Term term = iter.next();
- if (!term.field().equals(lastField)) {
- termsC = fields.terms(term.field());
- termsEnum = termsC.iterator();
- lastField = term.field();
- }
+ String lastField = null;
+ Terms termsC = null;
+ TermsEnum termsEnum = null;
+ DocsEnum docs = null;
+ for (Term term : terms) {
+ if (!term.field().equals(lastField)) {
+ termsC = fields.terms(term.field());
+ termsEnum = termsC.iterator();
+ lastField = term.field();
+ }
- if (terms != null) {
- br.copy(term.bytes());
- if (termsEnum.seekCeil(br) == TermsEnum.SeekStatus.FOUND) {
- docs = termsEnum.docs(liveDocs, docs);
- while(docs.nextDoc() != DocsEnum.NO_MORE_DOCS) {
- result.set(docs.docID());
- }
+ if (terms != null) { // TODO this check doesn't make sense, decide which variable its supposed to be for
+ br.copy(term.bytes());
+ if (termsEnum.seekCeil(br) == TermsEnum.SeekStatus.FOUND) {
+ docs = termsEnum.docs(liveDocs, docs);
+ while (docs.nextDoc() != DocsEnum.NO_MORE_DOCS) {
+ result.set(docs.docID());
}
}
}
}
return result;
}
-
- @Override
- public boolean equals(Object obj)
- {
- if(this == obj)
- return true;
- if((obj == null) || (obj.getClass() != this.getClass()))
- return false;
- TermsFilter test = (TermsFilter)obj;
- return (terms == test.terms ||
- (terms != null && terms.equals(test.terms)));
- }
-
- @Override
- public int hashCode()
- {
- int hash=9;
- for (Iterator<Term> iter = terms.iterator(); iter.hasNext();)
- {
- Term term = iter.next();
- hash = 31 * hash + term.hashCode();
- }
- return hash;
- }
-
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if ((obj == null) || (obj.getClass() != this.getClass())) {
+ return false;
+ }
+
+ TermsFilter test = (TermsFilter) obj;
+ return (terms == test.terms ||
+ (terms != null && terms.equals(test.terms)));
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 9;
+ for (Term term : terms) {
+ hash = 31 * hash + term.hashCode();
+ }
+ return hash;
+ }
+
}
Modified: lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/JakartaRegexpCapabilities.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/JakartaRegexpCapabilities.java?rev=1145916&r1=1145915&r2=1145916&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/JakartaRegexpCapabilities.java (original)
+++ lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/JakartaRegexpCapabilities.java Wed Jul 13 09:04:52 2011
@@ -36,6 +36,7 @@ import java.lang.reflect.Method;
public class JakartaRegexpCapabilities implements RegexCapabilities {
private static Field prefixField;
private static Method getPrefixMethod;
+
static {
try {
getPrefixMethod = REProgram.class.getMethod("getPrefix");
@@ -76,8 +77,7 @@ public class JakartaRegexpCapabilities i
*
* @param flags The matching style
*/
- public JakartaRegexpCapabilities(int flags)
- {
+ public JakartaRegexpCapabilities(int flags) {
this.flags = flags;
}
@@ -95,15 +95,22 @@ public class JakartaRegexpCapabilities i
@Override
public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null) return false;
- if (getClass() != obj.getClass()) return false;
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
JakartaRegexpCapabilities other = (JakartaRegexpCapabilities) obj;
- if (flags != other.flags) return false;
- return true;
+ return flags == other.flags;
}
class JakartaRegexMatcher implements RegexCapabilities.RegexMatcher {
+
private RE regexp;
private final CharsRef utf16 = new CharsRef(10);
private final CharacterIterator utf16wrapper = new CharacterIterator() {
Modified: lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/JavaUtilRegexCapabilities.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/JavaUtilRegexCapabilities.java?rev=1145916&r1=1145915&r2=1145916&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/JavaUtilRegexCapabilities.java (original)
+++ lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/JavaUtilRegexCapabilities.java Wed Jul 13 09:04:52 2011
@@ -33,6 +33,7 @@ import org.apache.lucene.util.UnicodeUti
* term for the specified field in the index.
*/
public class JavaUtilRegexCapabilities implements RegexCapabilities {
+
private int flags = 0;
// Define the optional flags from Pattern that can be used.
@@ -85,12 +86,18 @@ public class JavaUtilRegexCapabilities i
@Override
public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null) return false;
- if (getClass() != obj.getClass()) return false;
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
JavaUtilRegexCapabilities other = (JavaUtilRegexCapabilities) obj;
- if (flags != other.flags) return false;
- return true;
+ return flags == other.flags;
}
class JavaUtilRegexMatcher implements RegexCapabilities.RegexMatcher {
Modified: lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/RegexQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/RegexQuery.java?rev=1145916&r1=1145915&r2=1145916&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/RegexQuery.java (original)
+++ lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/RegexQuery.java Wed Jul 13 09:04:52 2011
@@ -37,6 +37,7 @@ import java.io.IOException;
* @see RegexTermsEnum
*/
public class RegexQuery extends MultiTermQuery implements RegexQueryCapable {
+
private RegexCapabilities regexImpl = new JavaUtilRegexCapabilities();
private Term term;
@@ -46,7 +47,9 @@ public class RegexQuery extends MultiTer
this.term = term;
}
- public Term getTerm() { return term; }
+ public Term getTerm() {
+ return term;
+ }
/**
* Defines which {@link RegexCapabilities} implementation is used by this instance.
@@ -92,16 +95,33 @@ public class RegexQuery extends MultiTer
@Override
public boolean equals(Object obj) {
- if (this == obj) return true;
- if (!super.equals(obj)) return false;
- if (getClass() != obj.getClass()) return false;
+ if (this == obj) {
+ return true;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
RegexQuery other = (RegexQuery) obj;
if (regexImpl == null) {
- if (other.regexImpl != null) return false;
- } else if (!regexImpl.equals(other.regexImpl)) return false;
+ if (other.regexImpl != null) {
+ return false;
+ }
+ } else if (!regexImpl.equals(other.regexImpl)) {
+ return false;
+ }
+
if (term == null) {
- if (other.term != null) return false;
- } else if (!term.equals(other.term)) return false;
+ if (other.term != null) {
+ return false;
+ }
+ } else if (!term.equals(other.term)) {
+ return false;
+ }
+
return true;
}
}
Modified: lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/RegexQueryCapable.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/RegexQueryCapable.java?rev=1145916&r1=1145915&r2=1145916&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/RegexQueryCapable.java (original)
+++ lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/RegexQueryCapable.java Wed Jul 13 09:04:52 2011
@@ -22,6 +22,7 @@ package org.apache.lucene.search.regex;
* Defines methods for regular expression supporting Querys to use.
*/
public interface RegexQueryCapable {
+
void setRegexImplementation(RegexCapabilities impl);
RegexCapabilities getRegexImplementation();
}
Modified: lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/RegexTermsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/RegexTermsEnum.java?rev=1145916&r1=1145915&r2=1145916&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/RegexTermsEnum.java (original)
+++ lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/RegexTermsEnum.java Wed Jul 13 09:04:52 2011
@@ -34,6 +34,7 @@ import java.io.IOException;
*/
public class RegexTermsEnum extends FilteredTermsEnum {
+
private RegexCapabilities.RegexMatcher regexImpl;
private final BytesRef prefixRef;
@@ -43,7 +44,9 @@ public class RegexTermsEnum extends Filt
this.regexImpl = regexCap.compile(text);
String pre = regexImpl.prefix();
- if (pre == null) pre = "";
+ if (pre == null) {
+ pre = "";
+ }
setInitialSeekTerm(prefixRef = new BytesRef(pre));
}