@Override protected AcceptStatus accept( BytesRef term ) { return StringHelper.startsWith( term, prefix ) ? AcceptStatus.YES : AcceptStatus.END; } }
@Override public BytesRef subtract(BytesRef output, BytesRef inc) { assert output != null; assert inc != null; if (inc == NO_OUTPUT) { // no prefix removed return output; } else { assert StringHelper.startsWith(output, inc); if (inc.length == output.length) { // entire output removed return NO_OUTPUT; } else { assert inc.length < output.length: "inc.length=" + inc.length + " vs output.length=" + output.length; assert inc.length > 0; return new BytesRef(output.bytes, output.offset + inc.length, output.length-inc.length); } } }
if (isSubBlock && StringHelper.startsWith(target, term)) {
assert StringHelper.startsWith(term.termBytes, prefix): "term.term=" + term.termBytes + " prefix=" + prefix; BlockTermState state = term.state; final int suffix = term.termBytes.length - prefixLength; PendingTerm term = (PendingTerm) ent; assert StringHelper.startsWith(term.termBytes, prefix): "term.term=" + term.termBytes + " prefix=" + prefix; BlockTermState state = term.state; final int suffix = term.termBytes.length - prefixLength; } else { PendingBlock block = (PendingBlock) ent; assert StringHelper.startsWith(block.prefix, prefix); final int suffix = block.prefix.length - prefixLength; assert StringHelper.startsWith(block.prefix, prefix);
StringHelper.startsWith(max, min) && suffixIsZeros(max, min.length)) {
@Override protected AcceptStatus accept(BytesRef term) { if (StringHelper.startsWith(term, prefixRef) && (floorLeadEnd == -1 || term.length == prefixRef.length || (term.bytes[term.offset + prefixRef.length] & 0xff) <= floorLeadEnd)) { return AcceptStatus.YES; } else { return AcceptStatus.END; } } };
@Override protected AcceptStatus accept(BytesRef term) { if (StringHelper.startsWith(term, prefixRef) && (floorLeadEnd == -1 || term.length == prefixRef.length || (term.bytes[term.offset + prefixRef.length] & 0xff) <= floorLeadEnd)) { return AcceptStatus.YES; } else { return AcceptStatus.END; } } };
private void getPrefixTerms(ObjectHashSet<Term> terms, final Term prefix, final IndexReader reader) throws IOException { // SlowCompositeReaderWrapper could be used... but this would merge all terms from each segment into one terms // instance, which is very expensive. Therefore I think it is better to iterate over each leaf individually. List<LeafReaderContext> leaves = reader.leaves(); for (LeafReaderContext leaf : leaves) { Terms _terms = leaf.reader().terms(field); if (_terms == null) { continue; } TermsEnum termsEnum = _terms.iterator(); TermsEnum.SeekStatus seekStatus = termsEnum.seekCeil(prefix.bytes()); if (TermsEnum.SeekStatus.END == seekStatus) { continue; } for (BytesRef term = termsEnum.term(); term != null; term = termsEnum.next()) { if (!StringHelper.startsWith(term, prefix.bytes())) { break; } terms.add(new Term(field, BytesRef.deepCopyOf(term))); if (terms.size() >= maxExpansions) { return; } } } }
@Override protected AcceptStatus accept(BytesRef term) { if (StringHelper.startsWith(term, prefixRef)) { // TODO: set BoostAttr based on distance of // searchTerm.text() and term().text() return regexImpl.match(term) ? AcceptStatus.YES : AcceptStatus.NO; } else { return AcceptStatus.NO; } } }
private BytesRef setTerm() throws IOException { term = termsEnum.term(); //System.out.println(" setTerm() term=" + term.utf8ToString() + " vs prefix=" + (prefix == null ? "null" : prefix.utf8ToString())); if (prefix != null && !StringHelper.startsWith(term, prefix)) { term = null; } return term; } }
private BytesRef setTerm() throws IOException { term = termsEnum.term(); //System.out.println(" setTerm() term=" + term.utf8ToString() + " vs prefix=" + (prefix == null ? "null" : prefix.utf8ToString())); if (prefix != null && !StringHelper.startsWith(term, prefix)) { term = null; } return term; } }
private boolean startsWith(BytesRef prefix) { return StringHelper.startsWith(scratch.get(), prefix); }
/** Used only in ctor: */ private boolean startsWith(BytesRef prefix) { return StringHelper.startsWith(scratch.get(), prefix); }
private boolean startsWith(BytesRefBuilder scratch, BytesRef prefix) { return StringHelper.startsWith(scratch.get(), prefix); }
@Override public boolean isPrefixOf(Cell c) { NRCell otherCell = (NRCell) c; assert term != otherCell.term; //trick to re-use bytesref; provided that we re-instate it int myLastLen = term.length; term.length = termLenByLevel[getLevel()]; int otherLastLen = otherCell.term.length; otherCell.term.length = termLenByLevel[otherCell.getLevel()]; boolean answer = StringHelper.startsWith(otherCell.term, term); term.length = myLastLen; otherCell.term.length = otherLastLen; return answer; }
@Override public boolean isPrefixOf(Cell c) { NRCell otherCell = (NRCell) c; assert term != otherCell.term; //trick to re-use bytesref; provided that we re-instate it int myLastLen = term.length; term.length = termLenByLevel[getLevel()]; int otherLastLen = otherCell.term.length; otherCell.term.length = termLenByLevel[otherCell.getLevel()]; boolean answer = StringHelper.startsWith(otherCell.term, term); term.length = myLastLen; otherCell.term.length = otherLastLen; return answer; }
@Override public boolean isPrefixOf(Cell c) { //Note: this only works when each level uses a whole number of bytes. LegacyCell cell = (LegacyCell)c; boolean result = sliceEquals(cell.bytes, cell.b_off, cell.b_len, bytes, b_off, b_len); assert result == StringHelper.startsWith(c.getTokenBytesNoLeaf(null), getTokenBytesNoLeaf(null)); return result; }
@Override public boolean isPrefixOf(Cell c) { //Note: this only works when each level uses a whole number of bytes. LegacyCell cell = (LegacyCell)c; boolean result = sliceEquals(cell.bytes, cell.b_off, cell.b_len, bytes, b_off, b_len); assert result == StringHelper.startsWith(c.getTokenBytesNoLeaf(null), getTokenBytesNoLeaf(null)); return result; }
private SortedNumericSelector.Type readNumericSelector(IndexInput input, BytesRefBuilder scratch) throws IOException { SimpleTextUtil.readLine(input, scratch); assert StringHelper.startsWith(scratch.get(), SI_SELECTOR_TYPE); final String selectorAsString = readString(SI_SELECTOR_TYPE.length, scratch); switch (selectorAsString) { case "min": return SortedNumericSelector.Type.MIN; case "max": return SortedNumericSelector.Type.MAX; default: throw new CorruptIndexException("unable to parse SortedNumericSelector type: " + selectorAsString, input); } }
private void readIndex(int maxDoc) throws IOException { ChecksumIndexInput input = new BufferedChecksumIndexInput(in); offsets = new long[maxDoc]; int upto = 0; while (!scratch.get().equals(END)) { SimpleTextUtil.readLine(input, scratch); if (StringHelper.startsWith(scratch.get(), DOC)) { offsets[upto] = input.getFilePointer(); upto++; } } SimpleTextUtil.checkFooter(input); assert upto == offsets.length; }