private void BuildCategoryDetails(
            org.apache.lucene.facet.Facets facets, IList<CategoryDetail> categoryDetails, CategoryOptions categoryOptions, 
            string categoryName, string[] label, int count, IEnumerable<string> drillDownValues)
        {
            var lastLabel = label.Last();
            if (!drillDownValues.Contains(lastLabel))
            {
                categoryDetails.Add(new CategoryDetail { Value = lastLabel, Count = count });
//logger.Info("Value = {2} -- {0}; Count = {1}", lastLabel, count, String.Join("_ ", label));
            }
            else
            {
                var drilldownFacets = facets.getTopChildren(categoryOptions.MaxPerCategory, categoryName, label);
                if (drilldownFacets != null)
                {
                    var valDetail = new CategoryDetail { Value = lastLabel, Count = count };
                    categoryDetails.Add(valDetail);
                    foreach (var lv in drilldownFacets.labelValues)
                    {
                        var childLabel = new List<string>(label);
                        childLabel.Add(lv.label);
                        BuildCategoryDetails(
                            facets, valDetail.Children, categoryOptions, 
                            categoryName, childLabel.ToArray(), lv.value.intValue(), 
                            drillDownValues);
                    }
                }
            }
        }
        private IList<Category> RetrieveDrilldown(org.apache.lucene.facet.Facets facets, CategoryOptions categoryOptions)
        {
            var results = new List<Category>();

            foreach (var name in categoryOptions.FacetNames)
            {
                if (Facets.IsHierarchical(name))
                {
                    var topCategory = new Category { Field = name, IsHierarchical = true };
                    results.Add(topCategory);

                    var directChildFacets = facets.getTopChildren(categoryOptions.MaxPerCategory, name);
                    if (directChildFacets != null)
                    {
                        IEnumerable<string> drillDownValues = categoryOptions.GetCategoryValues(name);
                        foreach (var labelValue in directChildFacets.labelValues)
                        {
                            var labelName = new string[] { labelValue.label };
                            BuildCategoryDetails(
                                facets, topCategory.Details, categoryOptions, 
                                name, labelName, labelValue.value.intValue(), 
                                drillDownValues);
                        }
                    }
                }
                else
                {
                    var fp = facets.getTopChildren(categoryOptions.MaxPerCategory, name);
                    if (fp != null)
                    {
                        var list = new List<CategoryDetail>(fp.labelValues.Length);
                        foreach (var lv in fp.labelValues)
                        {
                            list.Add(new CategoryDetail { Value = lv.label, Count = lv.value.intValue() });
                        }
                        results.Add(new Category { Field = name, Details = list });
                    }
                }
            }
            return results;
        }