Search in sources :

Example 1 with ByteRunAutomaton

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);
    }
}
Also used : RegExp(org.apache.lucene.util.automaton.RegExp) ByteRunAutomaton(org.apache.lucene.util.automaton.ByteRunAutomaton) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

BytesRef (org.apache.lucene.util.BytesRef)1 ByteRunAutomaton (org.apache.lucene.util.automaton.ByteRunAutomaton)1 RegExp (org.apache.lucene.util.automaton.RegExp)1