ontology/solr-facet-tree/src/main/java/uk/co/flax/biosolr/builders/ParentNodeFacetTreeBuilder.java
/**
	 * Find all parent nodes for the given set of items.
	 * @param searcher the searcher for the collection being used.
	 * @param facetValues the starting set of node IDs.
	 * @return a map of nodes, keyed by their IDs.
	 * @throws IOException
	 */
Find all parent nodes for the given set of items.
@param searcher the searcher for the collection being used.
@param facetValues the starting set of node IDs.
@return a map of nodes, keyed by their IDs.
Find all parent nodes for the given set of items . @param searcher the searcher for the collection being used . @param facetValues the starting set of node IDs . @return a map of nodes keyed by their IDs .
private Map<String, Set<String>> findParentEntries(SolrIndexSearcher searcher, Collection<String> facetValues)
			throws IOException {
		Map<String, Set<String>> nodeParentIds = new HashMap<>();
		Set<String> nodesFound = new HashSet<>();
		Set<String> nodeIds = new HashSet<>(facetValues);
		int count = 0;
		while (nodeIds.size() > 0 && (maxLevels == 0 || maxLevels >= count)) {
			Map<String, Set<String>> parents = findParentIdsForNodes(searcher, nodeIds);
			nodeParentIds.putAll(parents);
			nodesFound.addAll(nodeIds);
			nodeIds = parents.values().stream()
					.flatMap(v -> v.stream())
					.filter(id -> !nodesFound.contains(id))
					.collect(Collectors.toSet());
			count ++;
		};
		Map<String, Set<String>> parentChildIds = new HashMap<>();
		for (Entry<String, Set<String>> entry : nodeParentIds.entrySet()) {
			for (String parentId : entry.getValue()) {
				if (!parentChildIds.containsKey(parentId)) {
					parentChildIds.put(parentId, new HashSet<String>());
				}
				parentChildIds.get(parentId).add(entry.getKey());
			}
		}
		return parentChildIds;
	}
private Map < String , Set < String > > findParentEntries ( SolrIndexSearcher searcher , Collection < String > facetValues ) throws IOException { Map < String , Set < String > > nodeParentIds = new HashMap < > ( ) ; Set < String > nodesFound = new HashSet < > ( ) ; Set < String > nodeIds = new HashSet < > ( facetValues ) ; int count = 0 ; while ( nodeIds . size ( ) > 0 && ( maxLevels == 0 || maxLevels >= count ) ) { Map < String , Set < String > > parents = findParentIdsForNodes ( searcher , nodeIds ) ; nodeParentIds . putAll ( parents ) ; nodesFound . addAll ( nodeIds ) ; nodeIds = parents . values ( ) . stream ( ) . flatMap ( v -> v . stream ( ) ) . filter ( id -> ! nodesFound . contains ( id ) ) . collect ( Collectors . toSet ( ) ) ; count ++ ; } ; Map < String , Set < String > > parentChildIds = new HashMap < > ( ) ; for ( Entry < String , Set < String > > entry : nodeParentIds . entrySet ( ) ) { for ( String parentId : entry . getValue ( ) ) { if ( ! parentChildIds . containsKey ( parentId ) ) { parentChildIds . put ( parentId , new HashSet < String > ( ) ) ; } parentChildIds . get ( parentId ) . add ( entry . getKey ( ) ) ; } } return parentChildIds ; }
Find all parent nodes for the given set of items.
Find all parent nodes for the given set of items .
// Find the direct parents for the current node IDs // Get the parent IDs from all the retrieved nodes - these are the next set of // nodes whose parents should be found. // Now, invert the map, so it's a map of parent->child IDs