Skip to content

Commit

Permalink
unit test on histo facet handler
Browse files Browse the repository at this point in the history
  • Loading branch information
John Wang committed Jan 7, 2011
1 parent 38564a3 commit b9a2b45
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
Expand Up @@ -107,7 +107,7 @@ public FacetCountCollector getFacetCountCollector(BoboIndexReader reader, int do
{
FacetDataCache<?> dataCache = (FacetDataCache<?>)reader.getFacetData(_dataHandlerName);
FacetCountCollector baseCollector = baseCollectorSrc.getFacetCountCollector(reader, docBase);
return new HistogramCollector<T>(baseCollector, dataCache, ospec, _start, _end, _unit);
return new HistogramCollector<T>(getName(),baseCollector, dataCache, ospec, _start, _end, _unit);
}
};
}
Expand All @@ -122,11 +122,13 @@ public static class HistogramCollector<T extends Number> implements FacetCountCo
private final int[] _count;
private final TermValueList<?> _valArray;
private final FacetCountCollector _baseCollector;
private final String _facetName;

private boolean _isAggregated;

protected HistogramCollector(FacetCountCollector baseCollector, FacetDataCache<?> dataCache, FacetSpec ospec, T start, T end, T unit)
protected HistogramCollector(String facetName,FacetCountCollector baseCollector, FacetDataCache<?> dataCache, FacetSpec ospec, T start, T end, T unit)
{
_facetName = facetName;
_baseCollector = baseCollector;
_valArray = dataCache.valArray;
_ospec = ospec;
Expand Down Expand Up @@ -284,15 +286,16 @@ public List<BrowseFacet> getFacets()

public FacetIterator iterator()
{
if(!_isAggregated) aggregate();
return new HistogramFacetIterator(_count, _formatter);
}

public String getName()
{
return null;
return _facetName;
}

public void close()
public void close()
{
}
}
Expand Down
48 changes: 45 additions & 3 deletions test/src/com/browseengine/bobo/test/BoboTestCase.java
Expand Up @@ -98,6 +98,7 @@
import com.browseengine.bobo.facets.impl.FacetValueComparatorFactory;
import com.browseengine.bobo.facets.impl.FilteredRangeFacetHandler;
import com.browseengine.bobo.facets.impl.GeoFacetHandler;
import com.browseengine.bobo.facets.impl.HistogramFacetHandler;
import com.browseengine.bobo.facets.impl.MultiValueFacetHandler;
import com.browseengine.bobo.facets.impl.PathFacetHandler;
import com.browseengine.bobo.facets.impl.RangeFacetHandler;
Expand Down Expand Up @@ -501,6 +502,14 @@ public static List<FacetHandler<?>> buildFieldConf(){
predefinedBuckets[3] = new String("[10000 TO *]");
facetHandlers.add(new BucketFacetHandler("salaryBucket", Arrays.asList(predefinedBuckets), "salary"));

// histogram

SimpleFacetHandler dateNumHandler = new SimpleFacetHandler("datenum","date", new PredefinedTermListFactory(Date.class, "yyyy/MM/dd"));

HistogramFacetHandler<Long> histoHandler = new HistogramFacetHandler<Long>("datehisto", "datenum", new Long(0), new Long(100), new Long(10));

facetHandlers.add(dateNumHandler);
facetHandlers.add(histoHandler);

LinkedHashSet<String> dependsNames=new LinkedHashSet<String>();
dependsNames.add("color");
Expand Down Expand Up @@ -2289,6 +2298,40 @@ public void testTime() throws Exception
assertEquals("",23,result.getNumHits());
}

public void testHistogramFacetHandler() throws Exception{
BrowseRequest br=new BrowseRequest();
br.setCount(0);
br.setOffset(0);

FacetSpec output=new FacetSpec();
output.setMaxCount(100);
br.setFacetSpec("datehisto", output);

BrowseResult result = null;
Browsable boboBrowser = null;
try {
boboBrowser=newBrowser();
result = boboBrowser.browse(br);
System.out.println(result);
} catch (BrowseException e) {
e.printStackTrace();
fail(e.getMessage());
}
catch(IOException ioe){
fail(ioe.getMessage());
}
finally{
if (boboBrowser!=null){
try {
if (result!=null)result.close();
boboBrowser.close();
} catch (IOException e) {
fail(e.getMessage());
}
}
}
}

public void testBucketFacetHandlerDependingOnRangeHandler() throws Exception{
BrowseRequest br=new BrowseRequest();
br.setCount(10);
Expand Down Expand Up @@ -2324,10 +2367,9 @@ public void testBucketFacetHandlerDependingOnRangeHandler() throws Exception{

public static void main(String[] args)throws Exception {
//BoboTestCase test=new BoboTestCase("testSimpleGroupbyFacetHandler");
BoboTestCase test=new BoboTestCase("testBucketFacetHandlerDependingOnRangeHandler");
BoboTestCase test=new BoboTestCase("testHistogramFacetHandler");
test.setUp();
test.testBucketFacetHandlerDependingOnRangeHandler();
//test.testSimpleGroupbyFacetHandler();
test.testHistogramFacetHandler();
test.tearDown();
}
}

0 comments on commit b9a2b45

Please sign in to comment.