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

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

Introduction

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

Prototype

public Automaton(int numStates, int numTransitions) 

Source Link

Document

Constructor which creates an automaton with enough space for the given number of states and transitions.

Usage

From source file:com.lucene.MyPrefixQuery.java

License:Apache License

public static Automaton toAutomaton(BytesRef prefix) {
    final int numStatesAndTransitions = prefix.length + 1;
    final Automaton automaton = new Automaton(numStatesAndTransitions, numStatesAndTransitions);
    int lastState = automaton.createState();
    for (int i = 0; i < prefix.length; i++) {
        int state = automaton.createState();
        automaton.addTransition(lastState, state, prefix.bytes[prefix.offset + i] & 0xff);
        lastState = state;//from  w ww  . ja  va  2 s.  c om
    }
    automaton.setAccept(lastState, true);
    automaton.addTransition(lastState, lastState, 0, 255);
    automaton.finishState();
    assert automaton.isDeterministic();
    return automaton;
}