pass a config array to search engine, search returns hits and total count

This commit is contained in:
Uwe Steinmann 2020-09-10 15:26:40 +02:00
parent e3e46b853d
commit 1fda490bbe
9 changed files with 66 additions and 63 deletions

View File

@ -29,17 +29,17 @@ class SeedDMS_Lucene_Indexer {
*/
protected $indexname;
static function open($luceneDir) { /* {{{ */
static function open($conf) { /* {{{ */
try {
$index = Zend_Search_Lucene::open($luceneDir);
$index = Zend_Search_Lucene::open($conf['indexdir']);
return($index);
} catch (Exception $e) {
return null;
}
} /* }}} */
static function create($luceneDir) { /* {{{ */
$index = Zend_Search_Lucene::create($luceneDir);
static function create($conf) { /* {{{ */
$index = Zend_Search_Lucene::create($conf['indexdir']);
return($index);
} /* }}} */

View File

@ -93,7 +93,7 @@ class SeedDMS_Lucene_Search {
foreach($hits as $hit) {
$recs[] = array('id'=>$hit->id, 'document_id'=>$hit->document_id);
}
return $recs;
return array('count'=>count($hits), 'hits'=>$recs);
} catch (Zend_Search_Lucene_Exception $e) {
return false;
}

View File

@ -42,22 +42,22 @@ class SeedDMS_SQLiteFTS_Indexer {
*
* @param string $indexerDir directory on disk containing the index
*/
static function open($indexerDir) { /* {{{ */
if(file_exists($indexerDir.'/index.db')) {
return new SeedDMS_SQLiteFTS_Indexer($indexerDir);
static function open($conf) { /* {{{ */
if(file_exists($conf['indexdir'].'/index.db')) {
return new SeedDMS_SQLiteFTS_Indexer($conf['indexdir']);
} else
return self::create($indexerDir);
return self::create($conf['indexdir']);
} /* }}} */
/**
* Create a new index
*
* @param string $indexerDir directory on disk containing the index
* @param array $conf $conf['indexdir'] is the directory on disk containing the index
*/
static function create($indexerDir) { /* {{{ */
if(file_exists($indexerDir.'/index.db'))
unlink($indexerDir.'/index.db');
$index = new SeedDMS_SQLiteFTS_Indexer($indexerDir);
static function create($conf) { /* {{{ */
if(file_exists($conf['indexdir'].'/index.db'))
unlink($conf['indexdir'].'/index.db');
$index = new SeedDMS_SQLiteFTS_Indexer($conf['indexdir']);
/* Make sure the sequence of fields is identical to the field list
* in SeedDMS_SQLiteFTS_Term
*/
@ -153,7 +153,7 @@ class SeedDMS_SQLiteFTS_Indexer {
$hits[] = $hit;
}
}
return $hits;
return array('count'=>count($hits), 'hits'=>$hits);
} /* }}} */
/**

View File

@ -90,12 +90,12 @@ class SeedDMS_SQliteFTS_Search {
$querystr .= '';
}
try {
$hits = $this->index->find($querystr);
$result = $this->index->find($querystr);
$recs = array();
foreach($hits as $hit) {
foreach($result["hits"] as $hit) {
$recs[] = array('id'=>$hit->id, 'document_id'=>$hit->id);
}
return $recs;
return array('count'=>$result['count'], 'hits'=>$recs);
} catch (Exception $e) {
return false;
}

View File

@ -36,12 +36,16 @@ class SeedDMS_FulltextService {
*/
protected $maxsize;
private $index;
private $search;
public function __construct() {
$this->services = array();
$this->converters = array();
$this->maxsize = 0;
$this->indexdir = '';
$this->index = null;
$this->search = null;
$this->cmdtimeout = 5;
}
@ -57,10 +61,6 @@ class SeedDMS_FulltextService {
$this->maxsize = $maxsize;
}
public function setIndexDir($indexdir) {
$this->indexdir = $indexdir;
}
public function setCmdTimeout($timeout) {
$this->cmdtimeout = $timeout;
}
@ -74,18 +74,25 @@ class SeedDMS_FulltextService {
if($this->index)
return $this->index;
if($this->indexdir) {
if($this->services[0]) {
if($recreate)
$this->index = $this->services[0]['Indexer']::create($this->indexdir);
$this->index = $this->services[0]['Indexer']::create($this->services[0]['Conf']);
else
$this->index = $this->services[0]['Indexer']::open($this->indexdir);
$this->index = $this->services[0]['Indexer']::open($this->services[0]['Conf']);
return $this->index;
} else
return null;
}
public function Search() {
return new $this->services[0]['Search']($this->index);
if($this->search)
return $this->search;
if($this->services[0]) {
$this->search = new $this->services[0]['Search']($this->index);
return $this->search;
} else {
return null;
}
}
}

View File

@ -46,8 +46,6 @@ if(!$index) {
}
if($view) {
$view->setParam('luceneclassdir', $settings->_luceneClassDir);
$view->setParam('lucenedir', $settings->_luceneDir);
$view->setParam('index', $index);
$view($_GET);
exit;

View File

@ -128,23 +128,23 @@ if(isset($_GET["fullsearch"]) && $_GET["fullsearch"] && $settings->_enableFullSe
$startTime = getTime();
$index = $fulltextservice->Indexer();
$lucenesearch = $fulltextservice->Search();
$hits = $lucenesearch->search($query, $owner ? $owner->getLogin() : '', '', $categorynames, array(), $user->isAdmin() ? [] : [$user->getLogin()]);
if($hits === false) {
$searchresult = $lucenesearch->search($query, $owner ? $owner->getLogin() : '', '', $categorynames, array(), $user->isAdmin() ? [] : [$user->getLogin()]);
if($searchresult === false) {
$session->setSplashMsg(array('type'=>'error', 'msg'=>getMLText('splash_invalid_searchterm')));
$totalPages = 0;
$entries = array();
$searchTime = 0;
} else {
$entries = array();
$dcount = 0;
$dcount = $searchresult['count']; //0;
$fcount = 0;
if($hits) {
foreach($hits as $hit) {
if($searchresult) {
foreach($searchresult['hits'] as $hit) {
if($tmp = $dms->getDocument($hit['document_id'])) {
if($tmp->getAccessMode($user) >= M_READ) {
$tmp->verifyLastestContentExpriry();
$entries[] = $tmp;
$dcount++;
// $dcount++;
}
}
}

View File

@ -34,8 +34,6 @@ class SeedDMS_View_IndexInfo extends SeedDMS_Bootstrap_Style {
function show() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
$luceneclassdir = $this->params['luceneclassdir'];
$lucenedir = $this->params['lucenedir'];
$index = $this->params['index'];
$this->htmlStartPage(getMLText('fulltext_info'));
@ -49,8 +47,8 @@ class SeedDMS_View_IndexInfo extends SeedDMS_Bootstrap_Style {
$this->contentContainerStart();
for ($id = 0; $id < $numDocs; $id++) {
if (!$index->isDeleted($id)) {
$hit = $index->getDocument($id);
echo "<span title=\"".$hit->document_id."\">".htmlspecialchars($hit->title)."</span>\n";
if($hit = $index->getDocument($id))
echo "<span title=\"".$hit->document_id."\">".htmlspecialchars($hit->title)."</span>\n";
}
}
$this->contentContainerEnd();
@ -67,7 +65,7 @@ class SeedDMS_View_IndexInfo extends SeedDMS_Bootstrap_Style {
$this->contentContainerStart();
$field = $term->field;
}
echo htmlspecialchars($term->text)."\n";
echo "<span title=\"".$term->_occurrence."\">".htmlspecialchars($term->text)."</span>\n";
}
$this->contentContainerEnd();
// echo "</pre>";

View File

@ -37,34 +37,34 @@ class SeedDMS_View_Indexer_Process_Folder { /* {{{ */
public function process($folder) { /* {{{ */
$documents = $folder->getDocuments();
if($documents) {
$lucenesearch = $this->fulltextservice->Search();
echo "<div class=\"folder\">".$folder->getFolderPathPlain()."</div>";
foreach($documents as $document) {
echo "<div class=\"document\">".$document->getId().":".htmlspecialchars($document->getName());
/* If the document wasn't indexed before then just add it */
$lucenesearch = $this->fulltextservice->Search();
if(!($hit = $lucenesearch->getDocument($document->getId()))) {
echo " <span id=\"status_".$document->getID()."\" class=\"indexme indexstatus\" data-docid=\"".$document->getID()."\">".getMLText('index_waiting')."</span>";
} else {
/* Check if the attribute created is set or has a value older
* than the lastet content. Documents without such an attribute
* where added when a new document was added to the dms. In such
* a case the document content wasn't indexed.
*/
try {
$created = (int) $hit->getDocument()->getFieldValue('created');
} catch (/* Zend_Search_Lucene_ */Exception $e) {
$created = 0;
}
$content = $document->getLatestContent();
if($created >= $content->getDate() && !$this->forceupdate) {
echo "<span id=\"status_".$document->getID()."\" class=\"indexstatus\" data-docid=\"".$document->getID()."\">".getMLText('index_document_unchanged')."</span>";
} else {
$this->fulltextservice->Indexer()->delete($hit->id);
echo "<div class=\"document\">".$document->getId().":".htmlspecialchars($document->getName());
/* If the document wasn't indexed before then just add it */
if(!($hit = $lucenesearch->getDocument($document->getId()))) {
echo " <span id=\"status_".$document->getID()."\" class=\"indexme indexstatus\" data-docid=\"".$document->getID()."\">".getMLText('index_waiting')."</span>";
} else {
/* Check if the attribute created is set or has a value older
* than the lastet content. Documents without such an attribute
* where added when a new document was added to the dms. In such
* a case the document content wasn't indexed.
*/
try {
$created = (int) $hit->getDocument()->getFieldValue('created');
} catch (/* Zend_Search_Lucene_ */Exception $e) {
$created = 0;
}
$content = $document->getLatestContent();
if($created >= $content->getDate() && !$this->forceupdate) {
echo "<span id=\"status_".$document->getID()."\" class=\"indexstatus\" data-docid=\"".$document->getID()."\">".getMLText('index_document_unchanged')."</span>";
} else {
$this->fulltextservice->Indexer()->delete($hit->id);
echo " <span id=\"status_".$document->getID()."\" class=\"indexme indexstatus\" data-docid=\"".$document->getID()."\">".getMLText('index_waiting')."</span>";
}
}
echo "</div>";
}
echo "</div>";
}
}
} /* }}} */
} /* }}} */