/**
  * Magic method for unserializing
  *
  * @param string $serialized The serialized string
  */
 public function unserialize($serialized)
 {
     $data = unserialize($serialized);
     $this->engine = $data['engine'];
     foreach ($data['cache'] as $id => $score) {
         $hit = new Zend_Search_Lucene_Search_QueryHit($this->engine->getIndex());
         $hit->id = $id;
         $hit->score = $score;
         $this->hits[] = $hit;
     }
     $this->pointer = $data['pointer'];
 }
require 'result/xfResultException.class.php';
require 'addon/xfLuceneEnhancedFilesystem.class.php';
define('LOCATION', dirname(__FILE__) . '/../../sandbox/index');
if (is_dir(LOCATION)) {
    // clear the old index first
    foreach (new DirectoryIterator(LOCATION) as $file) {
        if ($file->isDot()) {
            continue;
        }
        unlink($file->getRealpath());
    }
} else {
    mkdir(LOCATION, 0777, true);
}
$t = new lime_test(69, new lime_output_color());
$engine = new xfLuceneEngine(LOCATION);
$t->diag('->open(), ->close()');
$engine->open();
$index = $engine->getIndex();
$t->isa_ok($index, 'Zend_Search_Lucene', '->open() opens the index');
$engine->open();
$t->ok($index === $engine->getIndex(), '->open() does not open another index if it is already open');
$engine->close();
try {
    $msg = '->close() closes the index';
    $engine->getIndex();
    $t->fail($msg);
} catch (Exception $e) {
    $t->pass($msg);
}
$engine->open();
Ejemplo n.º 3
0
 */
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');
$t->diag('->key(), ->next(), ->valid(), ->rewind(), ->seek()');
$t->is($hits->key(), 0, '->key() returns the current key');