Example usage for org.apache.lucene.util.automaton ByteRunAutomaton ByteRunAutomaton

List of usage examples for org.apache.lucene.util.automaton ByteRunAutomaton ByteRunAutomaton

Introduction

In this page you can find the example usage for org.apache.lucene.util.automaton ByteRunAutomaton ByteRunAutomaton.

Prototype

public ByteRunAutomaton(Automaton a) 

Source Link

Document

Converts incoming automaton to byte-based (UTF32ToUTF8) first

Usage

From source file:io.crate.expression.operator.RegexpMatchOperator.java

License:Apache License

@Override
public Boolean evaluate(Input<BytesRef>... args) {
    assert args.length == 2 : "invalid number of arguments";
    BytesRef source = args[0].value();/*from w  w  w. j  a va2 s.c  o m*/
    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);
    }
}

From source file:io.crate.operation.operator.RegexpMatchOperator.java

License:Apache License

@Override
public Boolean evaluate(Input<BytesRef>... args) {
    assert args.length == 2 : "invalid number of arguments";
    BytesRef source = args[0].value();//from  w  ww. j  a v a  2  s  .co m
    if (source == null) {
        return null;
    }
    BytesRef pattern = args[1].value();
    if (pattern == null) {
        return null;
    }
    if (isPcrePattern(pattern)) {
        return source.utf8ToString().matches(pattern.utf8ToString());
    } else {
        RegExp regexp = new RegExp(pattern.utf8ToString());
        ByteRunAutomaton regexpRunAutomaton = new ByteRunAutomaton(regexp.toAutomaton());
        return regexpRunAutomaton.run(source.bytes, source.offset, source.length);
    }
}