/** Constructs a Term with the given field and the bytes from a builder. * <p>Note that a null field value results in undefined * behavior for most Lucene APIs that accept a Term parameter. */ public Term(String fld, BytesRefBuilder bytesBuilder) { field = fld; this.bytes = bytesBuilder.toBytesRef(); }
final Term term = new Term(query.field, st.bytes.toBytesRef());
@Override public BytesRef get(int index) { /** * We need to make a copy here because {@link BinaryScriptDocValues} might reuse the * returned value and the same instance might be used to * return values from multiple documents. **/ return values[index].toBytesRef(); }
@Override public void nextToken() throws IOException { this.fillBytesRef(result); if (posIncAttr.getPositionIncrement() > 0 && result.get().bytesEquals(candidate.term)) { BytesRef term = result.toBytesRef(); // We should not use frequency(term) here because it will analyze the term again // If preFilter and postFilter are the same analyzer it would fail. long freq = internalFrequency(term); candidates.add(new Candidate(result.toBytesRef(), freq, candidate.stringDistance, score(candidate.frequency, candidate.stringDistance, dictSize), false)); } else { candidates.add(new Candidate(result.toBytesRef(), candidate.frequency, nonErrorLikelihood, score(candidate.frequency, candidate.stringDistance, dictSize), false)); } } }, spare);
public UidIndexFieldData(Index index, String type, IndexFieldData<?> idFieldData) { this.index = index; BytesRefBuilder prefix = new BytesRefBuilder(); prefix.append(new BytesRef(type)); prefix.append((byte) '#'); this.prefix = prefix.toBytesRef(); this.idFieldData = idFieldData; }
private static Query parseQueryString(ExtendedCommonTermsQuery query, Object queryString, String field, Analyzer analyzer, String lowFreqMinimumShouldMatch, String highFreqMinimumShouldMatch) throws IOException { // Logic similar to QueryParser#getFieldQuery try (TokenStream source = analyzer.tokenStream(field, queryString.toString())) { source.reset(); CharTermAttribute termAtt = source.addAttribute(CharTermAttribute.class); BytesRefBuilder builder = new BytesRefBuilder(); while (source.incrementToken()) { // UTF-8 builder.copyChars(termAtt); query.add(new Term(field, builder.toBytesRef())); } } query.setLowFreqMinimumNumberShouldMatch(lowFreqMinimumShouldMatch); query.setHighFreqMinimumNumberShouldMatch(highFreqMinimumShouldMatch); return query; }
@Override public BytesRef toBytesRef() { BytesRefBuilder builder = new BytesRefBuilder(); builder.grow(length()); BytesRef spare; BytesRefIterator iterator = iterator(); try { while ((spare = iterator.next()) != null) { builder.append(spare); } } catch (IOException ex) { throw new AssertionError("won't happen", ex); // this is really an error since we don't do IO in our bytesreferences } return builder.toBytesRef(); }
builder.add(Util.toUTF32(input, scratchIntsRef), scratch.toBytesRef());
/** Constructs a Term with the given field and the bytes from a builder. * <p>Note that a null field value results in undefined * behavior for most Lucene APIs that accept a Term parameter. */ public Term(String fld, BytesRefBuilder bytesBuilder) { field = fld; this.bytes = bytesBuilder.toBytesRef(); }
@Override public BytesRef get(int index) { /** * We need to make a copy here because {@link BinaryScriptDocValues} might reuse the * returned value and the same instance might be used to * return values from multiple documents. **/ return values[index].toBytesRef(); }
/** Constructs a Term with the given field and the bytes from a builder. * <p>Note that a null field value results in undefined * behavior for most Lucene APIs that accept a Term parameter. */ public Term(String fld, BytesRefBuilder bytesBuilder) { field = fld; this.bytes = bytesBuilder.toBytesRef(); }
BytesRefBuilder bytes = new BytesRefBuilder(); NumericUtils.longToPrefixCoded(item.getISBN(), 0, bytes); Term term = new Term(Book.ID, bytes.toBytesRef()); writer.deleteDocuments(term);
private Query query(Long value) { if (docValues) { return new DocValuesNumbersQuery(field, docValue(value)); } else { BytesRefBuilder ref = new BytesRefBuilder(); NumericUtils.longToPrefixCoded(value, 0, ref); return new TermQuery(new Term(field, ref.toBytesRef())); } }
private Query query(Integer value) { if (docValues) { return new DocValuesNumbersQuery(field, docValue(value)); } else { BytesRefBuilder ref = new BytesRefBuilder(); NumericUtils.intToPrefixCoded(value, 0, ref); return new TermQuery(new Term(field, ref.toBytesRef())); } }
@Override public BytesRef next() { BytesRefBuilder b = new BytesRefBuilder(); NumericUtils.intToPrefixCoded((int) values.valueAt(this.count++), 0, b); return b.toBytesRef(); }
@Override public BytesRef next() { BytesRefBuilder b = new BytesRefBuilder(); NumericUtils.longToPrefixCoded((int) values.valueAt(this.count++), 0, b); return b.toBytesRef(); }
public UidIndexFieldData(Index index, String type, IndexFieldData<?> idFieldData) { this.index = index; BytesRefBuilder prefix = new BytesRefBuilder(); prefix.append(new BytesRef(type)); prefix.append((byte) '#'); this.prefix = prefix.toBytesRef(); this.idFieldData = idFieldData; }
public UidIndexFieldData(Index index, String type, IndexFieldData<?> idFieldData) { this.index = index; BytesRefBuilder prefix = new BytesRefBuilder(); prefix.append(new BytesRef(type)); prefix.append((byte) '#'); this.prefix = prefix.toBytesRef(); this.idFieldData = idFieldData; }
public UidIndexFieldData(Index index, String type, IndexOrdinalsFieldData idFieldData) { this.index = index; this.type = type; BytesRefBuilder prefix = new BytesRefBuilder(); prefix.append(new BytesRef(type)); prefix.append((byte) '#'); this.prefix = prefix.toBytesRef(); this.idFieldData = idFieldData; }
public void testIterator() throws IOException { int length = randomIntBetween(10, PAGE_SIZE * randomIntBetween(2, 8)); BytesReference pbr = newBytesReference(length); BytesRefIterator iterator = pbr.iterator(); BytesRef ref; BytesRefBuilder builder = new BytesRefBuilder(); while((ref = iterator.next()) != null) { builder.append(ref); } assertArrayEquals(BytesReference.toBytes(pbr), BytesRef.deepCopyOf(builder.toBytesRef()).bytes); }