private FacetResult GetDim(string dim, OrdRange ordRange, int topN) { TopOrdAndInt32Queue q = null; int bottomCount = 0; int dimCount = 0; int childCount = 0; TopOrdAndInt32Queue.OrdAndValue reuse = null; //System.out.println("getDim : " + ordRange.start + " - " + ordRange.end); for (int ord = ordRange.Start; ord <= ordRange.End; ord++) { //System.out.println(" ord=" + ord + " count=" + counts[ord]); if (counts[ord] > 0) { dimCount += counts[ord]; childCount++; if (counts[ord] > bottomCount) { if (reuse == null) { reuse = new TopOrdAndInt32Queue.OrdAndValue(); } reuse.Ord = ord; reuse.Value = counts[ord]; if (q == null) { // Lazy init, so we don't create this for the // sparse case unnecessarily q = new TopOrdAndInt32Queue(topN); } reuse = q.InsertWithOverflow(reuse); if (q.Count == topN) { bottomCount = q.Top.Value; } } } } if (q == null) { return(null); } LabelAndValue[] labelValues = new LabelAndValue[q.Count]; for (int i = labelValues.Length - 1; i >= 0; i--) { TopOrdAndInt32Queue.OrdAndValue ordAndValue = q.Pop(); var term = new BytesRef(); dv.LookupOrd(ordAndValue.Ord, term); string[] parts = FacetsConfig.StringToPath(term.Utf8ToString()); labelValues[i] = new LabelAndValue(parts[1], ordAndValue.Value); } return(new FacetResult(dim, new string[0], dimCount, labelValues, childCount)); }
private FacetResult GetDim(string dim, OrdRange ordRange, int topN) { TopOrdAndInt32Queue q = null; int bottomCount = 0; int dimCount = 0; int childCount = 0; //System.out.println("getDim : " + ordRange.start + " - " + ordRange.end); for (int ord = ordRange.Start; ord <= ordRange.End; ord++) { //System.out.println(" ord=" + ord + " count=" + counts[ord]); if (counts[ord] > 0) { dimCount += counts[ord]; childCount++; if (counts[ord] > bottomCount) { if (q == null) { // Lazy init, so we don't create this for the // sparse case unnecessarily q = new TopOrdAndInt32Queue(topN); } // LUCENENET specific - use struct instead of reusing class instance for better performance q.Insert(new OrdAndValue <int>(ord, counts[ord])); if (q.Count == topN) { bottomCount = q.Top.Value; } } } } if (q == null) { return(null); } var scratch = new BytesRef(); LabelAndValue[] labelValues = new LabelAndValue[q.Count]; for (int i = labelValues.Length - 1; i >= 0; i--) { var ordAndValue = q.Pop(); dv.LookupOrd(ordAndValue.Ord, scratch); string[] parts = FacetsConfig.StringToPath(scratch.Utf8ToString()); labelValues[i] = new LabelAndValue(parts[1], ordAndValue.Value); } return(new FacetResult(dim, Arrays.Empty <string>(), dimCount, labelValues, childCount)); }
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)); }
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)); }