com.browseengine.bobo.client.BrowseResultFormatter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bobo-browse Show documentation
Show all versions of bobo-browse Show documentation
Bobo is a Faceted Search implementation written purely in Java, an extension of Apache Lucene
The newest version!
package com.browseengine.bobo.client;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.browseengine.bobo.api.BrowseFacet;
import com.browseengine.bobo.api.BrowseHit;
import com.browseengine.bobo.api.BrowseResult;
import com.browseengine.bobo.api.FacetAccessible;
public class BrowseResultFormatter {
static String formatResults(BrowseResult res) {
StringBuffer sb = new StringBuffer();
sb.append(res.getNumHits());
sb.append(" hits out of ");
sb.append(res.getTotalDocs());
sb.append(" docs\n");
BrowseHit[] hits = res.getHits();
Map map = res.getFacetMap();
Set keys = map.keySet();
for (String key : keys) {
FacetAccessible fa = map.get(key);
sb.append(key + "\n");
List lf = fa.getFacets();
for (BrowseFacet bf : lf) {
sb.append("\t" + bf + "\n");
}
}
for (BrowseHit hit : hits) {
sb.append("------------\n");
sb.append(formatHit(hit));
sb.append("\n");
}
sb.append("*****************************\n");
return sb.toString();
}
static StringBuffer formatHit(BrowseHit hit) {
StringBuffer sb = new StringBuffer();
Map fields = hit.getFieldValues();
Set keys = fields.keySet();
for (String key : keys) {
sb.append("\t" + key + " :");
String[] values = fields.get(key);
for (String value : values) {
sb.append(" " + value);
}
sb.append("\n");
}
return sb;
}
}