add path to index

This commit is contained in:
Uwe Steinmann 2020-12-17 18:33:16 +01:00
parent d9fa867582
commit b6b2b7e9a2
5 changed files with 38 additions and 5 deletions

View File

@ -128,6 +128,7 @@ class SeedDMS_Lucene_IndexedDocument extends Zend_Search_Lucene_Document {
if($comment = $document->getComment()) {
$this->addField(Zend_Search_Lucene_Field::Text('comment', $comment, 'utf-8'));
}
$this->addField(Zend_Search_Lucene_Field::Keyword('path', $document->getFolderList()));
if($document->isType('document')) {
$this->addField(Zend_Search_Lucene_Field::Keyword('document_id', 'D'.$document->getID()));

View File

@ -110,6 +110,21 @@ class SeedDMS_Lucene_Search {
$querystr .= implode('" || users:"', $fields['user']);
$querystr .= '")';
}
if(!empty($fields['rootFolder']) && $fields['rootFolder']->getFolderList()) {
if($querystr)
$querystr .= ' && ';
$querystr .= '(path:"';
$querystr .= $fields['rootFolder']->getFolderList().$fields['rootFolder']->getID().':';
$querystr .= '")';
}
if(!empty($fields['startFolder']) && $fields['startFolder']->getFolderList()) {
if($querystr)
$querystr .= ' && ';
$querystr .= '(path:"';
$querystr .= $fields['startFolder']->getFolderList().$fields['startFolder']->getID().':';
$querystr .= '")';
}
echo $querystr;
try {
$query = Zend_Search_Lucene_Search_QueryParser::parse($querystr);
try {

View File

@ -119,6 +119,7 @@ class SeedDMS_SQLiteFTS_IndexedDocument extends SeedDMS_SQLiteFTS_Document {
}
$owner = $document->getOwner();
$this->addField('owner', $owner->getLogin());
$this->addField('path', $document->getFolderList());
if($comment = $document->getComment()) {
$this->addField('comment', $comment);
}

View File

@ -63,9 +63,9 @@ class SeedDMS_SQLiteFTS_Indexer {
*/
$version = SQLite3::version();
if($version['versionNumber'] >= 3008000)
$sql = 'CREATE VIRTUAL TABLE docs USING fts4(documentid, title, comment, keywords, category, mimetype, origfilename, owner, content, created, users, status, notindexed=created, matchinfo=fts3)';
$sql = 'CREATE VIRTUAL TABLE docs USING fts4(documentid, title, comment, keywords, category, mimetype, origfilename, owner, content, created, users, status, path, notindexed=created, matchinfo=fts3)';
else
$sql = 'CREATE VIRTUAL TABLE docs USING fts4(documentid, title, comment, keywords, category, mimetype, origfilename, owner, content, created, users, status, matchinfo=fts3)';
$sql = 'CREATE VIRTUAL TABLE docs USING fts4(documentid, title, comment, keywords, category, mimetype, origfilename, owner, content, created, users, status, path, matchinfo=fts3)';
$res = $index->_conn->exec($sql);
if($res === false) {
return null;
@ -96,7 +96,7 @@ class SeedDMS_SQLiteFTS_Indexer {
if(!$this->_conn)
return false;
$sql = "INSERT INTO docs (documentid, title, comment, keywords, category, owner, content, mimetype, origfilename, created, users, status) VALUES (".$this->_conn->quote($doc->getFieldValue('document_id')).", ".$this->_conn->quote($doc->getFieldValue('title')).", ".$this->_conn->quote($doc->getFieldValue('comment')).", ".$this->_conn->quote($doc->getFieldValue('keywords')).", ".$this->_conn->quote($doc->getFieldValue('category')).", ".$this->_conn->quote($doc->getFieldValue('owner')).", ".$this->_conn->quote($doc->getFieldValue('content')).", ".$this->_conn->quote($doc->getFieldValue('mimetype')).", ".$this->_conn->quote($doc->getFieldValue('origfilename')).", ".(int)$doc->getFieldValue('created').", ".$this->_conn->quote($doc->getFieldValue('users')).", ".$this->_conn->quote($doc->getFieldValue('status'))/*time()*/.")";
$sql = "INSERT INTO docs (documentid, title, comment, keywords, category, owner, content, mimetype, origfilename, created, users, status, path) VALUES (".$this->_conn->quote($doc->getFieldValue('document_id')).", ".$this->_conn->quote($doc->getFieldValue('title')).", ".$this->_conn->quote($doc->getFieldValue('comment')).", ".$this->_conn->quote($doc->getFieldValue('keywords')).", ".$this->_conn->quote($doc->getFieldValue('category')).", ".$this->_conn->quote($doc->getFieldValue('owner')).", ".$this->_conn->quote($doc->getFieldValue('content')).", ".$this->_conn->quote($doc->getFieldValue('mimetype')).", ".$this->_conn->quote($doc->getFieldValue('origfilename')).", ".(int)$doc->getFieldValue('created').", ".$this->_conn->quote($doc->getFieldValue('users')).", ".$this->_conn->quote($doc->getFieldValue('status')).", ".$this->_conn->quote($doc->getFieldValue('path'))/*time()*/.")";
$res = $this->_conn->exec($sql);
if($res === false) {
return false;
@ -204,7 +204,7 @@ class SeedDMS_SQLiteFTS_Indexer {
if(!$this->_conn)
return false;
$sql = "SELECT docid, documentid, title, comment, owner, keywords, category, mimetype, origfilename, created, users, status FROM docs WHERE docid=".$id;
$sql = "SELECT docid, documentid, title, comment, owner, keywords, category, mimetype, origfilename, created, users, status, path FROM docs WHERE docid=".$id;
$res = $this->_conn->query($sql);
$doc = false;
if($res) {
@ -222,6 +222,7 @@ class SeedDMS_SQLiteFTS_Indexer {
$doc->addField('created', $rec['created']);
$doc->addField('users', $rec['users']);
$doc->addField('status', $rec['status']);
$doc->addField('path', $rec['path']);
}
return $doc;
} /* }}} */
@ -236,7 +237,7 @@ class SeedDMS_SQLiteFTS_Indexer {
if(!$this->_conn)
return false;
$sql = "SELECT docid, documentid, title, comment, owner, keywords, category, mimetype, origfilename, created, users, status FROM docs WHERE documentid='F".$id."'";
$sql = "SELECT docid, documentid, title, comment, owner, keywords, category, mimetype, origfilename, created, users, status, path FROM docs WHERE documentid='F".$id."'";
$res = $this->_conn->query($sql);
$doc = false;
if($res) {
@ -249,6 +250,7 @@ class SeedDMS_SQLiteFTS_Indexer {
$doc->addField('owner', $rec['owner']);
$doc->addField('created', $rec['created']);
$doc->addField('users', $rec['users']);
$doc->addField('path', $rec['path']);
}
return $doc;
} /* }}} */

View File

@ -111,6 +111,20 @@ class SeedDMS_SQliteFTS_Search {
$querystr .= implode(' OR users:', $fields['user']);
$querystr .= ')';
}
if(!empty($fields['rootFolder']) && $fields['rootFolder']->getFolderList()) {
if($querystr)
$querystr .= ' ';
$querystr .= '(path:';
$querystr .= $fields['rootFolder']->getFolderList().$fields['rootFolder']->getID().':';
$querystr .= ')';
}
if(!empty($fields['startFolder']) && $fields['startFolder']->getFolderList()) {
if($querystr)
$querystr .= ' ';
$querystr .= '(path:';
$querystr .= $fields['startFolder']->getFolderList().$fields['startFolder']->getID().':';
$querystr .= ')';
}
try {
$result = $this->index->find($querystr, $limit);
$recs = array();