mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-03-12 00:45:34 +00:00
implement Zend indexer as singleton in SeedDMS_Lucene_Indexer
This commit is contained in:
parent
3cc7497863
commit
593792089f
|
@ -29,10 +29,23 @@ class SeedDMS_Lucene_Indexer {
|
|||
*/
|
||||
protected $indexname;
|
||||
|
||||
/**
|
||||
* @var string $index lucene index
|
||||
* @access protected
|
||||
*/
|
||||
protected $index;
|
||||
|
||||
public function __construct($index) {
|
||||
$this->index = $index;
|
||||
}
|
||||
|
||||
static function open($conf) { /* {{{ */
|
||||
try {
|
||||
$index = Zend_Search_Lucene::open($conf['indexdir']);
|
||||
return($index);
|
||||
if($index)
|
||||
return new self($index);
|
||||
else
|
||||
return null;
|
||||
} catch (Exception $e) {
|
||||
return null;
|
||||
}
|
||||
|
@ -41,7 +54,10 @@ class SeedDMS_Lucene_Indexer {
|
|||
static function create($conf) { /* {{{ */
|
||||
try {
|
||||
$index = Zend_Search_Lucene::create($conf['indexdir']);
|
||||
return($index);
|
||||
if($index)
|
||||
return new self($index);
|
||||
else
|
||||
return null;
|
||||
} catch (Exception $e) {
|
||||
return null;
|
||||
}
|
||||
|
@ -62,6 +78,131 @@ class SeedDMS_Lucene_Indexer {
|
|||
Zend_Search_Lucene_Analysis_Analyzer::setDefault($analyzer);
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Add document to index
|
||||
*
|
||||
* @param object $doc indexed document of class
|
||||
* SeedDMS_Lucene_IndexedDocument
|
||||
* @return boolean false in case of an error, otherwise true
|
||||
*/
|
||||
function addDocument($doc) { /* {{{ */
|
||||
if(!$this->index)
|
||||
return false;
|
||||
|
||||
return $this->index->addDocument($doc);
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Remove document from index
|
||||
*
|
||||
* @param object $id internal id of document
|
||||
* @return boolean false in case of an error, otherwise true
|
||||
*/
|
||||
public function delete($id) { /* {{{ */
|
||||
if(!$this->index)
|
||||
return false;
|
||||
|
||||
return $this->index->delete($id);
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Check if document was deleted
|
||||
*
|
||||
* @param object $id internal id of document
|
||||
* @return boolean true if document was deleted
|
||||
*/
|
||||
public function isDeleted($id) { /* {{{ */
|
||||
if(!$this->index)
|
||||
return false;
|
||||
|
||||
return $this->index->isDeleted($id);
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Search in index
|
||||
*
|
||||
* @param string $query
|
||||
* @return array result
|
||||
*/
|
||||
public function find($query) { /* {{{ */
|
||||
if(!$this->index)
|
||||
return false;
|
||||
|
||||
return $this->index->find($query);
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Get a single document from index
|
||||
*
|
||||
* @param string $id id of document
|
||||
* @return boolean false in case of an error, otherwise true
|
||||
*/
|
||||
public function findById($id) { /* {{{ */
|
||||
if(!$this->index)
|
||||
return false;
|
||||
|
||||
return $this->index->findById($id);
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Get a single document from index
|
||||
*
|
||||
* @param integer $id id of index record
|
||||
* @return boolean false in case of an error, otherwise true
|
||||
*/
|
||||
public function getDocument($id, $content=true) { /* {{{ */
|
||||
if(!$this->index)
|
||||
return false;
|
||||
|
||||
return $this->index->getDocument($id);
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Return list of terms in index
|
||||
*
|
||||
* @return array list of Zend_Lucene_Term
|
||||
*/
|
||||
public function terms($prefix='', $col='') { /* {{{ */
|
||||
if(!$this->index)
|
||||
return false;
|
||||
|
||||
return $this->index->terms();
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Return number of documents in index
|
||||
*
|
||||
* @return interger number of documents
|
||||
*/
|
||||
public function count() { /* {{{ */
|
||||
if(!$this->index)
|
||||
return false;
|
||||
|
||||
return $this->index->count();
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Commit changes
|
||||
*
|
||||
* This function does nothing!
|
||||
*/
|
||||
function commit() { /* {{{ */
|
||||
if(!$this->index)
|
||||
return false;
|
||||
|
||||
return $this->index->commit();
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Optimize index
|
||||
*
|
||||
* This function does nothing!
|
||||
*/
|
||||
function optimize() { /* {{{ */
|
||||
if(!$this->index)
|
||||
return false;
|
||||
|
||||
return $this->index->optimize();
|
||||
} /* }}} */
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue
Block a user