$doc->addField($value);
$t->is($doc->getField('field1'), $value, '->getField() returns the registered field');
$t->is($doc->getFields(), array('field1' => $value), '->getFields() returns all the fields');
try {
    $msg = '->getField() fails if field name does not exist';
    $doc->getField('foobar');
    $t->fail($msg);
} catch (Exception $e) {
    $t->pass($msg);
}
$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);
 /**
  * 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;
 }