Set<String> fields = getFacetNames();
LinkedList<Filter> preFilterList = new LinkedList<Filter>();
List<FacetHitCollector> facetHitCollectorList = new LinkedList<FacetHitCollector>();
Filter baseFilter = req.getFilter();
if (baseFilter != null)
{
preFilterList.add(baseFilter);
}
int selCount = req.getSelectionCount();
boolean isNoQueryNoFilter = isNoQueryNoFilter(req);
boolean isDefaultSearch = isNoQueryNoFilter && selCount == 0;
try
{
for (String name : fields)
{
BrowseSelection sel = req.getSelection(name);
FacetSpec ospec = req.getFacetSpec(name);
FacetHandler<?> handler = getFacetHandler(name);
if (handler == null){
logger.error("facet handler: "+name+" is not defined, ignored.");
continue;
}
FacetHitCollector facetHitCollector = null;
RandomAccessFilter filter = null;
if (sel != null)
{
filter = handler.buildFilter(sel);
}
if (ospec == null)
{
if (filter != null)
{
preFilterList.add(filter);
}
}
else
{
/*FacetSpec fspec = new FacetSpec(); // OrderValueAsc,
fspec.setMaxCount(0);
fspec.setMinHitCount(1);
fspec.setExpandSelection(ospec.isExpandSelection());*/
FacetSpec fspec = ospec;
facetHitCollector = new FacetHitCollector();
facetHitCollector.facetHandler = handler;
if (isDefaultSearch)
{
facetHitCollector._collectAllSource=handler.getFacetCountCollectorSource(sel, fspec);
}
else
{
facetHitCollector._facetCountCollectorSource = handler.getFacetCountCollectorSource(sel, fspec);
if (ospec.isExpandSelection())
{
if (isNoQueryNoFilter && sel!=null && selCount == 1)
{
facetHitCollector._collectAllSource=handler.getFacetCountCollectorSource(sel, fspec);
if (filter != null)
{
preFilterList.add(filter);
}
}
else
{
if (filter != null)
{
facetHitCollector._filter = filter;
}
}
}
else
{
if (filter != null)
{
preFilterList.add(filter);
}
}
}
}
if (facetHitCollector != null)
{
facetHitCollectorList.add(facetHitCollector);
}
}
Filter finalFilter = null;
if (preFilterList.size() > 0)
{
if (preFilterList.size() == 1)
{
finalFilter = preFilterList.getFirst();