Exemple #1
0
        public virtual List <BrowseFacet> GetFacetsNew()
        {
            if (m_ospec != null)
            {
                if (m_predefinedRangeIndexes != null)
                {
                    int minCount       = m_ospec.MinHitCount;
                    int maxNumOfFacets = m_ospec.MaxCount;
                    if (maxNumOfFacets <= 0 || maxNumOfFacets > m_predefinedRangeIndexes.Length)
                    {
                        maxNumOfFacets = m_predefinedRangeIndexes.Length;
                    }

                    BigSegmentedArray rangeCount = new LazyBigInt32Array(m_predefinedRangeIndexes.Length);

                    for (int k = 0; k < m_predefinedRangeIndexes.Length; ++k)
                    {
                        int count = 0;
                        int idx   = m_predefinedRangeIndexes[k][0];
                        int end   = m_predefinedRangeIndexes[k][1];
                        while (idx <= end)
                        {
                            count += m_count.Get(idx++);
                        }
                        rangeCount.Add(k, count);
                    }

                    List <BrowseFacet>      facetColl;
                    FacetSpec.FacetSortSpec sortspec = m_ospec.OrderBy;
                    if (sortspec == FacetSpec.FacetSortSpec.OrderValueAsc)
                    {
                        facetColl = new List <BrowseFacet>(maxNumOfFacets);
                        for (int k = 0; k < m_predefinedRangeIndexes.Length; ++k)
                        {
                            if (rangeCount.Get(k) >= minCount)
                            {
                                BrowseFacet choice = new BrowseFacet(m_predefinedRanges.Get(k), rangeCount.Get(k));
                                facetColl.Add(choice);
                            }
                            if (facetColl.Count >= maxNumOfFacets)
                            {
                                break;
                            }
                        }
                    }
                    else //if (sortspec == FacetSortSpec.OrderHitsDesc)
                    {
                        IComparerFactory comparerFactory;
                        if (sortspec == FacetSpec.FacetSortSpec.OrderHitsDesc)
                        {
                            comparerFactory = new FacetHitcountComparerFactory();
                        }
                        else
                        {
                            comparerFactory = m_ospec.CustomComparerFactory;
                        }

                        if (comparerFactory == null)
                        {
                            throw new ArgumentException("facet comparer factory not specified");
                        }

                        IComparer <int> comparer = comparerFactory.NewComparer(new RangeFacetCountCollectorFieldAccessor(m_predefinedRanges), rangeCount);

                        int forbidden = -1;
                        Int32BoundedPriorityQueue pq = new Int32BoundedPriorityQueue(comparer, maxNumOfFacets, forbidden);
                        for (int i = 0; i < m_predefinedRangeIndexes.Length; ++i)
                        {
                            if (rangeCount.Get(i) >= minCount)
                            {
                                pq.Offer(i);
                            }
                        }

                        int val;
                        facetColl = new List <BrowseFacet>();
                        while ((val = pq.Poll()) != forbidden)
                        {
                            BrowseFacet facet = new BrowseFacet(m_predefinedRanges.ElementAt(val), rangeCount.Get(val));
                            facetColl.Insert(0, facet);
                        }
                    }
                    return(facetColl);
                }
                else
                {
                    return(FacetCountCollector.EMPTY_FACET_LIST);
                }
            }
            else
            {
                return(FacetCountCollector.EMPTY_FACET_LIST);
            }
        }
            public virtual ICollection <BrowseFacet> GetFacets()
            {
                if (m_fspec != null)
                {
                    int minCount = m_fspec.MinHitCount;
                    int max      = m_fspec.MaxCount;
                    if (max <= 0)
                    {
                        max = m_countlength;
                    }

                    FacetSpec.FacetSortSpec sortspec = m_fspec.OrderBy;
                    List <BrowseFacet>      facetColl;
                    if (sortspec == FacetSpec.FacetSortSpec.OrderValueAsc)
                    {
                        facetColl = new List <BrowseFacet>(max);
                        for (int i = 1; i < m_countlength; ++i) // exclude zero
                        {
                            int hits = m_count.Get(i);
                            if (hits >= minCount)
                            {
                                BrowseFacet facet = new BrowseFacet(GetFacetString(i), hits);
                                facetColl.Add(facet);
                            }
                            if (facetColl.Count >= max)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        IComparerFactory comparerFactory;
                        if (sortspec == FacetSpec.FacetSortSpec.OrderHitsDesc)
                        {
                            comparerFactory = new FacetHitcountComparerFactory();
                        }
                        else
                        {
                            comparerFactory = m_fspec.CustomComparerFactory;
                        }

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

                        IComparer <int> comparer = comparerFactory.NewComparer(new GroupbyFieldValueAccessor(this.GetFacetString, this.GetRawFaceValue), m_count);
                        facetColl = new List <BrowseFacet>();
                        int forbidden = -1;
                        Int32BoundedPriorityQueue pq = new Int32BoundedPriorityQueue(comparer, max, forbidden);

                        for (int i = 1; i < m_countlength; ++i) // exclude zero
                        {
                            int hits = m_count.Get(i);
                            if (hits >= minCount)
                            {
                                if (!pq.Offer(i))
                                {
                                    // pq is full. we can safely ignore any facet with <=hits.
                                    minCount = hits + 1;
                                }
                            }
                        }

                        int val;
                        while ((val = pq.Poll()) != forbidden)
                        {
                            BrowseFacet facet = new BrowseFacet(GetFacetString(val), m_count.Get(val));
                            facetColl.Insert(0, facet);
                        }
                    }
                    return(facetColl);
                }
                else
                {
                    return(FacetCountCollector.EMPTY_FACET_LIST);
                }
            }
Exemple #3
0
        public static ICollection <BrowseFacet> GetFacets(FacetSpec ospec, BigSegmentedArray count, int countlength, ITermValueList valList)
        {
            if (ospec != null)
            {
                int minCount = ospec.MinHitCount;
                int max      = ospec.MaxCount;
                if (max <= 0)
                {
                    max = countlength;
                }

                LinkedList <BrowseFacet> facetColl;
                FacetSpec.FacetSortSpec  sortspec = ospec.OrderBy;
                if (sortspec == FacetSpec.FacetSortSpec.OrderValueAsc)
                {
                    facetColl = new LinkedList <BrowseFacet>();
                    for (int i = 1; i < countlength; ++i) // exclude zero
                    {
                        int hits = count.Get(i);
                        if (hits >= minCount)
                        {
                            BrowseFacet facet = new BrowseFacet(valList.Get(i), hits);
                            facetColl.AddLast(facet);
                        }

                        if (facetColl.Count >= max)
                        {
                            break;
                        }
                    }
                }
                else //if (sortspec == FacetSortSpec.OrderHitsDesc)
                {
                    IComparerFactory comparerFactory;
                    if (sortspec == FacetSpec.FacetSortSpec.OrderHitsDesc)
                    {
                        comparerFactory = new FacetHitcountComparerFactory();
                    }
                    else
                    {
                        comparerFactory = ospec.CustomComparerFactory;
                    }

                    if (comparerFactory == null)
                    {
                        throw new ArgumentException("facet comparer factory not specified");
                    }

                    IComparer <int> comparer = comparerFactory.NewComparer(new DefaultFacetCountCollectorFieldAccessor(valList), count);
                    facetColl = new LinkedList <BrowseFacet>();
                    int forbidden = -1;
                    Int32BoundedPriorityQueue pq = new Int32BoundedPriorityQueue(comparer, max, forbidden);

                    for (int i = 1; i < countlength; ++i) // exclude zero
                    {
                        int hits = count.Get(i);
                        if (hits >= minCount)
                        {
                            pq.Offer(i);
                        }
                    }

                    int val;
                    while ((val = pq.Poll()) != forbidden)
                    {
                        BrowseFacet facet = new BrowseFacet(valList[val], count.Get(val));
                        facetColl.AddFirst(facet);
                    }
                }
                return(facetColl);
            }
            else
            {
                return(FacetCountCollector.EMPTY_FACET_LIST);
            }
        }