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

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

Introduction

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

Prototype

public void setAccept(int state, boolean accept) 

Source Link

Document

Set or clear this state as an accept state.

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;//  w w  w . ja v  a 2  s.c  o m
    }
    automaton.setAccept(lastState, true);
    automaton.addTransition(lastState, lastState, 0, 255);
    automaton.finishState();
    assert automaton.isDeterministic();
    return automaton;
}