diff --git a/CHANGELOG b/CHANGELOG index 87c0330ec..a9cb46f67 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -205,7 +205,8 @@ - add filter function to notification service - reindex document after it was edited - show preview images in drop folder menu after mouse over -- add support for indexing folders +- add support for indexing folders in fulltext search +- add support for start folder in fulltext search - always call hook postAddSubFolder and postEditDocument -------------------------------------------------------------------------------- diff --git a/SeedDMS_Lucene/Lucene/IndexedDocument.php b/SeedDMS_Lucene/Lucene/IndexedDocument.php index 91fee036e..45ba309b8 100644 --- a/SeedDMS_Lucene/Lucene/IndexedDocument.php +++ b/SeedDMS_Lucene/Lucene/IndexedDocument.php @@ -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())); diff --git a/SeedDMS_Lucene/Lucene/Search.php b/SeedDMS_Lucene/Lucene/Search.php index 5911360e3..2d13d3e73 100644 --- a/SeedDMS_Lucene/Lucene/Search.php +++ b/SeedDMS_Lucene/Lucene/Search.php @@ -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 { diff --git a/SeedDMS_SQLiteFTS/SQLiteFTS/IndexedDocument.php b/SeedDMS_SQLiteFTS/SQLiteFTS/IndexedDocument.php index fe567583d..d01297242 100644 --- a/SeedDMS_SQLiteFTS/SQLiteFTS/IndexedDocument.php +++ b/SeedDMS_SQLiteFTS/SQLiteFTS/IndexedDocument.php @@ -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); } diff --git a/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php b/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php index 0f135b208..6b209cb58 100644 --- a/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php +++ b/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php @@ -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; } /* }}} */ diff --git a/SeedDMS_SQLiteFTS/SQLiteFTS/Search.php b/SeedDMS_SQLiteFTS/SQLiteFTS/Search.php index 75b840b1e..0d951aad6 100644 --- a/SeedDMS_SQLiteFTS/SQLiteFTS/Search.php +++ b/SeedDMS_SQLiteFTS/SQLiteFTS/Search.php @@ -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(); diff --git a/out/out.Search.php b/out/out.Search.php index 8b52811c5..2c7afe2cf 100644 --- a/out/out.Search.php +++ b/out/out.Search.php @@ -166,6 +166,19 @@ if(((!isset($_GET["fullsearch"]) && $settings->_defaultSearchMethod == 'fulltext $status[] = S_EXPIRED; } + // Check to see if the search has been restricted to a particular sub-tree in + // the folder hierarchy. + $startFolder = null; + if (isset($_GET["targetid"]) && is_numeric($_GET["targetid"]) && $_GET["targetid"]>0) { + $targetid = $_GET["targetid"]; + $startFolder = $dms->getFolder($targetid); + if (!is_object($startFolder)) { + UI::exitError(getMLText("search"),getMLText("invalid_folder_id")); + } + } + + $rootFolder = $dms->getFolder($settings->_rootFolderID); + $startTime = getTime(); if($settings->_fullSearchEngine == 'lucene') { Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8'); @@ -183,7 +196,7 @@ if(((!isset($_GET["fullsearch"]) && $settings->_defaultSearchMethod == 'fulltext if($index) { $limit = 20; $lucenesearch = $fulltextservice->Search(); - $searchresult = $lucenesearch->search($query, array('owner'=>$owner, 'status'=>$status, 'category'=>$categorynames, 'user'=>$user->isAdmin() ? [] : [$user->getLogin()], 'mimetype'=>$mimetype), ($pageNumber == 'all' ? array() : array('limit'=>$limit, 'offset'=>$limit * ($pageNumber-1)))); + $searchresult = $lucenesearch->search($query, array('owner'=>$owner, 'status'=>$status, 'category'=>$categorynames, 'user'=>$user->isAdmin() ? [] : [$user->getLogin()], 'mimetype'=>$mimetype, 'startFolder'=>$startFolder, 'rootFolder'=>$rootFolder), ($pageNumber == 'all' ? array() : array('limit'=>$limit, 'offset'=>$limit * ($pageNumber-1)))); if($searchresult === false) { $session->setSplashMsg(array('type'=>'error', 'msg'=>getMLText('splash_invalid_searchterm'))); $dcount = 0;