Well, I did my custom TermSetQuery and TermSetTermEnum...
Code:
public class TermSetQuery extends MultiTermQuery {
private static final long serialVersionUID = -2230410403970258630L;
private String field;
private String[] values;
public String getField() { return field; }
public String[] getValues() { return values; }
public TermSetQuery(String field, String[] values) {
this.field = field;
this.values = values;
}
@Override
protected FilteredTermEnum getEnum(IndexReader reader) throws IOException {
return new TermSetTermEnum(reader, field, new HashSet<String>(Arrays.asList(values)));
}
@Override
public String toString(String field) {
StringBuilder buffer = new StringBuilder();
if (!getField().equals(field)) {
buffer.append(getField());
buffer.append(":");
}
buffer.append('[');
for(String value: values){
buffer.append(value + ';');
}
buffer.append(']');
return buffer.toString();
}
@Override
public boolean equals(final Object obj) {
boolean isEquals = false;
if (HashCodeUtils.preEquals(this, obj)) {
final TermSetQuery otherEntity = (TermSetQuery) obj;
isEquals = HashCodeUtils.buildEquals()
.append(this.field, otherEntity.getField())
.append(this.values, otherEntity.getValues())
.isEquals();
}
return isEquals;
}
@Override
public int hashCode() {
return HashCodeUtils.buildHashCode()
.append(this.field)
.append(this.values)
.toHashCode();
}
}
Code:
public class TermSetTermEnum extends FilteredTermEnum {
private String field;
private TreeSet<String> values;
private boolean endEnum = false;
public TermSetTermEnum(IndexReader reader, String field, Set<String> values) throws IOException {
this.field = StringHelper.intern(field);
this.values = new TreeSet<String>(values);
setEnum(reader.terms(this.values.isEmpty() ? new Term(this.field) : new Term(this.field, this.values.first())));
}
@Override
public float difference() {
return 1.0f;
}
@Override
protected boolean endEnum() {
return endEnum;
}
@Override
protected boolean termCompare(Term term) {
if (term != null && term.field() == field) {
return values.contains(term.text());
} else {
endEnum = true;
return false;
}
}
}
Maybe I re-invented the wheel, but I didn't find such class in lucene core :)