code: public void breadthFirstSearch(Context context, SearchResultVisitor visitor, Resource root) {
          Queue<Resource> queue = Lists.newLinkedList();
          queue.add(root);
          while (!queue.isEmpty()) {
              Resource r = queue.remove();
              for (SearchResults.Result result : m_searcher
                      .search(context, matchKeyAndValue(Constants.PARENT_TERM_FIELD, r.getId()))) {
                  if (!visitor.visit(result)) {
                      return;
                  }
                  queue.add(result.getResource());
              }
          }
      }
docs: Visits all nodes in the resource tree bellow the given resource using
  breadth-first search.