Exemple #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 + ")");
            }
            var        dimConfig = VerifyDim(dim);
            FacetLabel cp        = new FacetLabel(dim, path);
            int        dimOrd    = m_taxoReader.GetOrdinal(cp);

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

            TopOrdAndInt32Queue q = new TopOrdAndInt32Queue(Math.Min(m_taxoReader.Count, topN));

            int bottomValue = 0;

            int ord        = m_children[dimOrd];
            int totValue   = 0;
            int childCount = 0;

            TopOrdAndInt32Queue.OrdAndValue reuse = null;
            while (ord != TaxonomyReader.INVALID_ORDINAL)
            {
                if (m_values[ord] > 0)
                {
                    totValue += m_values[ord];
                    childCount++;
                    if (m_values[ord] > bottomValue)
                    {
                        if (reuse == null)
                        {
                            reuse = new TopOrdAndInt32Queue.OrdAndValue();
                        }
                        reuse.Ord   = ord;
                        reuse.Value = m_values[ord];
                        reuse       = q.InsertWithOverflow(reuse);
                        if (q.Count == topN)
                        {
                            bottomValue = q.Top.Value;
                        }
                    }
                }

                ord = m_siblings[ord];
            }

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

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

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

            return(new FacetResult(dim, path, totValue, labelValues, childCount));
        }
Exemple #2
0
        public override FacetResult GetTopChildren(int topN, string dim, params string[] path)
        {
            if (topN <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(topN), "topN must be > 0 (got: " + topN + ")"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentOutOfRangeException (.NET convention)
            }
            var        dimConfig = VerifyDim(dim);
            FacetLabel cp        = new FacetLabel(dim, path);
            int        dimOrd    = m_taxoReader.GetOrdinal(cp);

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

            TopOrdAndInt32Queue q = new TopOrdAndInt32Queue(Math.Min(m_taxoReader.Count, topN));

            int bottomValue = 0;

            int ord        = m_children[dimOrd];
            int totValue   = 0;
            int childCount = 0;

            while (ord != TaxonomyReader.INVALID_ORDINAL)
            {
                if (m_values[ord] > 0)
                {
                    totValue += m_values[ord];
                    childCount++;
                    if (m_values[ord] > bottomValue)
                    {
                        // LUCENENET specific - use struct instead of reusing class instance for better performance
                        q.Insert(new OrdAndValue <int>(ord, m_values[ord]));
                        if (q.Count == topN)
                        {
                            bottomValue = q.Top.Value;
                        }
                    }
                }

                ord = m_siblings[ord];
            }

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

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

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

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