本文整理匯總了Java中org.apache.lucene.util.BytesRef類的典型用法代碼示例。如果您正苦於以下問題:Java BytesRef類的具體用法?Java BytesRef怎麽用?Java BytesRef使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BytesRef類屬於org.apache.lucene.util包,在下文中一共展示了BytesRef類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getRandomizedBytesReference
import org.apache.lucene.util.BytesRef; //導入依賴的package包/類
private BytesReference getRandomizedBytesReference(int length) throws IOException {
// we know bytes stream output always creates a paged bytes reference, we use it to create randomized content
ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(length, bigarrays);
for (int i = 0; i < length; i++) {
out.writeByte((byte) random().nextInt(1 << 8));
}
assertEquals(out.size(), length);
BytesReference ref = out.bytes();
assertEquals(ref.length(), length);
if (randomBoolean()) {
return new BytesArray(ref.toBytesRef());
} else if (randomBoolean()) {
BytesRef bytesRef = ref.toBytesRef();
return Netty4Utils.toBytesReference(Unpooled.wrappedBuffer(bytesRef.bytes, bytesRef.offset,
bytesRef.length));
} else {
return ref;
}
}
示例2: testIteratorRandom
import org.apache.lucene.util.BytesRef; //導入依賴的package包/類
public void testIteratorRandom() throws IOException {
int length = randomIntBetween(10, PAGE_SIZE * randomIntBetween(2, 8));
BytesReference pbr = newBytesReference(length);
if (randomBoolean()) {
int sliceOffset = randomIntBetween(0, pbr.length());
int sliceLength = randomIntBetween(0, pbr.length() - sliceOffset);
pbr = pbr.slice(sliceOffset, sliceLength);
}
if (randomBoolean()) {
pbr = new BytesArray(pbr.toBytesRef());
}
BytesRefIterator iterator = pbr.iterator();
BytesRef ref = null;
BytesRefBuilder builder = new BytesRefBuilder();
while((ref = iterator.next()) != null) {
builder.append(ref);
}
assertArrayEquals(BytesReference.toBytes(pbr), BytesRef.deepCopyOf(builder.toBytesRef()).bytes);
}
示例3: lookupTerm
import org.apache.lucene.util.BytesRef; //導入依賴的package包/類
@Override
public long lookupTerm(BytesRef key) {
try {
switch (te.seekCeil(key)) {
case FOUND:
assert te.ord() >= 0;
return te.ord();
case NOT_FOUND:
assert te.ord() >= 0;
return -te.ord()-1;
default: /* END */
return -numTerms()-1;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例4: toPartitionName
import org.apache.lucene.util.BytesRef; //導入依賴的package包/類
public static PartitionName toPartitionName(TableIdent tableIdent,
@Nullable DocTableInfo docTableInfo,
List<Assignment> partitionProperties,
Object[] parameters) {
if (docTableInfo != null) {
return toPartitionName(docTableInfo, partitionProperties, parameters);
}
// Because only TableIdent is available, types of partitioned columns must be guessed
Map<ColumnIdent, Object> properties = assignmentsToMap(partitionProperties, parameters);
BytesRef[] values = new BytesRef[properties.size()];
int idx = 0;
for (Object o : properties.values()) {
values[idx++] = DataTypes.STRING.value(o);
}
return new PartitionName(tableIdent, Arrays.asList(values));
}
示例5: testSortMetaField
import org.apache.lucene.util.BytesRef; //導入依賴的package包/類
public void testSortMetaField() throws Exception {
createIndex("test");
ensureGreen();
final int numDocs = randomIntBetween(10, 20);
IndexRequestBuilder[] indexReqs = new IndexRequestBuilder[numDocs];
for (int i = 0; i < numDocs; ++i) {
indexReqs[i] = client().prepareIndex("test", "type", Integer.toString(i))
.setSource();
}
indexRandom(true, indexReqs);
SortOrder order = randomFrom(SortOrder.values());
SearchResponse searchResponse = client().prepareSearch()
.setQuery(matchAllQuery())
.setSize(randomIntBetween(1, numDocs + 5))
.addSort("_uid", order)
.execute().actionGet();
assertNoFailures(searchResponse);
SearchHit[] hits = searchResponse.getHits().getHits();
BytesRef previous = order == SortOrder.ASC ? new BytesRef() : UnicodeUtil.BIG_TERM;
for (int i = 0; i < hits.length; ++i) {
final BytesRef uid = new BytesRef(Uid.createUid(hits[i].getType(), hits[i].getId()));
assertThat(previous, order == SortOrder.ASC ? lessThan(uid) : greaterThan(uid));
previous = uid;
}
}
示例6: splitUidIntoTypeAndId
import org.apache.lucene.util.BytesRef; //導入依賴的package包/類
public static BytesRef[] splitUidIntoTypeAndId(BytesRef uid) {
int loc = -1;
final int limit = uid.offset + uid.length;
for (int i = uid.offset; i < limit; i++) {
if (uid.bytes[i] == Uid.DELIMITER_BYTE) { // 0x23 is equal to '#'
loc = i;
break;
}
}
if (loc == -1) {
return null;
}
int idStart = loc + 1;
return new BytesRef[] {
new BytesRef(uid.bytes, uid.offset, loc - uid.offset),
new BytesRef(uid.bytes, idStart, limit - idStart)
};
}
示例7: getRangeQuerySingle
import org.apache.lucene.util.BytesRef; //導入依賴的package包/類
private Query getRangeQuerySingle(String field, String part1, String part2,
boolean startInclusive, boolean endInclusive, QueryShardContext context) {
currentFieldType = context.fieldMapper(field);
if (currentFieldType != null) {
try {
BytesRef part1Binary = part1 == null ? null : getAnalyzer().normalize(field, part1);
BytesRef part2Binary = part2 == null ? null : getAnalyzer().normalize(field, part2);
Query rangeQuery;
if (currentFieldType instanceof DateFieldMapper.DateFieldType && settings.timeZone() != null) {
DateFieldMapper.DateFieldType dateFieldType = (DateFieldMapper.DateFieldType) this.currentFieldType;
rangeQuery = dateFieldType.rangeQuery(part1Binary, part2Binary,
startInclusive, endInclusive, settings.timeZone(), null, context);
} else {
rangeQuery = currentFieldType.rangeQuery(part1Binary, part2Binary, startInclusive, endInclusive, context);
}
return rangeQuery;
} catch (RuntimeException e) {
if (settings.lenient()) {
return null;
}
throw e;
}
}
return newRangeQuery(field, part1, part2, startInclusive, endInclusive);
}
示例8: getVariableBinary
import org.apache.lucene.util.BytesRef; //導入依賴的package包/類
private BinaryDocValues getVariableBinary(FieldInfo field, final BinaryEntry bytes) throws IOException {
final IndexInput data = this.data.clone();
final MonotonicBlockPackedReader addresses = getAddressInstance(data, field, bytes);
return new LongBinaryDocValues() {
final BytesRef term = new BytesRef(Math.max(0, bytes.maxLength));
@Override
public BytesRef get(long id) {
long startAddress = bytes.offset + (id == 0 ? 0 : addresses.get(id-1));
long endAddress = bytes.offset + addresses.get(id);
int length = (int) (endAddress - startAddress);
try {
data.seek(startAddress);
data.readBytes(term.bytes, 0, length);
term.length = length;
return term;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
}
示例9: indexedValueForSearch
import org.apache.lucene.util.BytesRef; //導入依賴的package包/類
@Override
public BytesRef indexedValueForSearch(Object value) {
if (value == null) {
return Values.FALSE;
}
if (value instanceof Boolean) {
return ((Boolean) value) ? Values.TRUE : Values.FALSE;
}
String sValue;
if (value instanceof BytesRef) {
sValue = ((BytesRef) value).utf8ToString();
} else {
sValue = value.toString();
}
if (sValue.length() == 0) {
return Values.FALSE;
}
if (sValue.length() == 1 && sValue.charAt(0) == 'F') {
return Values.FALSE;
}
if (Booleans.parseBoolean(sValue, false)) {
return Values.TRUE;
}
return Values.FALSE;
}
示例10: getFilter
import org.apache.lucene.util.BytesRef; //導入依賴的package包/類
@Override
public Filter getFilter(Element e) throws ParserException {
List<BytesRef> terms = new ArrayList<>();
String text = DOMUtils.getNonBlankTextOrFail(e);
String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
TokenStream ts = null;
try {
ts = analyzer.tokenStream(fieldName, text);
TermToBytesRefAttribute termAtt = ts.addAttribute(TermToBytesRefAttribute.class);
BytesRef bytes = termAtt.getBytesRef();
ts.reset();
while (ts.incrementToken()) {
termAtt.fillBytesRef();
terms.add(BytesRef.deepCopyOf(bytes));
}
ts.end();
}
catch (IOException ioe) {
throw new RuntimeException("Error constructing terms from index:" + ioe);
} finally {
IOUtils.closeWhileHandlingException(ts);
}
return new TermsFilter(fieldName, terms);
}
示例11: appendRandomData
import org.apache.lucene.util.BytesRef; //導入依賴的package包/類
private void appendRandomData(IndexOutput output) throws IOException {
int numBytes = randomIntBetween(1, 1024);
final BytesRef ref = new BytesRef(scaledRandomIntBetween(1, numBytes));
ref.length = ref.bytes.length;
while (numBytes > 0) {
if (random().nextInt(10) == 0) {
output.writeByte(randomByte());
numBytes--;
} else {
for (int i = 0; i<ref.length; i++) {
ref.bytes[i] = randomByte();
}
final int min = Math.min(numBytes, ref.bytes.length);
output.writeBytes(ref.bytes, ref.offset, min);
numBytes -= min;
}
}
}
示例12: payload
import org.apache.lucene.util.BytesRef; //導入依賴的package包/類
/**
* 將Product對象序列化存入payload
* [這裏僅僅是個示例,其實這種做法不可取,一般不會把整個對象存入payload,這樣索引體積會很大,浪費硬盤空間]
*/
@Override
public BytesRef payload() {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(currentProduct);
out.close();
return new BytesRef(bos.toByteArray());
} catch (IOException e) {
throw new RuntimeException("Well that's unfortunate.");
}
}
示例13: getComparableBytes
import org.apache.lucene.util.BytesRef; //導入依賴的package包/類
/**
* Given a document and a term, return the term itself if it exists or
* <tt>null</tt> otherwise.
*/
private BytesRef getComparableBytes(int doc, BytesRef term) {
if (term.length == 0 && isNull(doc, term)) {
return null;
}
return term;
}
示例14: ClusterLoggingOverridesChildExpression
import org.apache.lucene.util.BytesRef; //導入依賴的package包/類
protected ClusterLoggingOverridesChildExpression(final Map.Entry<String, String> setting) {
childImplementations.put(NAME, new SimpleObjectExpression<BytesRef>() {
@Override
public BytesRef value() {
return new BytesRef(setting.getKey());
}
});
childImplementations.put(LEVEL, new SimpleObjectExpression<BytesRef>() {
@Override
public BytesRef value() {
return new BytesRef(setting.getValue().toUpperCase(Locale.ENGLISH));
}
});
}
示例15: evaluate
import org.apache.lucene.util.BytesRef; //導入依賴的package包/類
private static BytesRef evaluate(@Nonnull BytesRef inputStr, int beginIdx, int len) {
final int startPos = Math.max(0, beginIdx - 1);
if (startPos > inputStr.length - 1) {
return EMPTY_BYTES_REF;
}
int endPos = inputStr.length;
if (startPos + len < endPos) {
endPos = startPos + len;
}
return substring(inputStr, startPos, endPos);
}