Hi,
I'd like to implement a SetFilter like describe in
http://www.nabble.com/Re%3A-Too-many-clauses-p1145373.html
At the moment, I have a working implementation but there are some gotchas I
do not understand (i.e I take the code from RangeFilter and adapt it as
suggested by the post)
Could someone have a look at my implementation and do some suggestion about
the TODO flags (or about the code if it is not so good)
public class SetFilter extends org.apache.lucene.search.Filter {
private String fieldName;
private Set<String> fieldAuthorizedValues;
public SetFilter(String fieldName, Set<String> fieldAuthorizedValues) {
this.fieldName = fieldName;
this.fieldAuthorizedValues = fieldAuthorizedValues;
}
@Override
public BitSet bits(IndexReader reader) throws IOException {
BitSet bits = new BitSet(reader.maxDoc());
//builds an enum only on the inspected field
TermEnum enumerator = reader.terms(new Term(fieldName,""));
try {
//TODO: why should this happen ?
if (enumerator.term() == null) {
return bits;
}
TermDocs termDocs = reader.termDocs();
try {
do {
Term term = enumerator.term();
//TODO: why the term can be null ?
//TODO: why the term can have a field different from the
inspected one ?
if (term != null && term.field().equals(fieldName)) {
if
(this.fieldAuthorizedValues.contains(term.text())) {
/* we have a good term, find the docs */
termDocs.seek(enumerator.term());
while (termDocs.next()) {
bits.set(termDocs.doc());
}
}
} else {
break;
}
}
while (enumerator.next());
} finally {
termDocs.close();
}
} finally {
enumerator.close();
}
return bits;
}
}
--
View this message in context:
http://www.nabble.com/question-on-the-implementation-of-a-SetFilter-tp14525027p14525027.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]