コード例 #1
0
        public static IEnumerable <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)
                {
                    IComparatorFactory comparatorFactory;
                    if (sortspec == FacetSpec.FacetSortSpec.OrderHitsDesc)
                    {
                        comparatorFactory = new FacetHitcountComparatorFactory();
                    }
                    else
                    {
                        comparatorFactory = ospec.CustomComparatorFactory;
                    }

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

                    IComparer <int> comparator = comparatorFactory.NewComparator(new DefaultFacetCountCollectorFieldAccessor(valList), count);
                    facetColl = new LinkedList <BrowseFacet>();
                    int forbidden = -1;
                    IntBoundedPriorityQueue pq = new IntBoundedPriorityQueue(comparator, 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_Fields.EMPTY_FACET_LIST);
            }
        }
コード例 #2
0
        public static IEnumerable<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)
                {
                    IComparatorFactory comparatorFactory;
                    if (sortspec == FacetSpec.FacetSortSpec.OrderHitsDesc)
                    {
                        comparatorFactory = new FacetHitcountComparatorFactory();
                    }
                    else
                    {
                        comparatorFactory = ospec.CustomComparatorFactory;
                    }

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

                    IComparer<int> comparator = comparatorFactory.NewComparator(new DefaultFacetCountCollectorFieldAccessor(valList), count);
                    facetColl = new LinkedList<BrowseFacet>();
                    int forbidden = -1;
                    IntBoundedPriorityQueue pq = new IntBoundedPriorityQueue(comparator, 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_Fields.EMPTY_FACET_LIST;
            }
        }
コード例 #3
0
            public virtual IEnumerable <BrowseFacet> GetFacets()
            {
                if (_fspec != null)
                {
                    int minCount = _fspec.MinHitCount;
                    int max      = _fspec.MaxCount;
                    if (max <= 0)
                    {
                        max = _countlength;
                    }

                    FacetSpec.FacetSortSpec sortspec = _fspec.OrderBy;
                    List <BrowseFacet>      facetColl;
                    if (sortspec == FacetSpec.FacetSortSpec.OrderValueAsc)
                    {
                        facetColl = new List <BrowseFacet>(max);
                        for (int i = 1; i < _countlength; ++i) // exclude zero
                        {
                            int hits = _count.Get(i);
                            if (hits >= minCount)
                            {
                                BrowseFacet facet = new BrowseFacet(GetFacetString(i), hits);
                                facetColl.Add(facet);
                            }
                            if (facetColl.Count >= max)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        IComparatorFactory comparatorFactory;
                        if (sortspec == FacetSpec.FacetSortSpec.OrderHitsDesc)
                        {
                            comparatorFactory = new FacetHitcountComparatorFactory();
                        }
                        else
                        {
                            comparatorFactory = _fspec.CustomComparatorFactory;
                        }

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

                        IComparer <int> comparator = comparatorFactory.NewComparator(new GroupbyFieldValueAccessor(this.GetFacetString, this.GetRawFaceValue), _count);
                        facetColl = new List <BrowseFacet>();
                        int forbidden = -1;
                        IntBoundedPriorityQueue pq = new IntBoundedPriorityQueue(comparator, max, forbidden);

                        for (int i = 1; i < _countlength; ++i) // exclude zero
                        {
                            int hits = _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), _count.Get(val));
                            facetColl.Insert(0, facet);
                        }
                    }
                    return(facetColl);
                }
                else
                {
                    return(FacetCountCollector_Fields.EMPTY_FACET_LIST);
                }
            }
コード例 #4
0
        public virtual List<BrowseFacet> GetFacetsNew()
        {
            if (_ospec != null)
            {
                if (_predefinedRangeIndexes != null)
                {
                    int minCount = _ospec.MinHitCount;
                    int maxNumOfFacets = _ospec.MaxCount;
                    if (maxNumOfFacets <= 0 || maxNumOfFacets > _predefinedRangeIndexes.Length) maxNumOfFacets = _predefinedRangeIndexes.Length;

                    BigSegmentedArray rangeCount = new LazyBigIntArray(_predefinedRangeIndexes.Length);

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

                    List<BrowseFacet> facetColl;
                    FacetSpec.FacetSortSpec sortspec = _ospec.OrderBy;
                    if (sortspec == FacetSpec.FacetSortSpec.OrderValueAsc)
                    {
                        facetColl = new List<BrowseFacet>(maxNumOfFacets);
                        for (int k = 0; k < _predefinedRangeIndexes.Length; ++k)
                        {
                            if (rangeCount.Get(k) >= minCount)
                            {
                                BrowseFacet choice = new BrowseFacet(_predefinedRanges.Get(k), rangeCount.Get(k));
                                facetColl.Add(choice);
                            }
                            if (facetColl.Count >= maxNumOfFacets) 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 ArgumentException("facet comparator factory not specified");
                        }

                        IComparer<int> comparator = comparatorFactory.NewComparator(new RangeFacetCountCollectorFieldAccessor(_predefinedRanges), rangeCount);

                        int forbidden = -1;
                        IntBoundedPriorityQueue pq = new IntBoundedPriorityQueue(comparator, maxNumOfFacets, forbidden);
                        for (int i = 0; i < _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(_predefinedRanges.ElementAt(val), rangeCount.Get(val));
                            facetColl.Insert(0, facet);
                        }
                    }
                    return facetColl;
                }
                else
                {
                    return FacetCountCollector_Fields.EMPTY_FACET_LIST;
                }
            }
            else
            {
                return FacetCountCollector_Fields.EMPTY_FACET_LIST;
            }
        }
コード例 #5
0
        public virtual List <BrowseFacet> GetFacetsNew()
        {
            if (_ospec != null)
            {
                if (_predefinedRangeIndexes != null)
                {
                    int minCount       = _ospec.MinHitCount;
                    int maxNumOfFacets = _ospec.MaxCount;
                    if (maxNumOfFacets <= 0 || maxNumOfFacets > _predefinedRangeIndexes.Length)
                    {
                        maxNumOfFacets = _predefinedRangeIndexes.Length;
                    }

                    BigSegmentedArray rangeCount = new LazyBigIntArray(_predefinedRangeIndexes.Length);

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

                    List <BrowseFacet>      facetColl;
                    FacetSpec.FacetSortSpec sortspec = _ospec.OrderBy;
                    if (sortspec == FacetSpec.FacetSortSpec.OrderValueAsc)
                    {
                        facetColl = new List <BrowseFacet>(maxNumOfFacets);
                        for (int k = 0; k < _predefinedRangeIndexes.Length; ++k)
                        {
                            if (rangeCount.Get(k) >= minCount)
                            {
                                BrowseFacet choice = new BrowseFacet(_predefinedRanges.Get(k), rangeCount.Get(k));
                                facetColl.Add(choice);
                            }
                            if (facetColl.Count >= maxNumOfFacets)
                            {
                                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 ArgumentException("facet comparator factory not specified");
                        }

                        IComparer <int> comparator = comparatorFactory.NewComparator(new RangeFacetCountCollectorFieldAccessor(_predefinedRanges), rangeCount);

                        int forbidden = -1;
                        IntBoundedPriorityQueue pq = new IntBoundedPriorityQueue(comparator, maxNumOfFacets, forbidden);
                        for (int i = 0; i < _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(_predefinedRanges.ElementAt(val), rangeCount.Get(val));
                            facetColl.Insert(0, facet);
                        }
                    }
                    return(facetColl);
                }
                else
                {
                    return(FacetCountCollector_Fields.EMPTY_FACET_LIST);
                }
            }
            else
            {
                return(FacetCountCollector_Fields.EMPTY_FACET_LIST);
            }
        }