I'm writing a Content Navigator response filter that will format two fields in a search result:
A date field
EXAMPLE: 2018-04-03T00:00:00 -> 04-03-2018
The content size field:
EXAMPLE: 14859 -> 14.5 kB
The "date" field was no problem - it worked fine.
The "content size" field isn't working. No errors or warnings - ICN just isn't displaying the formatted value.
The problem might be that ICN declares 'contentSize' to be xs:long
... and a "long" column can't contain letters like "kB", or punctuation like "."
Here's my code:
private void filterSearch(JSONResultSetResponse jsonResultSetResponse) throws Exception {
// For each document returned by the search...
for (int i = 0; i < jsonResultSetResponse.getRowCount(); i++) {
JSONResultSetRow row = jsonResultSetResponse.getRow(i);
...
// contentSize
Long size = Long.parseLong((String)currentValue);
final String[] units = new String[] { "", "kB", "MB", "GB", "TB" };
int digitGroups = (int) (Math.log10(size)/Math.log10(1024));
String formattedSize = new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups)) + " " + units[digitGroups];
// EXAMPLE: change 14859 -> 14.5 kB
row.setAttributeType(symName, "xs:string");
row.setAttributeValue(symName, formattedSize);
...
Q: Any ideas how I can correctly format a "long" value in Content Navigator search results?
Use this, set format as "fileSize".