All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.browseengine.bobo.client.BrowseResultFormatter Maven / Gradle / Ivy

Go to download

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;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy