protected SenseiFilter doConstructFilter(Object json) throws Exception {
final String fieldName = json instanceof String ? (String) json : ((JSONObject) json).getString("field");
return new SenseiFilter() {
@Override
public SenseiDocIdSet getSenseiDocIdSet(IndexReader reader) throws IOException {
BoboIndexReader boboReader = (BoboIndexReader) reader;
FacetHandler facetHandler = boboReader.getFacetHandler(fieldName);
Object facetData = facetHandler.getFacetData(boboReader);
String plan = EMPTY_STRING;
if(facetData instanceof MultiValueFacetDataCache)
{
final MultiValueFacetDataCache facetDataCache = (MultiValueFacetDataCache) facetData;
DocIdSet docIdSet = new DocIdSet() {
@Override
public DocIdSetIterator iterator() throws IOException {
return new MultiValueFacetDocIdSetIterator(facetDataCache, 0);
}
};
if(log.isDebugEnabled()) {
plan = fieldName + " IS MULTIVALUE NULL";
}
return new SenseiDocIdSet(docIdSet, DocIdSetCardinality.exact(facetDataCache.freqs[0], boboReader.maxDoc() + 1), plan);
}
else if (facetData instanceof FacetDataCache)
{
final FacetDataCache facetDataCache = (FacetDataCache) facetData;
DocIdSet docIdSet = new DocIdSet() {
@Override
public DocIdSetIterator iterator() throws IOException {
return new FacetFilter.FacetDocIdSetIterator(facetDataCache, 0);
}
};
if(log.isDebugEnabled()) {
plan = fieldName + " IS NULL";
}
return new SenseiDocIdSet(docIdSet, DocIdSetCardinality.exact(facetDataCache.freqs[0], boboReader.maxDoc() + 1), plan);
}
throw new UnsupportedOperationException("The null filter is supported only for the bobo facetHandlers that use FacetDataCache");
}
};
}