use of org.apache.lucene.util.automaton.ByteRunAutomaton in project crate by crate.
the class RegexpMatchOperator method evaluate.
@Override
public Boolean evaluate(Input<BytesRef>... args) {
assert args.length == 2 : "invalid number of arguments";
BytesRef source = args[0].value();
if (source == null) {
return null;
}
BytesRef pattern = args[1].value();
if (pattern == null) {
return null;
}
String sPattern = pattern.utf8ToString();
if (isPcrePattern(sPattern)) {
return source.utf8ToString().matches(sPattern);
} else {
RegExp regexp = new RegExp(sPattern);
ByteRunAutomaton regexpRunAutomaton = new ByteRunAutomaton(regexp.toAutomaton());
return regexpRunAutomaton.run(source.bytes, source.offset, source.length);
}
}
Aggregations