private FacetResult GetDim(string dim, OrdRange ordRange, int topN) { TopOrdAndIntQueue q = null; int bottomCount = 0; int dimCount = 0; int childCount = 0; TopOrdAndIntQueue.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 TopOrdAndIntQueue.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 TopOrdAndIntQueue(topN); } reuse = q.InsertWithOverflow(reuse); if (q.Size() == topN) { bottomCount = q.Top().Value; } } } } if (q == null) { return(null); } LabelAndValue[] labelValues = new LabelAndValue[q.Size()]; for (int i = labelValues.Length - 1; i >= 0; i--) { TopOrdAndIntQueue.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)); }
/// <summary> /// Creates this, pulling doc values from the specified /// field. /// </summary> public DefaultSortedSetDocValuesReaderState(IndexReader reader, string field = FacetsConfig.DEFAULT_INDEX_FIELD_NAME) { this.field = field; this.origReader = reader; // We need this to create thread-safe MultiSortedSetDV // per collector: topReader = SlowCompositeReaderWrapper.Wrap(reader); SortedSetDocValues dv = topReader.GetSortedSetDocValues(field); if (dv is null) { throw new ArgumentException("field \"" + field + "\" was not indexed with SortedSetDocValues"); } if (dv.ValueCount > int.MaxValue) { throw new ArgumentException("can only handle valueCount < System.Int32.MaxValue; got " + dv.ValueCount); } valueCount = (int)dv.ValueCount; // TODO: we can make this more efficient if eg we can be // "involved" when IOrdinalMap is being created? Ie see // each term/ord it's assigning as it goes... string lastDim = null; int startOrd = -1; BytesRef spare = new BytesRef(); // TODO: this approach can work for full hierarchy?; // TaxoReader can't do this since ords are not in // "sorted order" ... but we should generalize this to // support arbitrary hierarchy: for (int ord = 0; ord < valueCount; ord++) { dv.LookupOrd(ord, spare); string[] components = FacetsConfig.StringToPath(spare.Utf8ToString()); if (components.Length != 2) { throw new ArgumentException("this class can only handle 2 level hierarchy (dim/value); got: " + Arrays.ToString(components) + " " + spare.Utf8ToString()); } if (!components[0].Equals(lastDim, StringComparison.Ordinal)) { if (lastDim != null) { prefixToOrdRange[lastDim] = new OrdRange(startOrd, ord - 1); } startOrd = ord; lastDim = components[0]; } } if (lastDim != null) { prefixToOrdRange[lastDim] = new OrdRange(startOrd, valueCount - 1); } }
/// <summary> /// Creates this, pulling doc values from the specified /// field. /// </summary> public DefaultSortedSetDocValuesReaderState(IndexReader reader, string field = FacetsConfig.DEFAULT_INDEX_FIELD_NAME) { this.field = field; this.origReader = reader; // We need this to create thread-safe MultiSortedSetDV // per collector: topReader = SlowCompositeReaderWrapper.Wrap(reader); SortedSetDocValues dv = topReader.GetSortedSetDocValues(field); if (dv == null) { throw new System.ArgumentException("field \"" + field + "\" was not indexed with SortedSetDocValues"); } if (dv.ValueCount > int.MaxValue) { throw new System.ArgumentException("can only handle valueCount < Integer.MAX_VALUE; got " + dv.ValueCount); } valueCount = (int)dv.ValueCount; // TODO: we can make this more efficient if eg we can be // "involved" when IOrdinalMap is being created? Ie see // each term/ord it's assigning as it goes... string lastDim = null; int startOrd = -1; // TODO: this approach can work for full hierarchy?; // TaxoReader can't do this since ords are not in // "sorted order" ... but we should generalize this to // support arbitrary hierarchy: for (int ord = 0; ord < valueCount; ord++) { BytesRef term = new BytesRef(); dv.LookupOrd(ord, term); string[] components = FacetsConfig.StringToPath(term.Utf8ToString()); if (components.Length != 2) { throw new System.ArgumentException("this class can only handle 2 level hierarchy (dim/value); got: " + Arrays.ToString(components) + " " + term.Utf8ToString()); } if (!components[0].Equals(lastDim)) { if (lastDim != null) { prefixToOrdRange[lastDim] = new OrdRange(startOrd, ord - 1); } startOrd = ord; lastDim = components[0]; } } if (lastDim != null) { prefixToOrdRange[lastDim] = new OrdRange(startOrd, valueCount - 1); } }
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 ArgumentOutOfRangeException(nameof(topN), "topN must be > 0 (got: " + topN + ")"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentOutOfRangeException (.NET convention) } if (path.Length > 0) { throw new ArgumentOutOfRangeException(nameof(path), "path should be 0 length"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentOutOfRangeException (.NET convention) } OrdRange ordRange = state.GetOrdRange(dim); if (ordRange == null) { throw new ArgumentException("dimension \"" + dim + "\" was not indexed"); } return(GetDim(dim, ordRange, topN)); }
public override FacetResult GetTopChildren(int topN, string dim, params string[] path) { if (topN <= 0) { throw new System.ArgumentException("topN must be > 0 (got: " + topN + ")"); } if (path.Length > 0) { throw new System.ArgumentException("path should be 0 length"); } OrdRange ordRange = state.GetOrdRange(dim); if (ordRange == null) { throw new System.ArgumentException("dimension \"" + dim + "\" was not indexed"); } return(GetDim(dim, ordRange, topN)); }