Commit 8000e8d1c496c40375ea95f16c3dd7b12ec0350a
1 parent
009516cd
add simple folder search.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5413 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
5 changed files
with
79 additions
and
6 deletions
docs/VERSION.txt
lib/browse/BrowseColumns.inc.php
| @@ -124,7 +124,11 @@ class TitleColumn extends BrowseColumn { | @@ -124,7 +124,11 @@ class TitleColumn extends BrowseColumn { | ||
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | function buildFolderLink($aDataRow) { | 126 | function buildFolderLink($aDataRow) { |
| 127 | - return KTUtil::addQueryStringSelf('fFolderId='.$aDataRow["folder"]->getId()); | 127 | + if (is_null(KTUtil::arrayGet($this->aOptions, 'direct_folder'))) { |
| 128 | + return KTUtil::addQueryStringSelf('fFolderId='.$aDataRow["folder"]->getId()); | ||
| 129 | + } else { | ||
| 130 | + return KTBrowseUtil::getUrlForFolder($aDataRow['folder']); | ||
| 131 | + } | ||
| 128 | } | 132 | } |
| 129 | 133 | ||
| 130 | // use inline, since its just too heavy to even _think_ about using smarty. | 134 | // use inline, since its just too heavy to even _think_ about using smarty. |
lib/browse/DocumentCollection.inc.php
| @@ -167,7 +167,7 @@ class DocumentCollection { | @@ -167,7 +167,7 @@ class DocumentCollection { | ||
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | } | 169 | } |
| 170 | - | 170 | + //var_dump($folderSet); |
| 171 | $this->activeset = array( | 171 | $this->activeset = array( |
| 172 | "folders" => $folderSet, | 172 | "folders" => $folderSet, |
| 173 | "documents" => $documentSet, | 173 | "documents" => $documentSet, |
lib/browse/PartialQuery.inc.php
| @@ -39,6 +39,8 @@ require_once(KT_LIB_DIR . "/util/ktutil.inc"); | @@ -39,6 +39,8 @@ require_once(KT_LIB_DIR . "/util/ktutil.inc"); | ||
| 39 | require_once(KT_LIB_DIR . "/database/dbutil.inc"); | 39 | require_once(KT_LIB_DIR . "/database/dbutil.inc"); |
| 40 | require_once(KT_LIB_DIR . "/search/searchutil.inc.php"); | 40 | require_once(KT_LIB_DIR . "/search/searchutil.inc.php"); |
| 41 | 41 | ||
| 42 | +define('XXX_HARDCODE_SIMPLE_FOLDER_SEARCH', true); | ||
| 43 | + | ||
| 42 | // Abstract base class. | 44 | // Abstract base class. |
| 43 | class PartialQuery { | 45 | class PartialQuery { |
| 44 | // initialise here (pass whatever this needs) | 46 | // initialise here (pass whatever this needs) |
| @@ -254,14 +256,70 @@ class SimpleSearchQuery extends PartialQuery { | @@ -254,14 +256,70 @@ class SimpleSearchQuery extends PartialQuery { | ||
| 254 | var $searchable_text; | 256 | var $searchable_text; |
| 255 | 257 | ||
| 256 | function SimpleSearchQuery($sSearchableText) { $this->searchable_text = $sSearchableText; } | 258 | function SimpleSearchQuery($sSearchableText) { $this->searchable_text = $sSearchableText; } |
| 259 | + | ||
| 260 | + function _getFolderQuery($aOptions = null) { | ||
| 261 | + $res = KTSearchUtil::permissionToSQL($this->oUser, $this->sPermissionName, "F"); | ||
| 262 | + if (PEAR::isError($res)) { | ||
| 263 | + return $res; | ||
| 264 | + } | ||
| 265 | + list($sPermissionString, $aPermissionParams, $sPermissionJoin) = $res; | ||
| 266 | + | ||
| 267 | + $aPotentialWhere = array('MATCH (FST.folder_text) AGAINST (? IN BOOLEAN MODE) <> 0',$sPermissionString); | ||
| 268 | + $aWhere = array(); | ||
| 269 | + foreach ($aPotentialWhere as $sWhere) { | ||
| 270 | + if (empty($sWhere)) { | ||
| 271 | + continue; | ||
| 272 | + } | ||
| 273 | + if ($sWhere == "()") { | ||
| 274 | + continue; | ||
| 275 | + } | ||
| 276 | + $aWhere[] = $sWhere; | ||
| 277 | + } | ||
| 278 | + $sWhere = ""; | ||
| 279 | + if ($aWhere) { | ||
| 280 | + $sWhere = "\tWHERE " . join(" AND ", $aWhere); | ||
| 281 | + } | ||
| 282 | + | ||
| 283 | + $sSelect = KTUtil::arrayGet($aOptions, 'select', 'F.id'); | ||
| 284 | + | ||
| 285 | + $sQuery = "SELECT $sSelect FROM " . KTUtil::getTableName("folders") . " AS F | ||
| 286 | + LEFT JOIN " . KTUtil::getTableName("folder_searchable_text") . " AS FST ON (F.id = FST.folder_id) | ||
| 287 | + $sPermissionJoin $sWhere "; | ||
| 288 | + $aParams = array($this->searchable_text); | ||
| 289 | + $aParams = kt_array_merge($aParams, $aPermissionParams); | ||
| 290 | + return array($sQuery, $aParams); | ||
| 291 | + } | ||
| 257 | 292 | ||
| 258 | function getFolderCount() { | 293 | function getFolderCount() { |
| 259 | - // never any folders, given the current fulltext environ. | ||
| 260 | - return 0; | 294 | + // use hack to get folders, if included. |
| 295 | + if (!XXX_HARDCODE_SIMPLE_FOLDER_SEARCH) { return 0; } | ||
| 296 | + | ||
| 297 | + $aOptions = array( | ||
| 298 | + 'select' => 'count(F.id) AS cnt', | ||
| 299 | + ); | ||
| 300 | + $aQuery = $this->_getFolderQuery($aOptions); | ||
| 301 | + if (PEAR::isError($aQuery)) { return 0; } | ||
| 302 | + $iRet = DBUtil::getOneResultKey($aQuery, 'cnt'); | ||
| 303 | + return $iRet; | ||
| 261 | } | 304 | } |
| 262 | 305 | ||
| 263 | function getFolders($iBatchSize, $iBatchStart, $sSortColumn, $sSortOrder, $sJoinClause = null, $aJoinParams = null) { | 306 | function getFolders($iBatchSize, $iBatchStart, $sSortColumn, $sSortOrder, $sJoinClause = null, $aJoinParams = null) { |
| 264 | - return array(); | 307 | + if (!XXX_HARDCODE_SIMPLE_FOLDER_SEARCH) { return array(); } |
| 308 | + | ||
| 309 | + $res = $this->_getFolderQuery(); | ||
| 310 | + if (PEAR::isError($res)) { return array(); } | ||
| 311 | + list($sQuery, $aParams) = $res; | ||
| 312 | + $sQuery .= " ORDER BY " . $sSortColumn . " " . $sSortOrder . " "; | ||
| 313 | + | ||
| 314 | + $sQuery .= " LIMIT ?, ?"; | ||
| 315 | + $aParams[] = $iBatchStart; | ||
| 316 | + $aParams[] = $iBatchSize; | ||
| 317 | + | ||
| 318 | + $q = array($sQuery, $aParams); | ||
| 319 | + | ||
| 320 | + $res = DBUtil::getResultArray($q); | ||
| 321 | + | ||
| 322 | + return $res; | ||
| 265 | } | 323 | } |
| 266 | 324 | ||
| 267 | function getQuery($aOptions = null) { | 325 | function getQuery($aOptions = null) { |
sql/mysql/upgrade/3.0.2.2/folder_search.sql
0 → 100644
| 1 | +CREATE TABLE folder_searchable_text ( | ||
| 2 | + `folder_id` INT(11) NOT NULL DEFAULT 0, | ||
| 3 | + PRIMARY KEY(folder_id), | ||
| 4 | + `folder_text` text, | ||
| 5 | + KEY `folder_searchable_text_folder_indx` (`folder_id`), | ||
| 6 | + FULLTEXT KEY `folder_text` (`folder_text`) | ||
| 7 | +) Type=MyISAM; | ||
| 8 | + | ||
| 9 | +-- generate the data | ||
| 10 | + | ||
| 11 | +insert into folder_searchable_text (folder_id, folder_text) SELECT id, name from folders; |