public override float GetSpecificValue(string dim, params string[] path) { FacetsConfig.DimConfig dimConfig = VerifyDim(dim); if (path.Length == 0) { if (dimConfig.IsHierarchical && dimConfig.IsMultiValued == false) { // ok: rolled up at search time } else if (dimConfig.RequireDimCount && dimConfig.IsMultiValued) { // ok: we indexed all ords at index time } else { throw new ArgumentException("cannot return dimension-level value alone; use getTopChildren instead"); } } int ord = m_taxoReader.GetOrdinal(new FacetLabel(dim, path)); if (ord < 0) { return(-1); } return(m_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 m_config.DimConfigs) { string dim = ent.Key; FacetsConfig.DimConfig ft = ent.Value; if (ft.IsHierarchical && ft.IsMultiValued == false) { int dimRootOrd = m_taxoReader.GetOrdinal(new FacetLabel(dim)); Debug.Assert(dimRootOrd > 0); m_values[dimRootOrd] += Rollup(m_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 ArgumentException("topN must be > 0 (got: " + topN + ")"); } FacetsConfig.DimConfig dimConfig = VerifyDim(dim); FacetLabel cp = new FacetLabel(dim, path); int dimOrd = m_taxoReader.GetOrdinal(cp); if (dimOrd == -1) { return(null); } TopOrdAndSingleQueue q = new TopOrdAndSingleQueue(Math.Min(m_taxoReader.Count, topN)); float bottomValue = 0; int ord = m_children[dimOrd]; float sumValues = 0; int childCount = 0; while (ord != TaxonomyReader.INVALID_ORDINAL) { if (m_values[ord] > 0) { sumValues += 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 <float>(ord, m_values[ord])); if (q.Count == topN) { bottomValue = q.Top.Value; } } } ord = m_siblings[ord]; } if (sumValues == 0) { return(null); } if (dimConfig.IsMultiValued) { if (dimConfig.RequireDimCount) { sumValues = m_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.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, sumValues, 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 + ")"); } 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)); }