Java Code Examples for org.apache.lucene.util.BytesRef#toString()

The following examples show how to use org.apache.lucene.util.BytesRef#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BytesRefUtils.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static String decode(BytesRef ref) {
  try {
    return ref.utf8ToString();
  } catch (Exception e) {
    return ref.toString();
  }
}
 
Example 2
Source File: OrdsSegmentTermsEnum.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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();
  }
}
 
Example 3
Source File: OrdsBlockTreeTermsWriter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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();
  }
}
 
Example 4
Source File: OrdsBlockTreeTermsReader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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();
    }
  }
}
 
Example 5
Source File: IDVersionSegmentTermsEnum.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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();
  }
}
 
Example 6
Source File: VersionBlockTreeTermsReader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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();
    }
  }
}
 
Example 7
Source File: VersionBlockTreeTermsWriter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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();
  }
}
 
Example 8
Source File: BlockTreeTermsWriter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
static 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();
    }
  }
}
 
Example 9
Source File: BlockTreeTermsReader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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();
    }
  }
}
 
Example 10
Source File: IntersectTermsEnum.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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();
  }
}
 
Example 11
Source File: Term.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** Returns human-readable form of the term text. If the term is not unicode,
 * the raw bytes will be printed instead. */
public static final String toString(BytesRef termText) {
  // the term might not be text, but usually is. so we make a best effort
  CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder()
      .onMalformedInput(CodingErrorAction.REPORT)
      .onUnmappableCharacter(CodingErrorAction.REPORT);
  try {
    return decoder.decode(ByteBuffer.wrap(termText.bytes, termText.offset, termText.length)).toString();
  } catch (CharacterCodingException e) {
    return termText.toString();
  }
}
 
Example 12
Source File: BlockTreeTermsReader.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
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();
    }
  }
}
 
Example 13
Source File: ByteSequenceOutputs.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public String outputToString(BytesRef output) {
  return output.toString();
}
 
Example 14
Source File: BytesRefPrinter.java    From clue with Apache License 2.0 4 votes vote down vote up
@Override
public String print(BytesRef bytesRef) {
  return bytesRef.toString();
}