private AutomatonBackedStringFilter(Automaton automaton) { this.runAutomaton = new ByteRunAutomaton(automaton); }
/** returns true if term is within k edits of the query term */ private boolean matches(BytesRef termIn, int k) { return k == 0 ? termIn.equals(term.bytes()) : automata[k].runAutomaton.run(termIn.bytes, termIn.offset, termIn.length); }
if (runAutomaton.isAccept(state)) { output.clear(); return output.get(); while (true) { int label = input.bytes[input.offset + idx] & 0xff; int nextState = runAutomaton.step(state, label); if (nextState != -1 && runAutomaton.isAccept(nextState)) { int numTransitions = automaton.getNumTransitions(state); if (numTransitions == 0) { assert runAutomaton.isAccept(state); output.setLength(idx); if (runAutomaton.isAccept(state)) { output.setLength(idx);
public boolean matches(BytesRef term) { if (compiled == null) { compiled = new ByteRunAutomaton(automaton); } return compiled.run(term.bytes, term.offset, term.length); } }
int state = runAutomaton.getInitialState(); if (runAutomaton.isAccept(state)) { output.clear(); return output.get(); while (true) { int label = input.bytes[input.offset + idx] & 0xff; int nextState = runAutomaton.step(state, label); if (nextState != -1 && runAutomaton.isAccept(nextState)) { int numTransitions = automaton.getNumTransitions(state); if (numTransitions == 0) { assert runAutomaton.isAccept(state); output.setLength(idx); if (runAutomaton.isAccept(state)) { output.setLength(idx);
/** * Returns true if the given byte array is accepted by this automaton */ public boolean run(byte[] s, int offset, int length) { int p = 0; int l = offset + length; for (int i = offset; i < l; i++) { p = step(p, s[i] & 0xFF); if (p == -1) return false; } return accept[p]; } }
@Override protected BytesRef nextSeekTerm(final BytesRef term) throws IOException { //System.out.println("ATE.nextSeekTerm term=" + term); if (term == null) { assert seekBytesRef.length() == 0; // return the empty term, as it's valid if (runAutomaton.isAccept(0)) { return seekBytesRef.get(); } } else { seekBytesRef.copyBytes(term); } // seek to the next possible string; if (nextString()) { return seekBytesRef.get(); // reposition } else { return null; // no more possible strings can match } }
@Override protected BytesRef nextSeekTerm(final BytesRef term) throws IOException { //System.out.println("ATE.nextSeekTerm term=" + term); if (term == null) { assert seekBytesRef.length() == 0; // return the empty term, as it's valid if (runAutomaton.isAccept(runAutomaton.getInitialState())) { return seekBytesRef.get(); } } else { seekBytesRef.copyBytes(term); } // seek to the next possible string; if (nextString()) { return seekBytesRef.get(); // reposition } else { return null; // no more possible strings can match } }
assert linear == false; int state = runAutomaton.getInitialState(); assert state == 0; int maxInterval = 0xff; state = runAutomaton.step(state, seekBytesRef.byteAt(i) & 0xff); assert state >= 0: "state=" + state;
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((runAutomaton == null) ? 0 : runAutomaton.hashCode()); result = prime * result + ((term == null) ? 0 : term.hashCode()); result = prime * result + ((type == null) ? 0 : type.hashCode()); return result; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; CompiledAutomaton other = (CompiledAutomaton) obj; if (type != other.type) return false; if (type == AUTOMATON_TYPE.SINGLE) { if (!term.equals(other.term)) return false; } else if (type == AUTOMATON_TYPE.NORMAL) { if (!runAutomaton.equals(other.runAutomaton)) return false; } return true; } }
/** * Construct an enumerator based upon an automaton, enumerating the specified * field, working on a supplied TermsEnum * * @lucene.experimental * @param compiled CompiledAutomaton */ public AutomatonTermsEnum(TermsEnum tenum, CompiledAutomaton compiled) { super(tenum); if (compiled.type != CompiledAutomaton.AUTOMATON_TYPE.NORMAL) { throw new IllegalArgumentException("please use CompiledAutomaton.getTermsEnum instead"); } this.finite = compiled.finite; this.runAutomaton = compiled.runAutomaton; assert this.runAutomaton != null; this.commonSuffixRef = compiled.commonSuffixRef; this.automaton = compiled.automaton; // used for path tracking, where each bit is a numbered state. visited = new long[runAutomaton.getSize()]; }
int state = runAutomaton.getInitialState(); if (runAutomaton.isAccept(state)) { output.clear(); return output.get(); while (true) { int label = input.bytes[input.offset + idx] & 0xff; int nextState = runAutomaton.step(state, label); if (nextState != -1 && runAutomaton.isAccept(nextState)) { int numTransitions = automaton.getNumTransitions(state); if (numTransitions == 0) { assert runAutomaton.isAccept(state); output.setLength(idx); if (runAutomaton.isAccept(state)) { output.setLength(idx);
state = runAutomaton.step(state, seekBytesRef.byteAt(i) & 0xff); assert state >= 0: "state=" + state;
if (numTransitions == 0) { assert runAutomaton.isAccept(state); term.setLength(idx);
@Override protected BytesRef nextSeekTerm(final BytesRef term) throws IOException { //System.out.println("ATE.nextSeekTerm term=" + term); if (term == null) { assert seekBytesRef.length() == 0; // return the empty term, as it's valid if (runAutomaton.isAccept(runAutomaton.getInitialState())) { return seekBytesRef.get(); } } else { seekBytesRef.copyBytes(term); } // seek to the next possible string; if (nextString()) { return seekBytesRef.get(); // reposition } else { return null; // no more possible strings can match } }
assert linear == false; int state = runAutomaton.getInitialState(); assert state == 0; int maxInterval = 0xff; state = runAutomaton.step(state, seekBytesRef.byteAt(i) & 0xff); assert state >= 0: "state=" + state;
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((runAutomaton == null) ? 0 : runAutomaton.hashCode()); result = prime * result + ((term == null) ? 0 : term.hashCode()); result = prime * result + ((type == null) ? 0 : type.hashCode()); return result; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; CompiledAutomaton other = (CompiledAutomaton) obj; if (type != other.type) return false; if (type == AUTOMATON_TYPE.SINGLE) { if (!term.equals(other.term)) return false; } else if (type == AUTOMATON_TYPE.NORMAL) { if (!runAutomaton.equals(other.runAutomaton)) return false; } return true; } }
/** * Construct an enumerator based upon an automaton, enumerating the specified * field, working on a supplied TermsEnum * * @lucene.experimental * @param compiled CompiledAutomaton */ public AutomatonTermsEnum(TermsEnum tenum, CompiledAutomaton compiled) { super(tenum); this.finite = compiled.finite; this.runAutomaton = compiled.runAutomaton; assert this.runAutomaton != null; this.commonSuffixRef = compiled.commonSuffixRef; this.automaton = compiled.automaton; // used for path tracking, where each bit is a numbered state. visited = new long[runAutomaton.getSize()]; }