ontology/solr-facet-tree/src/main/java/uk/co/flax/biosolr/builders/ChildNodeFacetTreeBuilder.java
/**
	 * Recursively build an accumulated facet entry tree.
	 * @param level current level in the tree (used for debugging/logging).
	 * @param fieldValue the current node value.
	 * @param hierarchyMap the map of nodes (either in the original facet set,
	 * or parents of those entries).
	 * @param facetCounts the facet counts, keyed by node ID.
	 * @return a {@link TreeFacetField} containing details for the current node and all
	 * sub-nodes down to the lowest leaf which has a facet count.
	 */
Recursively build an accumulated facet entry tree.
@param level current level in the tree (used for debugging/logging).
@param fieldValue the current node value.
@param hierarchyMap the map of nodes (either in the original facet set,
or parents of those entries).
@param facetCounts the facet counts, keyed by node ID.
@return a  TreeFacetField containing details for the current node and all
sub-nodes down to the lowest leaf which has a facet count.
Recursively build an accumulated facet entry tree . @param level current level in the tree ( used for debugging / logging ) . @param fieldValue the current node value . @param hierarchyMap the map of nodes ( either in the original facet set or parents of those entries ) . @param facetCounts the facet counts keyed by node ID . @return a TreeFacetField containing details for the current node and all sub - nodes down to the lowest leaf which has a facet count .
private TreeFacetField buildAccumulatedEntryTree(int level, String fieldValue, Map<String, Set<String>> hierarchyMap,
			Map<String, Integer> facetCounts) {
		SortedSet<TreeFacetField> childHierarchy = new TreeSet<>(Collections.reverseOrder());
		long childTotal = 0;
		if (hierarchyMap.containsKey(fieldValue)) {
			for (String childId : hierarchyMap.get(fieldValue)) {
				if (hierarchyMap.containsKey(childId) && !childId.equals(fieldValue)) {
					LOGGER.trace("[{}] Building child tree for {}, with {} children", level, childId, hierarchyMap.get(childId).size());
					TreeFacetField childTree = buildAccumulatedEntryTree(level + 1, childId, hierarchyMap, facetCounts);
					if (childHierarchy.add(childTree)) {
						childTotal += childTree.getTotal();
					}
					LOGGER.trace("[{}] child tree total: {} - child Total {}, child count {}", level, childTree.getTotal(), childTotal, childHierarchy.size());
				} else {
					LOGGER.trace("[{}] no node entry for {}->{}", level, fieldValue, childId);
				}
			}
		}
		LOGGER.trace("[{}] Building facet tree for {}", level, fieldValue);
		return new TreeFacetField(getLabel(fieldValue), fieldValue, getFacetCount(fieldValue, facetCounts), childTotal, childHierarchy);
	}
private TreeFacetField buildAccumulatedEntryTree ( int level , String fieldValue , Map < String , Set < String > > hierarchyMap , Map < String , Integer > facetCounts ) { SortedSet < TreeFacetField > childHierarchy = new TreeSet < > ( Collections . reverseOrder ( ) ) ; long childTotal = 0 ; if ( hierarchyMap . containsKey ( fieldValue ) ) { for ( String childId : hierarchyMap . get ( fieldValue ) ) { if ( hierarchyMap . containsKey ( childId ) && ! childId . equals ( fieldValue ) ) { LOGGER . trace ( "[{}] Building child tree for {}, with {} children" , level , childId , hierarchyMap . get ( childId ) . size ( ) ) ; TreeFacetField childTree = buildAccumulatedEntryTree ( level + 1 , childId , hierarchyMap , facetCounts ) ; if ( childHierarchy . add ( childTree ) ) { childTotal += childTree . getTotal ( ) ; } LOGGER . trace ( "[{}] child tree total: {} - child Total {}, child count {}" , level , childTree . getTotal ( ) , childTotal , childHierarchy . size ( ) ) ; } else { LOGGER . trace ( "[{}] no node entry for {}->{}" , level , fieldValue , childId ) ; } } } LOGGER . trace ( "[{}] Building facet tree for {}" , level , fieldValue ) ; return new TreeFacetField ( getLabel ( fieldValue ) , fieldValue , getFacetCount ( fieldValue , facetCounts ) , childTotal , childHierarchy ) ; }
Recursively build an accumulated facet entry tree.
Recursively build an accumulated facet entry tree .
// Build the child hierarchy for this entry. // We use a reverse-ordered SortedSet so entries are returned in descending // order by their total count. // childTotal is the total number of facet hits below this node // Loop through all the direct child URIs, looking for those which are in the annotation map // Found a child of this node - recurse to build its facet tree // Only add to the total count if this node isn't already in the child hierarchy // Build the accumulated facet entry