public void Test9ModifiedNumberOfFacetsPerKey() { ModifiedSetup(); BrowseRequest request = CreateRequest(1, BrowseSelection.ValueOperation.ValueOperationOr); request.GetFacetSpec(AttributeHandlerName).OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc; BrowseResult res = browser.Browse(request); Console.WriteLine(res); IEnumerable <BrowseFacet> facets = res.GetFacetAccessor(AttributeHandlerName).GetFacets(); Assert.AreEqual(facets.Count(), 6); Assert.AreEqual(facets.Get(0).Value, "prop1=val1"); Assert.AreEqual(facets.Get(0).FacetValueHitCount, 4); Assert.AreEqual(facets.Get(1).Value, "prop2=val1"); Assert.AreEqual(facets.Get(1).FacetValueHitCount, 4); Assert.AreEqual(facets.Get(2).Value, "prop3=val1"); Assert.AreEqual(facets.Get(2).FacetValueHitCount, 1); }
public void Test10ModifiedNumberOfFacetsPerKeyInSelection() { ModifiedSetup(); selectionProperties.Put(AttributesFacetHandler.MAX_FACETS_PER_KEY_PROP_NAME, "2"); BrowseRequest request = CreateRequest(1, BrowseSelection.ValueOperation.ValueOperationOr, "prop1", "prop2", "prop3", "prop4", "prop5", "prop6", "prop7"); request.GetFacetSpec(AttributeHandlerName).OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc; BrowseResult res = browser.Browse(request); Console.WriteLine(res); IEnumerable <BrowseFacet> facets = res.GetFacetAccessor(AttributeHandlerName).GetFacets(); Assert.AreEqual(facets.Count(), 9); Assert.AreEqual(facets.Get(0).Value, "prop1=val1"); Assert.AreEqual(facets.Get(0).FacetValueHitCount, 4); Assert.AreEqual(facets.Get(1).Value, "prop2=val1"); Assert.AreEqual(facets.Get(1).FacetValueHitCount, 4); Assert.AreEqual(facets.Get(2).Value, "prop1=val2"); Assert.AreEqual(facets.Get(2).FacetValueHitCount, 2); Assert.AreEqual(facets.Get(3).Value, "prop3=val1"); Assert.AreEqual(facets.Get(3).FacetValueHitCount, 1); }
public static IDictionary <string, IFacetAccessible> MergeSimpleFacetContainers(IEnumerable <IDictionary <string, IFacetAccessible> > subMaps, BrowseRequest req) { Dictionary <string, Dictionary <object, BrowseFacet> > counts = new Dictionary <string, Dictionary <object, BrowseFacet> >(); foreach (Dictionary <string, IFacetAccessible> subMap in subMaps) { foreach (KeyValuePair <string, IFacetAccessible> entry in subMap) { Dictionary <object, BrowseFacet> count = counts[entry.Key]; if (count == null) { count = new Dictionary <object, BrowseFacet>(); counts.Add(entry.Key, count); } foreach (BrowseFacet facet in entry.Value.GetFacets()) { string val = facet.Value; BrowseFacet oldValue = count[val]; if (oldValue == null) { count.Add(val, new BrowseFacet(val, facet.FacetValueHitCount)); } else { oldValue.FacetValueHitCount = oldValue.FacetValueHitCount + facet.FacetValueHitCount; } } } } Dictionary <string, IFacetAccessible> mergedFacetMap = new Dictionary <string, IFacetAccessible>(); foreach (string facet in counts.Keys) { FacetSpec fs = req.GetFacetSpec(facet); FacetSpec.FacetSortSpec sortSpec = fs.OrderBy; IComparer <BrowseFacet> comparator; if (FacetSpec.FacetSortSpec.OrderValueAsc.Equals(sortSpec)) { comparator = FACET_VAL_COMPARATOR; } else if (FacetSpec.FacetSortSpec.OrderHitsDesc.Equals(sortSpec)) { comparator = FacetHitcountComparatorFactory.FACET_HITS_COMPARATOR; } else { comparator = fs.CustomComparatorFactory.NewComparator(); } Dictionary <object, BrowseFacet> facetValueCounts = counts[facet]; BrowseFacet[] facetArray = facetValueCounts.Values.ToArray(); Array.Sort(facetArray, comparator); int numToShow = facetArray.Length; if (req != null) { FacetSpec fspec = req.GetFacetSpec(facet); if (fspec != null) { int maxCount = fspec.MaxCount; if (maxCount > 0) { numToShow = Math.Min(maxCount, numToShow); } } } BrowseFacet[] facets; if (numToShow == facetArray.Length) { facets = facetArray; } else { facets = new BrowseFacet[numToShow]; Array.Copy(facetArray, 0, facets, 0, numToShow); } MappedFacetAccessible mergedFacetAccessible = new MappedFacetAccessible(facets); mergedFacetMap.Add(facet, mergedFacetAccessible); } return(mergedFacetMap); }
public void Test1Filter() { BrowseRequest request = CreateRequest(1, "prop3"); FacetCountCollectorSource facetCountCollectorSource = attributesFacetHandler.GetFacetCountCollectorSource(request.GetSelection(AttributeHandlerName), request.GetFacetSpec(AttributeHandlerName)); RandomAccessFilter randomAccessFilter = attributesFacetHandler.BuildFilter(request.GetSelection(AttributeHandlerName)); DocIdSetIterator iterator = randomAccessFilter.GetDocIdSet(boboReader).Iterator(); int docId = iterator.NextDoc(); int[] docIds = new int[2]; int i = 0; while (docId != DocIdSetIterator.NO_MORE_DOCS) { docIds[i] = docId; i++; docId = iterator.NextDoc(); } Assert.AreEqual(Arrays.ToString(new int[] { 1, 2 }), Arrays.ToString(docIds)); BrowseResult res = browser.Browse(request); Assert.AreEqual(res.NumHits, 2); IFacetAccessible fa = res.GetFacetAccessor(AttributeHandlerName); IEnumerable <BrowseFacet> facets = fa.GetFacets(); Console.WriteLine(facets); Assert.AreEqual(3, facets.Count()); BrowseFacet facet = facets.Get(0); Assert.AreEqual(1, facet.FacetValueHitCount); }