private ICollection <BrowseFacet> GetFacetsForPath(string selectedPath, int depth, bool strict, int minCount, int maxCount)
        {
            List <BrowseFacet> list = new List <BrowseFacet>();

            BoundedPriorityQueue <BrowseFacet> pq = null;

            if (m_comparerFactory != null)
            {
                IComparer <BrowseFacet> comparer = m_comparerFactory.NewComparer();

                pq = new BoundedPriorityQueue <BrowseFacet>(new PathFacetCountCollectorComparer(comparer), maxCount);
            }

            string[] startParts = null;
            int      startDepth = 0;

            if (selectedPath != null && selectedPath.Length > 0)
            {
                startParts = selectedPath.Split(new string[] { m_sep }, StringSplitOptions.RemoveEmptyEntries);
                startDepth = startParts.Length;
                if (!selectedPath.EndsWith(m_sep))
                {
                    selectedPath += m_sep;
                }
            }

            string currentPath  = null;
            int    currentCount = 0;

            int wantedDepth = startDepth + depth;

            int index = 0;

            if (selectedPath != null && selectedPath.Length > 0)
            {
                index = m_dataCache.ValArray.IndexOf(selectedPath);
                if (index < 0)
                {
                    index = -(index + 1);
                }
            }

            StringBuilder buf = new StringBuilder();

            for (int i = index; i < m_count.Length; ++i)
            {
                if (m_count.Get(i) >= minCount)
                {
                    string path = m_dataCache.ValArray.Get(i);
                    //if (path==null || path.equals(selectedPath)) continue;

                    int subCount = m_count.Get(i);

                    // do not use Java split string in a loop !
                    //				string[] pathParts=path.split(_sep);
                    int pathDepth = 0;
                    if (!SplitString(path))
                    {
                        pathDepth = 0;
                    }
                    else
                    {
                        pathDepth = PatListSize();
                    }

                    int tmpdepth = 0;
                    if ((startDepth == 0) || (startDepth > 0 && path.StartsWith(selectedPath)))
                    {
                        buf = new StringBuilder();

                        int minDepth = Math.Min(wantedDepth, pathDepth);
                        tmpdepth = 0;
                        for (int k = m_patStart; ((k < m_patEnd) && (tmpdepth < minDepth)); ++k, tmpdepth++)
                        {
                            buf.Append(m_stringData[k]);
                            if (!m_stringData[k].EndsWith(m_sep))
                            {
                                if (pathDepth != wantedDepth || k < (wantedDepth - 1))
                                {
                                    buf.Append(m_sep);
                                }
                            }
                        }
                        string wantedPath = buf.ToString();
                        if (currentPath == null)
                        {
                            currentPath  = wantedPath;
                            currentCount = subCount;
                        }
                        else if (wantedPath.Equals(currentPath))
                        {
                            if (!strict)
                            {
                                currentCount += subCount;
                            }
                        }
                        else
                        {
                            bool directNode = false;

                            if (wantedPath.EndsWith(m_sep))
                            {
                                if (currentPath.Equals(wantedPath.Substring(0, wantedPath.Length - 1)))
                                {
                                    directNode = true;
                                }
                            }

                            if (strict)
                            {
                                if (directNode)
                                {
                                    currentCount += subCount;
                                }
                                else
                                {
                                    BrowseFacet ch = new BrowseFacet(currentPath, currentCount);
                                    if (pq != null)
                                    {
                                        pq.Add(ch);
                                    }
                                    else
                                    {
                                        if (list.Count < maxCount)
                                        {
                                            list.Add(ch);
                                        }
                                    }
                                    currentPath  = wantedPath;
                                    currentCount = subCount;
                                }
                            }
                            else
                            {
                                if (!directNode)
                                {
                                    BrowseFacet ch = new BrowseFacet(currentPath, currentCount);
                                    if (pq != null)
                                    {
                                        pq.Add(ch);
                                    }
                                    else
                                    {
                                        if (list.Count < maxCount)
                                        {
                                            list.Add(ch);
                                        }
                                    }
                                    currentPath  = wantedPath;
                                    currentCount = subCount;
                                }
                                else
                                {
                                    currentCount += subCount;
                                }
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (currentPath != null && currentCount > 0)
            {
                BrowseFacet ch = new BrowseFacet(currentPath, currentCount);
                if (pq != null)
                {
                    pq.Add(ch);
                }
                else
                {
                    if (list.Count < maxCount)
                    {
                        list.Add(ch);
                    }
                }
            }

            if (pq != null)
            {
                BrowseFacet val;
                while ((val = pq.Poll()) != null)
                {
                    list.Insert(0, val);
                }
            }

            return(list);
        }
        public virtual IEnumerable<BrowseFacet> GetFacets()
        {
            if (_ospec != null)
            {
                string facetPrefix = _ospec.Prefix;
                bool checkPrefix = !string.IsNullOrEmpty(facetPrefix);

                int minCount = _ospec.MinHitCount;
                int max = _ospec.MaxCount;
                if (max <= 0)
                {
                    max = _count.Length;
                }

                ICollection<BrowseFacet> facetColl;
                List<string> valList = _dataCache.valArray.GetInnerList();
                FacetSpec.FacetSortSpec sortspec = _ospec.OrderBy;
                if (sortspec == FacetSpec.FacetSortSpec.OrderValueAsc)
                {
                    facetColl = new List<BrowseFacet>(max);
                    for (int i = 1; i < _count.Length; ++i) // exclude zero
                    {
                        int hits = _count[i];
                        if (!checkPrefix || valList[i].StartsWith(facetPrefix))
                        {
                            if (hits >= minCount)
                            {
                                BrowseFacet facet = new BrowseFacet(valList[i], hits);
                                facetColl.Add(facet);
                            }
                        }
                        if (facetColl.Count >= max)
                            break;
                    }
                }
                else //if (sortspec == FacetSortSpec.OrderHitsDesc)
                {
                    IComparatorFactory comparatorFactory;
                    if (sortspec == FacetSpec.FacetSortSpec.OrderHitsDesc)
                    {
                        comparatorFactory = new FacetHitcountComparatorFactory();
                    }
                    else
                    {
                        comparatorFactory = _ospec.CustomComparatorFactory;
                    }

                    if (comparatorFactory == null)
                    {
                        throw new System.ArgumentException("facet comparator factory not specified");
                    }

                    IComparer<int> comparator = comparatorFactory.NewComparator(new DefaultFacetCountCollectorFieldAccessor(_dataCache), _count);
                    facetColl = new LinkedList<BrowseFacet>();
                    BoundedPriorityQueue<int> pq = new BoundedPriorityQueue<int>(comparator, max);

                    for (int i = 1; i < _count.Length; ++i) // exclude zero
                    {
                        int hits = _count[i];
                        if (hits >= minCount)
                        {
                            if (!checkPrefix || valList[i].StartsWith(facetPrefix))
                            {
                                if (!pq.Offer(i))
                                {
                                    // pq is full. we can safely ignore any facet with <=hits.
                                    minCount = hits + 1;
                                }
                            }
                        }
                    }

                    while (!pq.IsEmpty)
                    {
                        int val = pq.DeleteMax();
                        BrowseFacet facet = new BrowseFacet(valList[val], _count[val]);
                        facetColl.Add(facet);
                    }
                }
                return facetColl;
            }
            else
            {
                return IFacetCountCollector_Fields.EMPTY_FACET_LIST;
            }
        }