/**
  * Gets the service
  *
  * @returns string
  */
 public function getServiceName()
 {
     return $this->document->getField('_service')->getValue();
 }
    $name = 'test';
    $field = new Zend_Search_Lucene_Field($name, 'bar', 'utf8', false, false, false, false);
    $field->{$property} = true;
    $doc->addField($field);
    $doc->addField(Zend_Search_Lucene_Field::UnIndexed('__boosts', serialize(array('test' => 1))));
    $response = $engine->unwriteDocument($doc)->getField('test')->getField()->getType();
    $t->is($response, $type, '->unwriteDocument() can exclusively handle "' . $property . '"');
}
$t->diag('->add()');
$doc = new xfDocument('guid');
$doc->addField(new xfFieldValue(new xfField('name', xfField::KEYWORD), 'carl'));
$doc->addField(new xfFieldValue(new xfField('age', xfField::STORED), 18));
$engine->add($doc);
$engine->commit();
$t->is($engine->count(), 1, '->add() adds a document');
$parent = new xfDocument('parent');
$child = new xfDocument('child');
$pet = new xfDocument('pet');
$parent->addChild($child);
$child->addChild($pet);
$engine->add($parent);
$engine->commit();
$t->is($engine->count(), 4, '->add() adds a document and every subdocument');
$t->diag('->findGuid()');
$doc = $engine->findGuid('guid');
$t->isa_ok($doc, 'xfDocument', '->findGuid() returns an xfDocument');
$t->is($doc->getGuid(), 'guid', '->findGuid() returns the correct document');
$doc = $engine->findGuid('parent');
$children = $doc->getChildren();
$t->is(count($children), 1, '->findGuid() rebuilds subdocuments correctly');
$t->is($children['child']->getGuid(), 'child', '->findGuid() rebuilds subdocuments in correct order');
 * This file is part of the sfSearch package.
 * (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/xfField.class.php';
require 'document/xfFieldValue.class.php';
require 'result/xfDocumentHit.class.php';
require 'result/xfResultException.class.php';
require 'mock/result/xfMockRetort.class.php';
$t = new lime_test(11, new lime_output_color());
$document = new xfDocument('guid');
$document->addField(new xfFieldValue(new xfField('_service', xfField::STORED), 'foo-service'));
$hit = new xfDocumentHit($document, array('score' => 0.2));
$t->diag('->getOption(), ->getOptions(), hasOption(), setOption()');
$t->is($hit->getOption('score'), 0.2, '->getOption() returns the option value');
$t->is($hit->getOption('foobar'), null, '->getOption() returns null for unset options');
$t->is($hit->getOption('foobar', 42), 42, '->getOption() returns the default for unset options');
$t->ok($hit->hasOption('score'), '->hasOption() returns true for options that exist');
$t->ok(!$hit->hasOption('foobar'), '->hasOption() returns false for options that do not exist');
$hit->setOption('foobar', 'baz');
$t->is($hit->getOption('foobar'), 'baz', '->getOption() returns the option value');
$t->is($hit->getOptions(), array('score' => 0.2, 'foobar' => 'baz'), '->getOptions() returns all options');
$t->diag('->getDocument(), ->getServiceName()');
$t->is($hit->getDocument(), $document, '->getDocument() returns the wrapped document');
$t->is($hit->getServiceName(), 'foo-service', '->getServiceName() returns the service name');
$t->diag('->__call()');
$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');
$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);
 * 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/xfLuceneZendManager.class.php';
require 'engine/xfLuceneHits.class.php';
require 'engine/xfEngine.interface.php';
require 'engine/xfLuceneEngine.class.php';
require 'criteria/xfCriterion.interface.php';
require 'result/xfDocumentHit.class.php';
require 'document/xfDocument.class.php';
require 'document/xfField.class.php';
require 'document/xfFieldValue.class.php';
require 'addon/xfLuceneEnhancedFilesystem.class.php';
$t = new lime_test(17, new lime_output_color());
$doc = new xfDocument('foobar');
$doc->addField(new xfFieldValue(new xfField('title', xfField::TEXT), 'foobar'));
$engine = new xfLuceneEngine(dirname(__FILE__) . '/../../sandbox/index');
$engine->erase();
$engine->open();
$engine->add($doc);
$engine->commit();
$zhits = $engine->getIndex()->find('foobar');
$hits = new xfLuceneHits($engine, $zhits);
$t->diag('->current()');
$r = $hits->current();
$t->isa_ok($r, 'xfDocumentHit', '->current() returns an xfDocumentHit');
$t->is($r->getOption('score'), $zhits[0]->score, '->current() returns an xfDocumentHit with correct score');
$t->is($r->getOption('id'), $zhits[0]->id, '->current() returns an xfDocumentHit with correct id');
$t->is($r->getDocument()->getField('title')->getValue(), 'foobar', '->current() communicates with the unwriter correctly');
$t->ok($r === $hits->current(), '->current() caches the response');
/**
 * This file is part of the sfSearch package.
 * (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 'result/xfRetort.interface.php';
require 'result/xfRetortRoute.class.php';
require 'result/xfDocumentHit.class.php';
require 'document/xfDocument.class.php';
require 'document/xfField.class.php';
require 'document/xfFieldValue.class.php';
$doc = new xfDocument('guid');
$doc->addField(new xfFieldValue(new xfField('isbn', xfField::KEYWORD), '1234567890'));
$doc->addField(new xfFieldValue(new xfField('id', xfField::KEYWORD), '42'));
$hit = new xfDocumentHit($doc);
$t = new lime_test(5, new lime_output_color());
$retort = new xfRetortRoute('show/book?id=$id$');
$t->diag('->can()');
$t->ok(!$retort->can($hit, 'getFoo'), '->can() returns false if method does not match');
$t->ok($retort->can($hit, 'getRoute'), '->can() returns true if method does match');
$t->diag('->respond()');
$t->is($retort->respond($hit, 'getRoute'), 'show/book?id=42', '->respond() can do a single replacement');
$retort = new xfRetortRoute('show/book?id=$id$&isbn=$isbn$');
$t->is($retort->respond($hit, 'getRoute'), 'show/book?id=42&isbn=1234567890', '->respond() can do a double replacement');
$t->diag('->setMethod()');
$retort->setMethod('getIt');
$t->ok($retort->can($hit, 'getIt'), '->setMethod() changes the matching method');
 public function add(xfDocument $doc)
 {
     $this->documents[$doc->getGuid()] = $doc;
 }
 /**
  * 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;
 }
require 'result/xfResultIterator.class.php';
require 'result/xfDocumentHit.class.php';
require 'result/xfResultException.class.php';
require 'mock/result/xfMockRetort.class.php';
require 'document/xfDocument.class.php';
require 'document/xfField.class.php';
require 'document/xfFieldValue.class.php';
require 'service/xfServiceRegistry.class.php';
require 'service/xfService.class.php';
require 'mock/service/xfMockIdentifier.class.php';
$service = new xfService(new xfMockIdentifier());
$retort = new xfMockRetort();
$service->addRetort($retort);
$registry = new xfServiceRegistry();
$registry->register($service);
$document = new xfDocument('guid');
$document->addField(new xfFieldValue(new xfField('_service', xfField::KEYWORD), 'foobar'));
$hit = new xfDocumentHit($document);
$array = array($hit, 'foo');
$iterator = new xfResultIterator(new ArrayIterator($array), $registry);
$t = new lime_test(9, new lime_output_color());
$t->diag('->current()');
$response = $iterator->current();
$t->isa_ok($response, 'xfDocumentHit', '->current() returns an xfDocumentHit');
$t->is($response->getDocument(), $document, '->current() returns an xfDocumentHit linked to the original document');
$iterator->next();
try {
    $msg = '->current() throws exception if internal iterator does not return an xfDocumentHit';
    $iterator->current();
    $t->fail($msg);
} catch (Exception $e) {
<?php

/**
 * This file is part of the sfSearch package.
 * (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 'result/xfRetort.interface.php';
require 'result/xfRetortField.class.php';
require 'result/xfDocumentHit.class.php';
require 'document/xfDocument.class.php';
require 'document/xfField.class.php';
require 'document/xfFieldValue.class.php';
require 'util/xfToolkit.class.php';
$doc = new xfDocument('guid');
$doc->addField(new xfFieldValue(new xfField('name', xfField::KEYWORD), 'carl'));
$doc->addField(new xfFieldValue(new xfField('cat_name', xfField::KEYWORD), 'earl'));
$hit = new xfDocumentHit($doc);
$t = new lime_test(5, new lime_output_color());
$retort = new xfRetortField();
$t->diag('->can()');
$t->ok($retort->can($hit, 'getName'), '->can() returns true if method matches a field in the document');
$t->ok(!$retort->can($hit, 'getFoo'), '->can() returns false if method does not match a field in the document');
$t->ok(!$retort->can($hit, 'fetchName'), '->can() returns false if method is invalid syntax');
$t->diag('->respond()');
$t->is($retort->respond($hit, 'getName'), 'carl', '->respond() returns the field response');
$t->is($retort->respond($hit, 'getCatName'), 'earl', '->respond() uses camel case');
 /**
  * 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;
 }
 public function build($input, xfDocument $doc)
 {
     $doc->addField(new xfFieldValue(new xfField('foobar', xfField::KEYWORD), 'bar'));
     $doc->addField(new xfFieldValue(new xfField('input', xfField::TEXT), $input));
     return $doc;
 }