DocId getParent(int n, BitSet deleted) throws IOException
   {
      DocId parent;
      boolean existing = false;
      int parentDocNum = inSegmentParents[n];
      if (parentDocNum != -1) {
         parent = DocId.create(parentDocNum);
      } else {
         parent = foreignParentDocIds.get(n);
      }

      if (parent != null)
      {
         existing = true;

         // check if valid and reset if necessary
         if (!parent.isValid(deleted))
         {
            if (log.isDebugEnabled())
            {
               log.debug(parent + " not valid anymore.");
            }
            parent = null;
         }
      }

      if (parent == null)
      {
         int plainDocId = -1;
         Document doc = document(n, FieldSelectors.UUID_AND_PARENT);
         String[] parentUUIDs = doc.getValues(FieldNames.PARENT);
         if (parentUUIDs.length == 0 || parentUUIDs[0].length() == 0)
         {
            // root node
            parent = DocId.NULL;
         }
         else
         {
            if (shareableNodes.get(n))
            {
               parent = DocId.create(parentUUIDs);
            }
            else
            {
               if (!existing)
               {
                  Term id = new Term(FieldNames.UUID, parentUUIDs[0]);
                  TermDocs docs = termDocs(id);
                  try
                  {
                     while (docs.next())
                     {
                        if (!deleted.get(docs.doc()))
                        {
                           plainDocId = docs.doc();
                           parent = DocId.create(plainDocId);
                           break;
                        }
                     }
                  }
                  finally
                  {
                     docs.close();
                  }
               }
               // if still null, then parent is not in this index, or existing
               // DocId was invalid. thus, only allowed to create DocId from uuid
               if (parent == null)
               {
                  parent = DocId.create(parentUUIDs[0]);
               }
            }
         }

         // finally put to cache
         if (plainDocId != -1) {
            // PlainDocId
            inSegmentParents[n] = plainDocId;
         } else {
            // UUIDDocId
            foreignParentDocIds.put(n, parent);
            if (existing) {
               // there was an existing parent reference in
               // inSegmentParents, which was invalid and is replaced
               // inSegmentParents, which was invalid and is replaced
               // mark as unknown
               inSegmentParents[n] = -1;
            }
         }
      }
      return parent;
   }
DocId getParent ( int n , BitSet deleted ) throws IOException { DocId parent ; boolean existing = false ; int parentDocNum = inSegmentParents [ n ] ; if ( parentDocNum != - 1 ) { parent = DocId . create ( parentDocNum ) ; } else { parent = foreignParentDocIds . get ( n ) ; } if ( parent != null ) { existing = true ; if ( ! parent . isValid ( deleted ) ) { if ( log . isDebugEnabled ( ) ) { log . debug ( parent + " not valid anymore." ) ; } parent = null ; } } if ( parent == null ) { int plainDocId = - 1 ; Document doc = document ( n , FieldSelectors . UUID_AND_PARENT ) ; String [ ] parentUUIDs = doc . getValues ( FieldNames . PARENT ) ; if ( parentUUIDs . length == 0 || parentUUIDs [ 0 ] . length ( ) == 0 ) { parent = DocId . NULL ; } else { if ( shareableNodes . get ( n ) ) { parent = DocId . create ( parentUUIDs ) ; } else { if ( ! existing ) { Term id = new Term ( FieldNames . UUID , parentUUIDs [ 0 ] ) ; TermDocs docs = termDocs ( id ) ; try { while ( docs . next ( ) ) { if ( ! deleted . get ( docs . doc ( ) ) ) { plainDocId = docs . doc ( ) ; parent = DocId . create ( plainDocId ) ; break ; } } } finally { docs . close ( ) ; } } if ( parent == null ) { parent = DocId . create ( parentUUIDs [ 0 ] ) ; } } } if ( plainDocId != - 1 ) { inSegmentParents [ n ] = plainDocId ; } else { foreignParentDocIds . put ( n , parent ) ; if ( existing ) { inSegmentParents [ n ] = - 1 ; } } } return parent ; }
Returns the <code>DocId</code> of the parent of <code>n</code> or
{@link DocId#NULL} if <code>n</code> does not have a parent
(<code>n</code> is the root node).

@param n the document number.
@param deleted the documents that should be regarded as deleted.
@return the <code>DocId</code> of <code>n</code>'s parent.
@throws IOException if an error occurs while reading from the index.