public override float GetSpecificValue(string dim, params string[] path) { var dimConfig = VerifyDim(dim); if (path.Length == 0) { if (dimConfig.Hierarchical && dimConfig.MultiValued == false) { // ok: rolled up at search time } else if (dimConfig.RequireDimCount && dimConfig.MultiValued) { // ok: we indexed all ords at index time } else { throw new System.ArgumentException("cannot return dimension-level value alone; use getTopChildren instead"); } } int ord = TaxoReader.GetOrdinal(new FacetLabel(dim, path)); if (ord < 0) { return(-1); } return(values[ord]); }
/// <summary> /// Rolls up any single-valued hierarchical dimensions. </summary> protected virtual void Rollup() { // Rollup any necessary dims: foreach (KeyValuePair <string, FacetsConfig.DimConfig> ent in Config.DimConfigs) { string dim = ent.Key; FacetsConfig.DimConfig ft = ent.Value; if (ft.Hierarchical && ft.MultiValued == false) { int dimRootOrd = TaxoReader.GetOrdinal(new FacetLabel(dim)); Debug.Assert(dimRootOrd > 0); values[dimRootOrd] += Rollup(Children[dimRootOrd]); } } }
/// <summary> /// Rolls up any single-valued hierarchical dimensions. </summary> protected virtual void Rollup() { // Rollup any necessary dims: foreach (KeyValuePair <string, FacetsConfig.DimConfig> ent in Config.DimConfigs) { string dim = ent.Key; FacetsConfig.DimConfig ft = ent.Value; if (ft.Hierarchical && ft.MultiValued == false) { int dimRootOrd = TaxoReader.GetOrdinal(new FacetLabel(dim)); // It can be -1 if this field was declared in the // config but never indexed: if (dimRootOrd > 0) { values[dimRootOrd] += Rollup(Children[dimRootOrd]); } } } }
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 = TaxoReader.GetOrdinal(cp); if (dimOrd == -1) { return(null); } TopOrdAndIntQueue q = new TopOrdAndIntQueue(Math.Min(TaxoReader.Size, topN)); int bottomValue = 0; int ord = Children[dimOrd]; int totValue = 0; int childCount = 0; TopOrdAndIntQueue.OrdAndValue reuse = null; while (ord != TaxonomyReader.INVALID_ORDINAL) { if (values[ord] > 0) { totValue += values[ord]; childCount++; if (values[ord] > bottomValue) { if (reuse == null) { reuse = new TopOrdAndIntQueue.OrdAndValue(); } reuse.Ord = ord; reuse.Value = values[ord]; reuse = q.InsertWithOverflow(reuse); if (q.Size() == topN) { bottomValue = q.Top().Value; } } } ord = Siblings[ord]; } if (totValue == 0) { return(null); } if (dimConfig.MultiValued) { if (dimConfig.RequireDimCount) { totValue = 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.Size()]; for (int i = labelValues.Length - 1; i >= 0; i--) { TopOrdAndIntQueue.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, totValue, labelValues, childCount)); }