From 13af82b7eeb2bb16f1a6fe53fd213d6d77920d98 Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 24 Jun 2003 11:00:05 +0000 Subject: [PATCH] Altered search query to improve performance --- presentation/lookAndFeel/knowledgeTree/search/standardSearchBL.php | 259 ++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- presentation/lookAndFeel/knowledgeTree/search/standardSearchUI.inc | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 121 insertions(+), 239 deletions(-) diff --git a/presentation/lookAndFeel/knowledgeTree/search/standardSearchBL.php b/presentation/lookAndFeel/knowledgeTree/search/standardSearchBL.php index db1af2f..8f1bfa3 100644 --- a/presentation/lookAndFeel/knowledgeTree/search/standardSearchBL.php +++ b/presentation/lookAndFeel/knowledgeTree/search/standardSearchBL.php @@ -13,7 +13,6 @@ * */ require_once("../../../../config/dmsDefaults.php"); - if (checkSession()) { require_once("$default->fileSystemRoot/lib/visualpatterns/PatternBrowsableSearchResults.inc"); require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); @@ -29,272 +28,74 @@ if (checkSession()) { $fStandardSearchString = addslashes($fStandardSearchString); if (strlen($fBrowseType) > 0) { + echo "browse type"; //the user was browsing by a specific type switch ($fBrowseType) { case "folder" : - //user was browsing a specific folder - search that folder + //user was browsing a specific folder - search that folder if (!$fFolderID) { //start at the root folder $fFolderID = 0; - $sFolderString = getFolderString($fFolderID); - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); - $oPatternCustom = & new PatternCustom(); - //$oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fStandardSearchString))); - $oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, $fStandardSearchString)); - $main->setCentralPayload($oPatternCustom); - $main->render(); - } else { - $sFolderString = getFolderString($fFolderID); - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); - $oPatternCustom = & new PatternCustom(); - //$oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fStandardSearchString))); - $oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, $fStandardSearchString)); - $main->setCentralPayload($oPatternCustom); - $main->render(); - } + } + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); + $oPatternCustom = & new PatternCustom(); + $oPatternCustom->setHtml(getSeachResultsByFolder($fFolderID, $fStartIndex, $fStandardSearchString)); + $main->setCentralPayload($oPatternCustom); + $main->render(); break; case "category" : //user was browsing by category - search all documents in that category if (!$fCategoryName) { //no category name specified, so just start at the root folder $fFolderID = 0; - $sFolderString = getFolderString($fFolderID); - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); - $oPatternCustom = & new PatternCustom(); - //$oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fStandardSearchString))); - $oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, $fStandardSearchString)); - $main->setCentralPayload($oPatternCustom); - $main->render(); - } else { - $sFolderString = getFolderStringFromCategory($fCategoryName); - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); - $oPatternCustom = & new PatternCustom(); - //$oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fStandardSearchString))); - $oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, $fStandardSearchString)); - $main->setCentralPayload($oPatternCustom); - $main->render(); - } - break; - + } + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); + $oPatternCustom = & new PatternCustom(); + $oPatternCustom->setHtml(getSearchResultsByCategory($fFolderID, $fStandardSearchString, $fStartIndex, $fCategoryName)); + $main->setCentralPayload($oPatternCustom); + $main->render(); + break; case "documentType" : //user was browsing by document type - search all documents in that doc type if (!$fDocTypeID) { //no document type specified, so just start at the root folder $fFolderID = 0; - $sFolderString = getApprovedFolderString($fFolderID); - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); - $oPatternCustom = & new PatternCustom(); - //$oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fStandardSearchString))); - $oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, $fStandardSearchString)); - $main->setCentralPayload($oPatternCustom); - $main->render(); - } else { - $sDocumentString = getApprovedDocsDocType($fDocTypeID); - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); - $oPatternCustom = & new PatternCustom(); - //$oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sDocumentString, $fStartIndex, getSQLSearchString($fStandardSearchString), true)); - $oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sDocumentString, $fStartIndex, $fStandardSearchString, true)); - $main->setCentralPayload($oPatternCustom); - $main->render(); - } + } + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); + $oPatternCustom = & new PatternCustom(); + $oPatternCustom->setHtml(getSearchResultsByDocumentType($fFolderID, $fStandardSearchString, $fStartIndex, $fDocTypeID)); + $main->setCentralPayload($oPatternCustom); + $main->render(); break; default: //search from the root folder down i.e. all documents break; - } + } } else if (strlen($fFolderID) > 0) { - //the user was browsing a folder, search that folder - $sFolderString = getFolderString($fFolderID); + //the user was browsing a folder, search that folder require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); - $oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, $fStandardSearchString)); + $oPatternCustom->setHtml(getSeachResultsByFolder($fFolderID, $fStartIndex, $fStandardSearchString)); $main->setCentralPayload($oPatternCustom); $main->render(); } else if (strlen($fDocumentID) > 0) { //the user was viewing a document, search in that document's folder $oDocument = Document::get($fDocumentID); - //$sFolderString = getApprovedFolderString($oDocument->getFolderID()); - $sFolderString = getFolderString($oDocument->getFolderID()); require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); - $oPatternCustom = & new PatternCustom(); - //$oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fStandardSearchString))); - $oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, $fStandardSearchString)); - $main->setCentralPayload($oPatternCustom); - $main->setFormAction("addFolderBL.php?fFolderID=$fFolderID"); - $main->setHasRequiredFields(true); + $oPatternCustom = & new PatternCustom(); + $oPatternCustom->setHtml(getSeachResultsByFolder($oDocument->getFolderID(), $fStartIndex, $fStandardSearchString)); + $main->setCentralPayload($oPatternCustom); $main->render(); } else { - //search from the root folder down i.e. all documents + //search from the root folder down i.e. all documents $fFolderID = 0; - //$sFolderString = getApprovedFolderString($fFolderID); - $sFolderString = getFolderString($fFolderID); require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); - //$oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fStandardSearchString))); - $oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, $fStandardSearchString)); - $main->setCentralPayload($oPatternCustom); - $main->setFormAction("addFolderBL.php?fFolderID=$fFolderID"); - $main->setHasRequiredFields(true); + $oPatternCustom->setHtml(getSeachResultsByFolder($fFolderID, $fStartIndex, $fStandardSearchString)); + $main->setCentralPayload($oPatternCustom); $main->render(); } } - -function getFolderString($iFolderID) { - $aChildren = Folder::getChildren($iFolderID); - //add the folder we started on - $aChildren[count($aChildren)] = $iFolderID; - return implode(",", $aChildren); -} - -/* -function getApprovedFolderString($iFolderID) { - $aChildren = Folder::getChildren($iFolderID); - $aApprovedChildren = array(); - //filter out all the folders the user does - //not have permission to see - for ($i = 0; $i < count($aChildren); $i++) { - $oFolder = Folder::get($aChildren[$i]); - - //if the folder is already approved, continue - if (in_array($oFolder->getID(), $aApprovedChildren)) { - //echo "Already in: " . $oFolder->getID() . "
"; - continue; - } - - $aParentFolderIDs = explode(",",$oFolder->getParentFolderIDs()); - - //if one of the folder's parents is already approved, add the folder - for ($j = 0; $j < count($aParentFolderIDs); $j++) { - if (in_array($aParentFolderIDs[$j], $aApprovedChildren)) { - if (in_array($oFolder->getID(), $aApprovedChildren)) { - $aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID(); - } - continue; - } - } - - //check if the user has read permission for this folder - if (Permission::userHasFolderReadPermission($oFolder->getID())) { - $aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID(); - continue; - } - - } - return implode(",", $aApprovedChildren); -} - - -*/ - -function getFolderStringFromCategory($sCategory) { - global $default; - $sQuery = "SELECT DISTINCT D.folder_id " . - "FROM $default->owl_documents_table AS D inner join $default->owl_document_fields_table AS DFL ON D.id = DFL.document_id " . - "INNER JOIN $default->owl_fields_table AS DF ON DF.id = DFL.document_field_id " . - "WHERE DF.name LIKE 'Category' " . - "AND DFL.value LIKE '$sCategory'"; - - $sql = $default->db; - $sql->query($sQuery); - - if ($sql->next_record()) { - //get all the folders in the category - $aFolders = array($sql->f("folder_id")); - while ($sql->next_record()) { - $aFolders[count($aFolders)] = $sql->f("folder_id"); - } - return implode(",", $aFolders); - } - return "0"; - -} - -/*function getApprovedFolderStringFromCategory($sCategory) { - global $default; - $sQuery = "SELECT DISTINCT D.folder_id " . - "FROM $default->owl_documents_table AS D inner join $default->owl_document_fields_table AS DFL ON D.id = DFL.document_id " . - "INNER JOIN $default->owl_fields_table AS DF ON DF.id = DFL.document_field_id " . - "WHERE DF.name LIKE 'Category' " . - "AND DFL.value LIKE '$sCategory'"; - - $sql = $default->db; - $sql->query($sQuery); - if ($sql->next_record()) { - //get all the folders in the category - $aFolders = array($sql->f("folder_id")); - while ($sql->next_record()) { - $aFolders[count($aFolders)] = $sql->f("folder_id"); - } - - $aApprovedChildren = array(); - //filter out all the folders the user does - //not have permission to see - for ($i = 0; $i < count($aFolders); $i++) { - $oFolder = Folder::get($aFolders[$i]); - - //if the folder is already approved, continue - if (in_array($oFolder->getID(), $aApprovedChildren)) { - //echo "Already in: " . $oFolder->getID() . "
"; - continue; - } - - $aParentFolderIDs = explode(",",$oFolder->getParentFolderIDs()); - - //if one of the folder's parents is already approved, add the folder - for ($j = 0; $j < count($aParentFolderIDs); $j++) { - if (in_array($aParentFolderIDs[$j], $aApprovedChildren)) { - if (in_array($oFolder->getID(), $aApprovedChildren)) { - $aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID(); - } - continue; - } - } - - //check if the user has read permission for this folder - if (Permission::userHasFolderReadPermission($oFolder->getID())) { - $aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID(); - continue; - } - - } - return implode(",", $aApprovedChildren); - } - return "0"; -}*/ - -function getSQLSearchString($sSearchString) { - $aWords = explode(" ", $sSearchString); - $sSQLSearchString; - for ($i = 0; $i < count($aWords) - 1; $i++) { - $sSQLSearchString .= "(WL.word LIKE '%" . $aWords[$i] . "%') OR "; - } - $sSQLSearchString .= "(WL.word LIKE '%" . $aWords[count($aWords) -1] . "%')"; - return $sSQLSearchString; -} - -function searchByCategory($sCategoryName) { - -} - -function getApprovedDocsDocType($iDocTypeID) { - global $default; - $sQuery = "SELECT D.id " . - "FROM $default->owl_documents_table AS D " . - "WHERE D.document_type_id = $iDocTypeID"; - - $sql = $default->db; - $sql->query($sQuery); - while ($sql->next_record()) { - if (Permission::userHasDocumentReadPermission($sql->f("id"))) { - $aDocuments[count($aDocuments)] = $sql->f("id"); - } - if (count($aDocuments) > 0) { - return implode(",", $aDocuments); - } - } - return "0"; -} - ?> diff --git a/presentation/lookAndFeel/knowledgeTree/search/standardSearchUI.inc b/presentation/lookAndFeel/knowledgeTree/search/standardSearchUI.inc index c79aadb..a5086da 100644 --- a/presentation/lookAndFeel/knowledgeTree/search/standardSearchUI.inc +++ b/presentation/lookAndFeel/knowledgeTree/search/standardSearchUI.inc @@ -9,23 +9,104 @@ * @package presentation.lookAndFeel.documentmanagement */ -function getPage($sSearchText, $sBrowseType, $iFolderID, $iDocumentID, $sCategoryName, $iDocType, $sFolderIDs, $iStartIndex, $sSQLSearchString, $bSearchByDocument = false) { - $sRefreshMessage = "
If your browser displays a 'Warning: Page has Expired' message when you attempt to return to these search results, please click your browser's 'Refresh' button
"; - return renderHeading("Standard Search") . getSearchResults($sFolderIDs, $sSQLSearchString, $iStartIndex, $bSearchByDocument) . $sRefreshMessage . getSearchVariablesHtml($sSearchText, $sBrowseType, $iFolderID, $iDocumentID, $sCategoryName, $iDocType); +function getHeading() { + return renderHeading("Standard Search"); } -function getSearchResults($sFolderIDs, $sKeywords, $iStartIndex) { +function getMessage() { + $sRefreshMessage = "
If your browser displays a 'Warning: Page has Expired' message when you attempt to return to these search results, please click your browser's 'Refresh' button
"; +} + +function getSearchResultsByCategory($iFolderID, $sKeywords, $iStartIndex, $sCategory) { + global $default; + $sQuery = "SELECT DISTINCT '" . "$default->graphicsUrl/widgets/dfolder.gif" . "' AS folder_image_url, F.id AS folder_id, D.id AS document_id, D.name AS document_name, ROUND(MATCH(DT.document_text) AGAINST ('" . $sKeywords . "'),3) AS score " . + "FROM documents AS D INNER JOIN document_text AS DT ON D.id = DT.document_id " . + "INNER JOIN $default->owl_fields_table AS DF ON DF.id = DFL.document_field_id " . + "INNER JOIN status_lookup AS SL ON D.status_id = SL.id " . + "INNER JOIN folders AS F on F.ID = D.folder_id " . + "INNER JOIN search_document_user_link AS SDUL ON SDUL.document_id = D.id " . + "WHERE MATCH(DT.document_text) AGAINST ('" . $sKeywords . "') " . + "AND SDUL.user_id = " . $_SESSION["userID"] . " " . + "AND SL.name='Live' "; + //only check in the parent_folder_ids if we're not searching from the + //root folder down + if ($iFolderID != 0) { + $sQuery .= "AND (F.parent_folder_ids LIKE '%,$iFolderID,%' OR F.id = $iFolderID) "; + } + $sQuery .= "AND DF.name LIKE 'Category' "; + if (isset($sCategory)) { + $sQuery .= "AND DFL.value LIKE '$sCategory' "; + } + $sQuery .= "ORDER BY score DESC"; + + + //var_dump($sQuery); + + $aColumns = array("folder_image_url", "document_name","score"); + $aColumnTypes = array(4,3,3); + $aColumnHeaders = array("Folder","Document","Score"); + $aLinkURLs = array("$default->rootUrl/control.php?action=browse","$default->rootUrl/control.php?action=viewDocument"); + $aDBQueryStringColumns = array("document_id","folder_id","score"); + $aQueryStringVariableNames = array("fDocumentID", "fFolderID"); + + $oPatternBrowse = & new PatternBrowseableSearchResults($sQuery, 10, $aColumns, $aColumnTypes, $aColumnHeaders, $aLinkURLs, $aDBQueryStringColumns, $aQueryStringVariableNames); + $oPatternBrowse->setStartIndex($iStartIndex); + return getHeading() . $oPatternBrowse->render() . getSearchVariablesHtml($sKeywords, "category", $iFolderID, "", $sCategory, "") . getMessage(); +} + +function getSearchResultsByDocumentType($iFolderID, $sKeywords, $iStartIndex, $iDocTypeID) { + global $default; + $sQuery = "SELECT DISTINCT '" . "$default->graphicsUrl/widgets/dfolder.gif" . "' AS folder_image_url, F.id AS folder_id, D.id AS document_id, D.name AS document_name, ROUND(MATCH(DT.document_text) AGAINST ('" . $sKeywords . "'),3) AS score " . + "FROM documents AS D INNER JOIN document_text AS DT ON D.id = DT.document_id " . + "INNER JOIN status_lookup AS SL ON D.status_id = SL.id " . + "INNER JOIN folders AS F on F.ID = D.folder_id " . + "INNER JOIN search_document_user_link AS SDUL ON SDUL.document_id = D.id " . + "WHERE MATCH(DT.document_text) AGAINST ('" . $sKeywords . "') " . + "AND SDUL.user_id = " . $_SESSION["userID"] . " "; + if (isset($iDocTypeID)) { + $sQuery .= "AND D.document_type_id = $iDocTypeID "; + } + $sQuery .= "AND SL.name='Live' "; + //only check in the parent_folder_ids if we're not searching from the + //root folder down + if ($iFolderID != 0) { + $sQuery .= "AND (F.parent_folder_ids LIKE '%,$iFolderID,%' OR F.id = $iFolderID) "; + } + $sQuery .= "ORDER BY score DESC"; + + //var_dump($sQuery); + + $aColumns = array("folder_image_url", "document_name","score"); + $aColumnTypes = array(4,3,3); + $aColumnHeaders = array("Folder","Document","Score"); + $aLinkURLs = array("$default->rootUrl/control.php?action=browse","$default->rootUrl/control.php?action=viewDocument"); + $aDBQueryStringColumns = array("document_id","folder_id","score"); + $aQueryStringVariableNames = array("fDocumentID", "fFolderID"); + + $oPatternBrowse = & new PatternBrowseableSearchResults($sQuery, 10, $aColumns, $aColumnTypes, $aColumnHeaders, $aLinkURLs, $aDBQueryStringColumns, $aQueryStringVariableNames); + $oPatternBrowse->setStartIndex($iStartIndex); + return getHeading() . $oPatternBrowse->render() . getSearchVariablesHtml($sKeywords, "documentType", $iFolderID, "", "", $iDocTypeID) . getMessage(); + +} + +function getSeachResultsByFolder($iFolderID, $iStartIndex, $sKeywords) { global $default; $sQuery = "SELECT DISTINCT '" . "$default->graphicsUrl/widgets/dfolder.gif" . "' AS folder_image_url, F.id AS folder_id, D.id AS document_id, D.name AS document_name, ROUND(MATCH(DT.document_text) AGAINST ('" . $sKeywords . "'),3) AS score " . - "FROM search_document_user_link AS SDUL INNER JOIN document_text AS DT ON SDUL.document_id = DT.document_id " . - "INNER JOIN documents AS D ON D.id = SDUL.document_id " . + "FROM documents AS D INNER JOIN document_text AS DT ON D.id = DT.document_id " . "INNER JOIN status_lookup AS SL ON D.status_id = SL.id " . "INNER JOIN folders AS F on F.ID = D.folder_id " . + "INNER JOIN search_document_user_link AS SDUL ON SDUL.document_id = D.id " . "WHERE MATCH(DT.document_text) AGAINST ('" . $sKeywords . "') " . "AND SDUL.user_id = " . $_SESSION["userID"] . " " . - "AND SL.name='Live' " . - "AND F.id IN ($sFolderIDs) " . - "ORDER BY score DESC"; + "AND SL.name='Live' "; + //only check in the parent_folder_ids if we're not searching from the + //root folder down + if ($iFolderID != 0) { + $sQuery .= "AND (F.parent_folder_ids LIKE '%,$iFolderID,%' OR F.id = $iFolderID) "; + } + $sQuery .= "ORDER BY score DESC"; + + //var_dump($sQuery); $aColumns = array("folder_image_url", "document_name","score"); $aColumnTypes = array(4,3,3); @@ -36,7 +117,7 @@ function getSearchResults($sFolderIDs, $sKeywords, $iStartIndex) { $oPatternBrowse = & new PatternBrowseableSearchResults($sQuery, 10, $aColumns, $aColumnTypes, $aColumnHeaders, $aLinkURLs, $aDBQueryStringColumns, $aQueryStringVariableNames); $oPatternBrowse->setStartIndex($iStartIndex); - return $oPatternBrowse->render(); + return getHeading() . $oPatternBrowse->render() . getSearchVariablesHtml($sKeywords, "", $iFolderID, "", "", "") . getMessage(); } function getSearchVariablesHtml($sSearchText, $sBrowseType, $iFolderID, $iDocumentID, $sCategoryName, $iDocType) { -- libgit2 0.21.4