public virtual void TestPathToStringAndBack() { int iters = AtLeast(1000); for (int i = 0; i < iters; i++) { int numParts = TestUtil.NextInt32(Random, 1, 6); string[] parts = new string[numParts]; for (int j = 0; j < numParts; j++) { string s; while (true) { s = TestUtil.RandomUnicodeString(Random); if (s.Length > 0) { break; } } parts[j] = s; } string s1 = FacetsConfig.PathToString(parts); string[] parts2 = FacetsConfig.StringToPath(s1); Assert.True(Arrays.Equals(parts, parts2)); } }
/// <summary> /// Note: if you use a counting <see cref="Facets"/> implementation, you can amortize the /// sampled counts by calling this method. Uses the <see cref="FacetsConfig"/> and /// the <see cref="IndexSearcher"/> to determine the upper bound for each facet value. /// </summary> public virtual FacetResult AmortizeFacetCounts(FacetResult res, FacetsConfig config, IndexSearcher searcher) { if (res == null || totalHits <= sampleSize) { return(res); } LabelAndValue[] fixedLabelValues = new LabelAndValue[res.LabelValues.Length]; IndexReader reader = searcher.IndexReader; DimConfig dimConfig = config.GetDimConfig(res.Dim); // +2 to prepend dimension, append child label string[] childPath = new string[res.Path.Length + 2]; childPath[0] = res.Dim; Array.Copy(res.Path, 0, childPath, 1, res.Path.Length); // reuse for (int i = 0; i < res.LabelValues.Length; i++) { childPath[res.Path.Length + 1] = res.LabelValues[i].Label; string fullPath = FacetsConfig.PathToString(childPath, childPath.Length); int max = reader.DocFreq(new Term(dimConfig.IndexFieldName, fullPath)); int correctedCount = (int)((double)res.LabelValues[i].Value / samplingRate); correctedCount = Math.Min(max, correctedCount); fixedLabelValues[i] = new LabelAndValue(res.LabelValues[i].Label, correctedCount); } // cap the total count on the total number of non-deleted documents in the reader int correctedTotalCount = (int)res.Value; if (correctedTotalCount > 0) { correctedTotalCount = Math.Min(reader.NumDocs, (int)((double)res.Value / samplingRate)); } return(new FacetResult(res.Dim, res.Path, correctedTotalCount, fixedLabelValues, res.ChildCount)); }
/// <summary> /// Creates a drill-down term. /// </summary> public static Term Term(string field, string dim, params string[] path) { return(new Term(field, FacetsConfig.PathToString(dim, path))); }