mirror of https://github.com/apache/lucene.git
SOLR-737: fix filters equals/hashcode so they can be cached if used directly in a non-rewritten query
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@690332 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e3512d241b
commit
142ed529e9
|
@ -18,10 +18,12 @@
|
|||
package org.apache.solr.search;
|
||||
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.apache.lucene.search.DocIdSet;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.TermEnum;
|
||||
import org.apache.lucene.index.TermDocs;
|
||||
import org.apache.lucene.util.OpenBitSet;
|
||||
|
||||
import java.util.BitSet;
|
||||
import java.io.IOException;
|
||||
|
@ -38,6 +40,7 @@ public class PrefixFilter extends Filter {
|
|||
|
||||
Term getPrefix() { return prefix; }
|
||||
|
||||
@Override
|
||||
public BitSet bits(IndexReader reader) throws IOException {
|
||||
final BitSet bitSet = new BitSet(reader.maxDoc());
|
||||
new PrefixGenerator(prefix) {
|
||||
|
@ -47,6 +50,36 @@ public class PrefixFilter extends Filter {
|
|||
}.generate(reader);
|
||||
return bitSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
|
||||
final OpenBitSet bitSet = new OpenBitSet(reader.maxDoc());
|
||||
new PrefixGenerator(prefix) {
|
||||
public void handleDoc(int doc) {
|
||||
bitSet.set(doc);
|
||||
}
|
||||
}.generate(reader);
|
||||
return bitSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof PrefixFilter && ((PrefixFilter)o).prefix.equals(this.prefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 0xcecf7fe2 + prefix.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString () {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("PrefixFilter(");
|
||||
sb.append(prefix.toString());
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
// keep this protected until I decide if it's a good way
|
||||
|
|
|
@ -46,6 +46,7 @@ public class WildcardFilter extends Filter {
|
|||
/**
|
||||
* @deprecated Use {@link #getDocIdSet(IndexReader)} instead.
|
||||
*/
|
||||
@Override
|
||||
public BitSet bits(IndexReader reader) throws IOException {
|
||||
final BitSet bitSet = new BitSet(reader.maxDoc());
|
||||
new WildcardGenerator(term) {
|
||||
|
@ -56,6 +57,7 @@ public class WildcardFilter extends Filter {
|
|||
return bitSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
|
||||
final OpenBitSet bitSet = new OpenBitSet(reader.maxDoc());
|
||||
new WildcardGenerator(term) {
|
||||
|
@ -66,6 +68,17 @@ public class WildcardFilter extends Filter {
|
|||
return bitSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof WildcardFilter && ((WildcardFilter)o).term.equals(this.term);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return term.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString () {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("WildcardFilter(");
|
||||
|
|
Loading…
Reference in New Issue