public List<BrowseFacet> getFacets() { if (_ospec != null) { if (_predefinedRangeIndexes != null) { int minCount = _ospec.getMinHitCount(); List<BrowseFacet> list = new ArrayList<BrowseFacet>(_predefinedRangeIndexes.length); for (int k = 0; k < _predefinedRangeIndexes.length; ++k) { int count = 0; int idx = _predefinedRangeIndexes[k][0]; int end = _predefinedRangeIndexes[k][1]; while (idx <= end) { count += _count[idx++]; } if (count >= minCount) { BrowseFacet choice = new BrowseFacet(); choice.setHitCount(count); choice.setValue(_predefinedRanges.get(k)); list.add(choice); } } return list; } else { return FacetCountCollector.EMPTY_FACET_LIST; } } else { return FacetCountCollector.EMPTY_FACET_LIST; } }
void convertFacets(BrowseFacet[] facets) { int i = 0; for (BrowseFacet facet : facets) { int hit = facet.getHitCount(); String val = facet.getValue(); RangeFacet rangeFacet = new RangeFacet(); rangeFacet.setValues(val, val); rangeFacet.setHitCount(hit); facets[i++] = rangeFacet; } }
public BrowseFacet getFacet(String value) { int sum = -1; String foundValue = null; if (_list != null) { for (FacetAccessible facetAccessor : _list) { BrowseFacet facet = facetAccessor.getFacet(value); if (facet != null) { foundValue = facet.getValue(); if (sum == -1) sum = facet.getHitCount(); else sum += facet.getHitCount(); } } } if (sum == -1) return null; return new BrowseFacet(foundValue, sum); }
public List<BrowseFacet> getFacets() { Map<String, BrowseFacet> facetMap; if (FacetSortSpec.OrderValueAsc.equals(_fspec.getOrderBy())) { facetMap = new TreeMap<String, BrowseFacet>(); } else { facetMap = new HashMap<String, BrowseFacet>(); } for (FacetAccessible facetAccessor : _list) { Iterator<BrowseFacet> iter = facetAccessor.getFacets().iterator(); if (facetMap.size() == 0) { while (iter.hasNext()) { BrowseFacet facet = iter.next(); facetMap.put(facet.getValue(), facet); } } else { while (iter.hasNext()) { BrowseFacet facet = iter.next(); BrowseFacet existing = facetMap.get(facet.getValue()); if (existing == null) { facetMap.put(facet.getValue(), facet); } else { existing.setHitCount(existing.getHitCount() + facet.getHitCount()); } } } } int cnt = 0; int maxCnt = _fspec.getMaxCount(); if (maxCnt <= 0) maxCnt = Integer.MAX_VALUE; int minHits = _fspec.getMinHitCount(); List<BrowseFacet> list = new LinkedList<BrowseFacet>(); if (FacetSortSpec.OrderValueAsc.equals(_fspec.getOrderBy())) { for (BrowseFacet facet : facetMap.values()) { if (facet.getHitCount() >= minHits) { list.add(facet); if (++cnt >= maxCnt) break; } } } else { Comparator<BrowseFacet> comparator; if (FacetSortSpec.OrderHitsDesc.equals(_fspec.getOrderBy())) { comparator = new Comparator<BrowseFacet>() { public int compare(BrowseFacet f1, BrowseFacet f2) { int val = f2.getHitCount() - f1.getHitCount(); if (val == 0) { val = (f1.getValue().compareTo(f2.getValue())); } return val; } }; } else // FacetSortSpec.OrderByCustom.equals(_fspec.getOrderBy() { comparator = _fspec.getCustomComparatorFactory().newComparator(); } ArrayList<BrowseFacet> facets = new ArrayList<BrowseFacet>(facetMap.values()); Collections.sort(facets, comparator); for (BrowseFacet facet : facets) { if (facet.getHitCount() >= minHits) { list.add(facet); if (++cnt >= maxCnt) break; } } } return list; }
public static Map<String, FacetAccessible> mergeSimpleFacetContainers( Collection<Map<String, FacetAccessible>> subMaps, BrowseRequest req) { Map<String, Map<String, BrowseFacet>> counts = new HashMap<String, Map<String, BrowseFacet>>(); for (Map<String, FacetAccessible> subMap : subMaps) { for (Map.Entry<String, FacetAccessible> entry : subMap.entrySet()) { Map<String, BrowseFacet> count = counts.get(entry.getKey()); if (count == null) { count = new HashMap<String, BrowseFacet>(); counts.put(entry.getKey(), count); } for (BrowseFacet facet : entry.getValue().getFacets()) { String val = facet.getValue(); BrowseFacet oldValue = count.get(val); if (oldValue == null) { count.put(val, new BrowseFacet(val, facet.getHitCount())); } else { oldValue.setHitCount(oldValue.getHitCount() + facet.getHitCount()); } } } } Map<String, FacetAccessible> mergedFacetMap = new HashMap<String, FacetAccessible>(); for (String facet : counts.keySet()) { FacetSpec fs = req.getFacetSpec(facet); FacetSpec.FacetSortSpec sortSpec = fs.getOrderBy(); Comparator<BrowseFacet> comparator; if (FacetSortSpec.OrderValueAsc.equals(sortSpec)) comparator = FACET_VAL_COMPARATOR; else if (FacetSortSpec.OrderHitsDesc.equals(sortSpec)) comparator = FacetHitcountComparatorFactory.FACET_HITS_COMPARATOR; else comparator = fs.getCustomComparatorFactory().newComparator(); Map<String, BrowseFacet> facetValueCounts = counts.get(facet); BrowseFacet[] facetArray = facetValueCounts.values().toArray(new BrowseFacet[facetValueCounts.size()]); Arrays.sort(facetArray, comparator); int numToShow = facetArray.length; if (req != null) { FacetSpec fspec = req.getFacetSpec(facet); if (fspec != null) { int maxCount = fspec.getMaxCount(); if (maxCount > 0) { numToShow = Math.min(maxCount, numToShow); } } } BrowseFacet[] facets; if (numToShow == facetArray.length) { facets = facetArray; } else { facets = new BrowseFacet[numToShow]; System.arraycopy(facetArray, 0, facets, 0, numToShow); } MappedFacetAccessible mergedFacetAccessible = new MappedFacetAccessible(facets); mergedFacetMap.put(facet, mergedFacetAccessible); } return mergedFacetMap; }
public int compare(BrowseFacet o1, BrowseFacet o2) { return o1.getValue().compareTo(o2.getValue()); }