private boolean prefixMatches(BytesRef target) { for(int bytePos=0;bytePos<prefix;bytePos++) { if (target.bytes[target.offset + bytePos] != ste.term.byteAt(bytePos)) { return false; } } return true; }
/** * Attempts to backtrack thru the string after encountering a dead end * at some given position. Returns false if no more possible strings * can match. * * @param position current position in the input String * @return {@code position >= 0} if more possible solutions exist for the DFA */ private int backtrack(int position) { while (position-- > 0) { int nextChar = seekBytesRef.byteAt(position) & 0xff; // if a character is 0xff it's a dead-end too, // because there is no higher character in binary sort order. if (nextChar++ != 0xff) { seekBytesRef.setByteAt(position, (byte) nextChar); seekBytesRef.setLength(position+1); return position; } } return -1; /* all solutions exhausted */ } }
state = runAutomaton.step(state, seekBytesRef.byteAt(i) & 0xff); assert state >= 0: "state=" + state; for (int i = 0; i < numTransitions; i++) { automaton.getNextTransition(transition); if (transition.min <= (seekBytesRef.byteAt(position) & 0xff) && (seekBytesRef.byteAt(position) & 0xff) <= transition.max) { maxInterval = transition.max; break;
/** Pushes the new term to the top of the stack, and writes new blocks. */ private void pushTerm(BytesRef text) throws IOException { int limit = Math.min(lastTerm.length(), text.length); // Find common prefix between last term and current term: int pos = 0; while (pos < limit && lastTerm.byteAt(pos) == text.bytes[text.offset+pos]) { pos++; } // if (DEBUG) System.out.println(" shared=" + pos + " lastTerm.length=" + lastTerm.length); // Close the "abandoned" suffix now: for(int i=lastTerm.length()-1;i>=pos;i--) { // How many items on top of the stack share the current suffix // we are closing: int prefixTopSize = pending.size() - prefixStarts[i]; if (prefixTopSize >= minItemsInBlock) { // if (DEBUG) System.out.println("pushTerm i=" + i + " prefixTopSize=" + prefixTopSize + " minItemsInBlock=" + minItemsInBlock); writeBlocks(i+1, prefixTopSize); prefixStarts[i] -= prefixTopSize-1; } } if (prefixStarts.length < text.length) { prefixStarts = ArrayUtil.grow(prefixStarts, text.length); } // Init new tail: for(int i=pos;i<text.length;i++) { prefixStarts[i] = pending.size(); } lastTerm.copyBytes(text); }
@Override protected int comparePivot(int j) { for (int o = 0; o < pivot.length(); ++o) { final int b1 = pivot.byteAt(o) & 0xff; final int b2 = byteAt(j, d + o); if (b1 != b2) { return b1 - b2; } } if (d + pivot.length() == maxLength) { return 0; } return -1 - byteAt(j, d + pivot.length()); }
@Override protected int comparePivot(int j) { for (int o = 0; o < pivot.length(); ++o) { final int b1 = pivot.byteAt(o) & 0xff; final int b2 = byteAt(j, k + o); if (b1 != b2) { return b1 - b2; } } if (k + pivot.length() == maxLength) { return 0; } return -1 - byteAt(j, k + pivot.length()); }
int nextState = runAutomaton.step(state, seekBytesRef.byteAt(pos) & 0xff); if (nextState == -1) break; if ((pos = backtrack(pos)) < 0) /* no more solutions at all */ return false; final int newState = runAutomaton.step(savedStates.intAt(pos), seekBytesRef.byteAt(pos) & 0xff); if (newState >= 0 && runAutomaton.isAccept(newState))
c = seekBytesRef.byteAt(position) & 0xff;
private boolean prefixMatches(BytesRef target) { for(int bytePos=0;bytePos<prefix;bytePos++) { if (target.bytes[target.offset + bytePos] != ste.term.byteAt(bytePos)) { return false; } } return true; }
private boolean prefixMatches(BytesRef target) { for(int bytePos=0;bytePos<prefix;bytePos++) { if (target.bytes[target.offset + bytePos] != ste.term.byteAt(bytePos)) { return false; } } return true; }
private boolean prefixMatches(BytesRef target) { for(int bytePos=0;bytePos<prefix;bytePos++) { if (target.bytes[target.offset + bytePos] != ste.term.byteAt(bytePos)) { return false; } } return true; }
private boolean prefixMatches(BytesRef target) { for(int bytePos=0;bytePos<prefix;bytePos++) { if (target.bytes[target.offset + bytePos] != ste.term.byteAt(bytePos)) { return false; } } return true; }
private boolean prefixMatches(BytesRef target) { for(int bytePos=0;bytePos<prefix;bytePos++) { if (target.bytes[target.offset + bytePos] != ste.term.byteAt(bytePos)) { return false; } } return true; }
private boolean prefixMatches(BytesRef target) { for(int bytePos=0;bytePos<prefix;bytePos++) { if (target.bytes[target.offset + bytePos] != ste.term.byteAt(bytePos)) { return false; } } return true; }
@Override public int advance(int target) throws IOException { for (int i = target; i < maxDoc; ++i) { in.seek(field.dataStartFilePointer + (1+field.pattern.length()+2)*i); SimpleTextUtil.readLine(in, scratch); // data SimpleTextUtil.readLine(in, scratch); // 'T' or 'F' if (scratch.byteAt(0) == (byte) 'T') { return doc = i; } } return doc = NO_MORE_DOCS; }
@Override boolean advanceExact(int target) throws IOException { this.doc = target; in.seek(field.dataStartFilePointer + (1+field.pattern.length()+2)*target); SimpleTextUtil.readLine(in, scratch); // data SimpleTextUtil.readLine(in, scratch); // 'T' or 'F' return scratch.byteAt(0) == (byte) 'T'; } };
@Override protected int comparePivot(int j) { for (int o = 0; o < pivot.length(); ++o) { final int b1 = pivot.byteAt(o) & 0xff; final int b2 = byteAt(j, d + o); if (b1 != b2) { return b1 - b2; } } if (d + pivot.length() == maxLength) { return 0; } return -1 - byteAt(j, d + pivot.length()); }