/** * 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']; }
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(); $t->isa_ok($engine->getIndex(), 'Zend_Search_Lucene', '->open() can reopen the index'); $t->diag('->getAnalyzer(), ->setAnalyzer()'); $t->isa_ok($engine->getAnalyzer(), 'Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive', '->getAnalyzer() is UTF8, number, and case insensitive by default');
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'); $t->ok($hits->valid(), '->valid() returns true if key exists'); $hits->next(); $t->is($hits->key(), 1, '->next() advances the key by one'); $t->ok(!$hits->valid(), '->valid() returns false if key does not exist'); $hits->rewind();