* (c) Carl Vondrick <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require dirname(__FILE__) . '/../../bootstrap/unit.php'; require 'util/xfException.class.php'; require 'document/xfDocument.class.php'; require 'document/xfFieldValue.class.php'; require 'document/xfField.class.php'; require 'document/xfDocumentException.class.php'; $t = new lime_test(15, new lime_output_color()); $t->diag('->__construct()'); $doc = new xfDocument('guid'); $t->is($doc->getGuid(), 'guid', '->getGuid() returns the document GUID'); $t->is($doc->getFields(), array(), '->getFields() returns an empty array initially'); $t->diag('->addField()'); $value = new xfFieldValue(new xfField('field1', xfField::KEYWORD), 'value'); $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');
/** * 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; }