本文整理匯總了Java中org.apache.lucene.util.BytesRef.utf8ToString方法的典型用法代碼示例。如果您正苦於以下問題:Java BytesRef.utf8ToString方法的具體用法?Java BytesRef.utf8ToString怎麽用?Java BytesRef.utf8ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.lucene.util.BytesRef
的用法示例。
在下文中一共展示了BytesRef.utf8ToString方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doEvaluate
import org.apache.lucene.util.BytesRef; //導入方法依賴的package包/類
@Override
protected Boolean doEvaluate(Object left, Iterable<?> rightIterable) {
BytesRef rightBytesRef = (BytesRef) left;
String pattern = rightBytesRef.utf8ToString();
boolean hasNull = false;
for (Object elem : rightIterable) {
if (elem == null) {
hasNull = true;
continue;
}
assert (elem instanceof BytesRef || elem instanceof String);
String elemValue;
if (elem instanceof BytesRef) {
elemValue = ((BytesRef) elem).utf8ToString();
} else {
elemValue = (String)elem;
}
if (matches(elemValue, pattern)) {
return true;
}
}
return hasNull ? null : false;
}
示例2: getParentId
import org.apache.lucene.util.BytesRef; //導入方法依賴的package包/類
public static String getParentId(ParentFieldMapper fieldMapper, LeafReader reader, int docId) {
try {
SortedDocValues docValues = reader.getSortedDocValues(fieldMapper.name());
if (docValues == null) {
// hit has no _parent field.
return null;
}
BytesRef parentId = docValues.get(docId);
return parentId.length > 0 ? parentId.utf8ToString() : null;
} catch (IOException e) {
throw ExceptionsHelper.convertToElastic(e);
}
}
示例3: getValue
import org.apache.lucene.util.BytesRef; //導入方法依賴的package包/類
public String getValue() {
BytesRef value = getBytesValue();
if (value == null) {
return null;
} else {
return value.utf8ToString();
}
}
示例4: valueForDisplay
import org.apache.lucene.util.BytesRef; //導入方法依賴的package包/類
@Override
public Object valueForDisplay(Object value) {
if (value == null) {
return null;
}
// keywords are internally stored as utf8 bytes
BytesRef binaryValue = (BytesRef) value;
return binaryValue.utf8ToString();
}
示例5: createString
import org.apache.lucene.util.BytesRef; //導入方法依賴的package包/類
private String createString(String[] tokens, Map<String, List<BytesRef>> payloads, int encoding, char delimiter) {
String resultString = "";
ObjectIntHashMap<String> payloadCounter = new ObjectIntHashMap<>();
for (String token : tokens) {
if (!payloadCounter.containsKey(token)) {
payloadCounter.putIfAbsent(token, 0);
} else {
payloadCounter.put(token, payloadCounter.get(token) + 1);
}
resultString = resultString + token;
BytesRef payload = payloads.get(token).get(payloadCounter.get(token));
if (payload.length > 0) {
resultString = resultString + delimiter;
switch (encoding) {
case 0: {
resultString = resultString + Float.toString(PayloadHelper.decodeFloat(payload.bytes, payload.offset));
break;
}
case 1: {
resultString = resultString + Integer.toString(PayloadHelper.decodeInt(payload.bytes, payload.offset));
break;
}
case 2: {
resultString = resultString + payload.utf8ToString();
break;
}
default: {
throw new ElasticsearchException("unsupported encoding type");
}
}
}
resultString = resultString + " ";
}
return resultString;
}
示例6: compareTermVectors
import org.apache.lucene.util.BytesRef; //導入方法依賴的package包/類
private void compareTermVectors(String fieldName, Fields fields0, Fields fields1) throws IOException {
Terms terms0 = fields0.terms(fieldName);
Terms terms1 = fields1.terms(fieldName);
assertThat(terms0, notNullValue());
assertThat(terms1, notNullValue());
assertThat(terms0.size(), equalTo(terms1.size()));
TermsEnum iter0 = terms0.iterator();
TermsEnum iter1 = terms1.iterator();
for (int i = 0; i < terms0.size(); i++) {
BytesRef next0 = iter0.next();
assertThat(next0, notNullValue());
BytesRef next1 = iter1.next();
assertThat(next1, notNullValue());
// compare field value
String string0 = next0.utf8ToString();
String string1 = next1.utf8ToString();
assertThat("expected: " + string0, string0, equalTo(string1));
// compare df and ttf
assertThat("term: " + string0, iter0.docFreq(), equalTo(iter1.docFreq()));
assertThat("term: " + string0, iter0.totalTermFreq(), equalTo(iter1.totalTermFreq()));
// compare freq and docs
PostingsEnum docsAndPositions0 = iter0.postings(null, PostingsEnum.ALL);
PostingsEnum docsAndPositions1 = iter1.postings(null, PostingsEnum.ALL);
assertThat("term: " + string0, docsAndPositions0.nextDoc(), equalTo(docsAndPositions1.nextDoc()));
assertThat("term: " + string0, docsAndPositions0.freq(), equalTo(docsAndPositions1.freq()));
// compare position, start offsets and end offsets
for (int j = 0; j < docsAndPositions0.freq(); j++) {
assertThat("term: " + string0, docsAndPositions0.nextPosition(), equalTo(docsAndPositions1.nextPosition()));
assertThat("term: " + string0, docsAndPositions0.startOffset(), equalTo(docsAndPositions1.startOffset()));
assertThat("term: " + string0, docsAndPositions0.endOffset(), equalTo(docsAndPositions1.endOffset()));
}
}
assertThat(iter0.next(), nullValue());
assertThat(iter1.next(), nullValue());
}
示例7: brToString
import org.apache.lucene.util.BytesRef; //導入方法依賴的package包/類
@SuppressWarnings("unused")
static String brToString(BytesRef b) {
try {
return b.utf8ToString() + " " + b;
} catch (Throwable t) {
// If BytesRef isn't actually UTF8, or it's eg a
// prefix of UTF8 that ends mid-unicode-char, we
// fallback to hex:
return b.toString();
}
}
示例8: brToString
import org.apache.lucene.util.BytesRef; //導入方法依賴的package包/類
String brToString(BytesRef b) {
if (b == null) {
return "null";
} else {
try {
return b.utf8ToString() + " " + b;
} catch (Throwable t) {
// If BytesRef isn't actually UTF8, or it's eg a
// prefix of UTF8 that ends mid-unicode-char, we
// fallback to hex:
return b.toString();
}
}
}
示例9: visitMatchingTerms
import org.apache.lucene.util.BytesRef; //導入方法依賴的package包/類
@Override
public void visitMatchingTerms(
IndexReader reader,
String fieldName,
MatchingTermVisitor mtv) throws IOException
{
int prefixLength = prefix.length();
Terms terms = MultiFields.getTerms(reader, fieldName);
if (terms != null) {
Matcher matcher = pattern.matcher("");
try {
TermsEnum termsEnum = terms.iterator(null);
TermsEnum.SeekStatus status = termsEnum.seekCeil(prefixRef);
BytesRef text;
if (status == TermsEnum.SeekStatus.FOUND) {
text = prefixRef;
} else if (status == TermsEnum.SeekStatus.NOT_FOUND) {
text = termsEnum.term();
} else {
text = null;
}
while(text != null) {
if (text != null && StringHelper.startsWith(text, prefixRef)) {
String textString = text.utf8ToString();
matcher.reset(textString.substring(prefixLength));
if (matcher.matches()) {
mtv.visitMatchingTerm(new Term(fieldName, textString));
}
} else {
break;
}
text = termsEnum.next();
}
} finally {
matcher.reset();
}
}
}
示例10: parseTimeZone
import org.apache.lucene.util.BytesRef; //導入方法依賴的package包/類
public static DateTimeZone parseTimeZone(BytesRef timezone) throws IllegalArgumentException {
if (timezone == null) {
throw new IllegalArgumentException("invalid time zone value NULL");
}
if (timezone.equals(DEFAULT_TZ_BYTES_REF)) {
return DEFAULT_TZ;
}
DateTimeZone tz = TIME_ZONE_MAP.get(timezone);
if (tz == null) {
try {
String text = timezone.utf8ToString();
int index = text.indexOf(':');
if (index != -1) {
int beginIndex = text.charAt(0) == '+' ? 1 : 0;
// format like -02:30
tz = DateTimeZone.forOffsetHoursMinutes(
Integer.parseInt(text.substring(beginIndex, index)),
Integer.parseInt(text.substring(index + 1))
);
} else {
// id, listed here: http://joda-time.sourceforge.net/timezones.html
// or here: http://www.joda.org/joda-time/timezones.html
tz = DateTimeZone.forID(text);
}
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH,
"invalid time zone value '%s'", timezone.utf8ToString()));
}
TIME_ZONE_MAP.putIfAbsent(timezone, tz);
}
return tz;
}
示例11: setToStringArray
import org.apache.lucene.util.BytesRef; //導入方法依賴的package包/類
private static String[] setToStringArray(Set<BytesRef> values) {
String[] strings = new String[values.size()];
int idx = 0;
for (BytesRef value : values) {
strings[idx] = value == null ? null : value.utf8ToString();
idx++;
}
return strings;
}
示例12: format
import org.apache.lucene.util.BytesRef; //導入方法依賴的package包/類
@Override
public String format(BytesRef value) {
return value.utf8ToString();
}
示例13: validate
import org.apache.lucene.util.BytesRef; //導入方法依賴的package包/類
private void validate(BytesRef ip) {
if(!isValid(ip)) {
throw new IllegalArgumentException("Failed to validate ip [" + ip.utf8ToString() + "], not a valid ipv4 address");
}
}
示例14: createVcfIndexEntry
import org.apache.lucene.util.BytesRef; //導入方法依賴的package包/類
private VcfIndexEntry createVcfIndexEntry(Document d, List<String> vcfInfoFields) {
VcfIndexEntry vcfIndexEntry = new VcfIndexEntry();
vcfIndexEntry.setGene(d.get(FeatureIndexFields.GENE_ID.getFieldName()));
BytesRef bytes = d.getBinaryValue(FeatureIndexFields.GENE_IDS.getFieldName());
if (bytes != null) {
vcfIndexEntry.setGeneIds(bytes.utf8ToString());
}
vcfIndexEntry.setGeneName(d.get(FeatureIndexFields.GENE_NAME.getFieldName()));
bytes = d.getBinaryValue(FeatureIndexFields.GENE_NAMES.getFieldName());
if (bytes != null) {
vcfIndexEntry.setGeneNames(bytes.utf8ToString());
}
vcfIndexEntry.setInfo(new HashMap<>());
String isExonStr = d.get(FeatureIndexFields.IS_EXON.getFieldName()); //TODO: remove, in future only binary
// value will remain
if (isExonStr == null) {
bytes = d.getBinaryValue(FeatureIndexFields.IS_EXON.getFieldName());
if (bytes != null) {
isExonStr = bytes.utf8ToString();
}
}
boolean isExon = isExonStr != null && Boolean.parseBoolean(isExonStr);
vcfIndexEntry.setExon(isExon);
vcfIndexEntry.getInfo().put(FeatureIndexFields.IS_EXON.getFieldName(), isExon);
BytesRef featureIdBytes = d.getBinaryValue(FeatureIndexFields.VARIATION_TYPE.getFieldName());
if (featureIdBytes != null) {
vcfIndexEntry.setVariationType(VariationType.valueOf(featureIdBytes.utf8ToString().toUpperCase()));
}
vcfIndexEntry.setFailedFilter(d.get(FeatureIndexFields.FAILED_FILTER.getFieldName()));
IndexableField qualityField = d.getField(FeatureIndexFields.QUALITY.getFieldName());
if (qualityField != null) {
vcfIndexEntry.setQuality(qualityField.numericValue().doubleValue());
}
if (vcfInfoFields != null) {
for (String infoField : vcfInfoFields) {
if (d.getBinaryValue(infoField.toLowerCase()) != null) {
vcfIndexEntry.getInfo().put(infoField, d.getBinaryValue(infoField.toLowerCase()).utf8ToString());
} else {
vcfIndexEntry.getInfo().put(infoField, d.get(infoField.toLowerCase()));
}
}
}
return vcfIndexEntry;
}