/**
  * Checks for circular references
  *
  * @param xfDocument $child The child document
  * @return int The number of circular references found
  */
 private function checkCircularReference(xfDocument $child)
 {
     $circular = 0;
     if ($child === $this) {
         $circular++;
     }
     foreach ($child->getChildren() as $grandchild) {
         $circular += $this->checkCircularReference($grandchild);
     }
     return $circular;
 }
}
$t->diag('->hasField()');
$t->ok($doc->hasField('field1'), '->hasField() returns true if the field exists');
$t->ok(!$doc->hasField('field99'), '->hasField() returns false if the field does not exist');
$t->diag('->setBoost(), ->getBoost()');
$doc = new xfDocument('guid');
$t->is($doc->getBoost(), 1.0, '->getBoost() is 1.0 initially');
$doc->setBoost(M_PI);
$t->is($doc->getBoost(), M_PI, '->setBoost() changes the boost');
$doc->setBoost('42foobar');
$t->is($doc->getBoost(), 42, '->setBoost() casts the input to a float');
$t->diag('->addChild(), ->getChildren()');
$parent = new xfDocument('parent');
$child = new xfDocument('child');
$parent->addChild($child);
$t->is($parent->getChildren(), array('child' => $child), '->addChild() adds a child');
$parent->addChild($child);
$t->is($parent->getChildren(), array('child' => $child), '->addChild() does not add a child twice');
try {
    $msg = '->addChild() rejects circular children';
    $child->addChild($parent);
    $t->fail($msg);
} catch (Exception $e) {
    $t->pass($msg);
}
$grandparent = new xfDocument('grandparent');
$parent = new xfDocument('parent');
$child = new xfDocument('child');
$grandchild = new xfDocument('grandchild');
$grandparent->addChild($parent);
$parent->addChild($child);
 /**
  * Rewrites a xfDocument into a Zend_Search_Lucene document
  *
  * @param xfDocument $doc The document
  * @returns Zend_Search_Lucene_Document
  */
 public function rewriteDocument(xfDocument $doc)
 {
     $zdoc = new Zend_Search_Lucene_Document();
     $zdoc->addField(Zend_Search_Lucene_Field::Keyword('__guid', $doc->getGuid()));
     $zdoc->boost = $doc->getBoost();
     $boosts = array();
     foreach ($doc->getFields() as $field) {
         $type = $field->getField()->getType();
         $zfield = new Zend_Search_Lucene_Field($field->getField()->getName(), $field->getValue(), $field->getEncoding(), ($type & xfField::STORED) > 0, ($type & xfField::INDEXED) > 0, ($type & xfField::TOKENIZED) > 0, ($type & xfField::BINARY) > 0);
         $zfield->boost = $field->getField()->getBoost();
         $zdoc->addField($zfield);
         $boosts[$field->getField()->getName()] = $field->getField()->getBoost();
     }
     $childrenGuids = array();
     foreach ($doc->getChildren() as $child) {
         $childrenGuids[] = $child->getGuid();
     }
     $zdoc->addField(Zend_Search_Lucene_Field::UnIndexed('__sub_documents', serialize($childrenGuids)));
     $zdoc->addField(Zend_Search_Lucene_Field::UnIndexed('__boosts', serialize($boosts)));
     return $zdoc;
 }