コード例 #1
0
        public override FacetResult GetTopChildren(int topN, string dim, params string[] path)
        {
            if (topN <= 0)
            {
                throw new System.ArgumentException("topN must be > 0 (got: " + topN + ")");
            }
            FacetsConfig.DimConfig dimConfig = VerifyDim(dim);
            FacetLabel cp = new FacetLabel(dim, path);
            int dimOrd = taxoReader.GetOrdinal(cp);
            if (dimOrd == -1)
            {
                return null;
            }

            TopOrdAndFloatQueue q = new TopOrdAndFloatQueue(Math.Min(taxoReader.Count, topN));
            float bottomValue = 0;

            int ord = children[dimOrd];
            float sumValues = 0;
            int childCount = 0;

            TopOrdAndFloatQueue.OrdAndValue reuse = null;
            while (ord != TaxonomyReader.INVALID_ORDINAL)
            {
                if (values[ord] > 0)
                {
                    sumValues += values[ord];
                    childCount++;
                    if (values[ord] > bottomValue)
                    {
                        if (reuse == null)
                        {
                            reuse = new TopOrdAndFloatQueue.OrdAndValue();
                        }
                        reuse.Ord = ord;
                        reuse.Value = values[ord];
                        reuse = q.InsertWithOverflow(reuse);
                        if (q.Size() == topN)
                        {
                            bottomValue = q.Top().Value;
                        }
                    }
                }

                ord = siblings[ord];
            }

            if (sumValues == 0)
            {
                return null;
            }

            if (dimConfig.MultiValued)
            {
                if (dimConfig.RequireDimCount)
                {
                    sumValues = values[dimOrd];
                }
                else
                {
                    // Our sum'd count is not correct, in general:
                    sumValues = -1;
                }
            }
            else
            {
                // Our sum'd dim count is accurate, so we keep it
            }

            LabelAndValue[] labelValues = new LabelAndValue[q.Size()];
            for (int i = labelValues.Length - 1; i >= 0; i--)
            {
                TopOrdAndFloatQueue.OrdAndValue ordAndValue = q.Pop();
                FacetLabel child = taxoReader.GetPath(ordAndValue.Ord);
                labelValues[i] = new LabelAndValue(child.Components[cp.Length], ordAndValue.Value);
            }

            return new FacetResult(dim, path, sumValues, labelValues, childCount);
        }
コード例 #2
0
ファイル: FloatTaxonomyFacets.cs プロジェクト: wwb/lucenenet
        public override FacetResult GetTopChildren(int topN, string dim, params string[] path)
        {
            if (topN <= 0)
            {
                throw new System.ArgumentException("topN must be > 0 (got: " + topN + ")");
            }
            FacetsConfig.DimConfig dimConfig = VerifyDim(dim);
            FacetLabel             cp        = new FacetLabel(dim, path);
            int dimOrd = taxoReader.GetOrdinal(cp);

            if (dimOrd == -1)
            {
                return(null);
            }

            TopOrdAndFloatQueue q = new TopOrdAndFloatQueue(Math.Min(taxoReader.Count, topN));
            float bottomValue     = 0;

            int   ord        = children[dimOrd];
            float sumValues  = 0;
            int   childCount = 0;

            TopOrdAndFloatQueue.OrdAndValue reuse = null;
            while (ord != TaxonomyReader.INVALID_ORDINAL)
            {
                if (values[ord] > 0)
                {
                    sumValues += values[ord];
                    childCount++;
                    if (values[ord] > bottomValue)
                    {
                        if (reuse == null)
                        {
                            reuse = new TopOrdAndFloatQueue.OrdAndValue();
                        }
                        reuse.Ord   = ord;
                        reuse.Value = values[ord];
                        reuse       = q.InsertWithOverflow(reuse);
                        if (q.Size() == topN)
                        {
                            bottomValue = q.Top().Value;
                        }
                    }
                }

                ord = siblings[ord];
            }

            if (sumValues == 0)
            {
                return(null);
            }

            if (dimConfig.MultiValued)
            {
                if (dimConfig.RequireDimCount)
                {
                    sumValues = values[dimOrd];
                }
                else
                {
                    // Our sum'd count is not correct, in general:
                    sumValues = -1;
                }
            }
            else
            {
                // Our sum'd dim count is accurate, so we keep it
            }

            LabelAndValue[] labelValues = new LabelAndValue[q.Size()];
            for (int i = labelValues.Length - 1; i >= 0; i--)
            {
                TopOrdAndFloatQueue.OrdAndValue ordAndValue = q.Pop();
                FacetLabel child = taxoReader.GetPath(ordAndValue.Ord);
                labelValues[i] = new LabelAndValue(child.Components[cp.Length], ordAndValue.Value);
            }

            return(new FacetResult(dim, path, sumValues, labelValues, childCount));
        }