@Override
public FilterScript newInstance(LeafReaderContext context) throws IOException {
final byte[] decodedTerms = Base64.getDecoder().decode(terms);
final ByteBuffer buffer = ByteBuffer.wrap(decodedTerms);
RoaringBitmap rBitmap = new RoaringBitmap();
rBitmap.deserialize(buffer);
return new FilterScript(params, lookup, context) {
@Override
public boolean execute() {
try {
final ScriptDocValues.Longs fieldNameValue = (ScriptDocValues.Longs)getDoc().get(fieldName);
final int docId = (int)fieldNameValue.getValue();
if (opType.equals("exclude") && rBitmap.contains(docId)) {
return false;
}
else if (opType.equals("include") && !rBitmap.contains(docId)) {
return false;
}
return true;
} catch (Exception exception) {
throw exception;
}
}
};
}
|