/// <summary> /// Returns the ordinal of the category given as a path. The ordinal is the /// category's serial number, an integer which starts with 0 and grows as more /// categories are added (note that once a category is added, it can never be /// deleted). /// </summary> /// <returns> the category's ordinal or <see cref="INVALID_ORDINAL"/> if the category /// wasn't found. </returns> public abstract int GetOrdinal(FacetLabel categoryPath);
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) } 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 + ")"); } 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)); }
private void ProcessFacetFields(TaxonomyWriter taxoWriter, IDictionary<string, IList<FacetField>> byField, Document doc) { foreach (KeyValuePair<string, IList<FacetField>> ent in byField) { string indexFieldName = ent.Key; //System.out.println(" indexFieldName=" + indexFieldName + " fields=" + ent.getValue()); IntsRef ordinals = new IntsRef(32); foreach (FacetField facetField in ent.Value) { FacetsConfig.DimConfig ft = GetDimConfig(facetField.dim); if (facetField.path.Length > 1 && ft.Hierarchical == false) { throw new System.ArgumentException("dimension \"" + facetField.dim + "\" is not hierarchical yet has " + facetField.path.Length + " components"); } FacetLabel cp = new FacetLabel(facetField.dim, facetField.path); checkTaxoWriter(taxoWriter); int ordinal = taxoWriter.AddCategory(cp); if (ordinals.Length == ordinals.Ints.Length) { ordinals.Grow(ordinals.Length + 1); } ordinals.Ints[ordinals.Length++] = ordinal; //System.out.println("ords[" + (ordinals.length-1) + "]=" + ordinal); //System.out.println(" add cp=" + cp); if (ft.MultiValued && (ft.Hierarchical || ft.RequireDimCount)) { //System.out.println(" add parents"); // Add all parents too: int parent = taxoWriter.GetParent(ordinal); while (parent > 0) { if (ordinals.Ints.Length == ordinals.Length) { ordinals.Grow(ordinals.Length + 1); } ordinals.Ints[ordinals.Length++] = parent; parent = taxoWriter.GetParent(parent); } if (ft.RequireDimCount == false) { // Remove last (dimension) ord: ordinals.Length--; } } // Drill down: for (int i = 1; i <= cp.Length; i++) { doc.Add(new StringField(indexFieldName, PathToString(cp.Components, i), Field.Store.NO)); } } // Facet counts: // DocValues are considered stored fields: doc.Add(new BinaryDocValuesField(indexFieldName, DedupAndEncode(ordinals))); } }
private void ProcessAssocFacetFields(TaxonomyWriter taxoWriter, IDictionary<string, IList<AssociationFacetField>> byField, Document doc) { foreach (KeyValuePair<string, IList<AssociationFacetField>> ent in byField) { byte[] bytes = new byte[16]; int upto = 0; string indexFieldName = ent.Key; foreach (AssociationFacetField field in ent.Value) { // NOTE: we don't add parents for associations checkTaxoWriter(taxoWriter); FacetLabel label = new FacetLabel(field.dim, field.path); int ordinal = taxoWriter.AddCategory(label); if (upto + 4 > bytes.Length) { bytes = ArrayUtil.Grow(bytes, upto + 4); } // big-endian: bytes[upto++] = (byte)(ordinal >> 24); bytes[upto++] = (byte)(ordinal >> 16); bytes[upto++] = (byte)(ordinal >> 8); bytes[upto++] = (byte)ordinal; if (upto + field.assoc.Length > bytes.Length) { bytes = ArrayUtil.Grow(bytes, upto + field.assoc.Length); } Array.Copy(field.assoc.Bytes, field.assoc.Offset, bytes, upto, field.assoc.Length); upto += field.assoc.Length; // Drill down: for (int i = 1; i <= label.Length; i++) { doc.Add(new StringField(indexFieldName, PathToString(label.Components, i), Field.Store.NO)); } } doc.Add(new BinaryDocValuesField(indexFieldName, new BytesRef(bytes, 0, upto))); } }
public void processSSDVFacetFields(IDictionary<string, IList<SortedSetDocValuesFacetField>> byField, Document doc) { //System.out.println("process SSDV: " + byField); foreach (KeyValuePair<string, IList<SortedSetDocValuesFacetField>> ent in byField) { string indexFieldName = ent.Key; //System.out.println(" field=" + indexFieldName); foreach (SortedSetDocValuesFacetField facetField in ent.Value) { FacetLabel cp = new FacetLabel(facetField.Dim, facetField.Label); string fullPath = PathToString(cp.Components, cp.Length); //System.out.println("add " + fullPath); // For facet counts: doc.Add(new SortedSetDocValuesField(indexFieldName, new BytesRef(fullPath))); // For drill-down: doc.Add(new StringField(indexFieldName, fullPath, Field.Store.NO)); doc.Add(new StringField(indexFieldName, facetField.Dim, Field.Store.NO)); } } }