code: protected NodeFilter sharedNodesFilter() {
          return new NodeFilter() {
              private final Set<NodeKey> shareableNodeKeys = new HashSet<>();
  
              @Override
              public boolean includeNode( CachedNode node,
                                          NodeCache cache ) {
                  if (nodeTypes.isShareable(node.getPrimaryType(cache), node.getMixinTypes(cache))) {
                      NodeKey key = node.getKey();
                      if (shareableNodeKeys.contains(key)) {
                          return false;
                      }
                      // we're seeing the original shareable node, so we need to process it
                      shareableNodeKeys.add(key);
                      return true;
                  }
                  return true;
              }
  
              @Override
              public boolean continueProcessingChildren( CachedNode node, NodeCache cache ) {
                  return !shareableNodeKeys.contains(node.getKey());
              }
  
              @Override
              public String toString() {
                  return "(excludes-sharables)";
              }
          };
      }
docs: Creates a node filter which doesn't include any of the nodes from the shared set in the query result. This is per
  JSR-283/#14.16: if a query matches a descendant node of a shared set, it appears in query results only once.
  
  @return a new {@link org.modeshape.jcr.cache.document.NodeCacheIterator.NodeFilter} instance