Commit 015e92fb34c15b9b3ebdee1312f26a227b3abc44

Authored by rob
1 parent 6dff2b1b

Altered search query to improve performance


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2240 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/search/standardSearchBL.php
... ... @@ -13,7 +13,6 @@
13 13 *
14 14 */
15 15 require_once("../../../../config/dmsDefaults.php");
16   -
17 16 if (checkSession()) {
18 17 require_once("$default->fileSystemRoot/lib/visualpatterns/PatternBrowsableSearchResults.inc");
19 18 require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
... ... @@ -29,272 +28,74 @@ if (checkSession()) {
29 28 $fStandardSearchString = addslashes($fStandardSearchString);
30 29  
31 30 if (strlen($fBrowseType) > 0) {
  31 + echo "browse type";
32 32 //the user was browsing by a specific type
33 33 switch ($fBrowseType) {
34 34 case "folder" :
35   - //user was browsing a specific folder - search that folder
  35 + //user was browsing a specific folder - search that folder
36 36 if (!$fFolderID) {
37 37 //start at the root folder
38 38 $fFolderID = 0;
39   - $sFolderString = getFolderString($fFolderID);
40   - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
41   - $oPatternCustom = & new PatternCustom();
42   - //$oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fStandardSearchString)));
43   - $oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, $fStandardSearchString));
44   - $main->setCentralPayload($oPatternCustom);
45   - $main->render();
46   - } else {
47   - $sFolderString = getFolderString($fFolderID);
48   - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
49   - $oPatternCustom = & new PatternCustom();
50   - //$oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fStandardSearchString)));
51   - $oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, $fStandardSearchString));
52   - $main->setCentralPayload($oPatternCustom);
53   - $main->render();
54   - }
  39 + }
  40 + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
  41 + $oPatternCustom = & new PatternCustom();
  42 + $oPatternCustom->setHtml(getSeachResultsByFolder($fFolderID, $fStartIndex, $fStandardSearchString));
  43 + $main->setCentralPayload($oPatternCustom);
  44 + $main->render();
55 45 break;
56 46 case "category" :
57 47 //user was browsing by category - search all documents in that category
58 48 if (!$fCategoryName) {
59 49 //no category name specified, so just start at the root folder
60 50 $fFolderID = 0;
61   - $sFolderString = getFolderString($fFolderID);
62   - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
63   - $oPatternCustom = & new PatternCustom();
64   - //$oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fStandardSearchString)));
65   - $oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, $fStandardSearchString));
66   - $main->setCentralPayload($oPatternCustom);
67   - $main->render();
68   - } else {
69   - $sFolderString = getFolderStringFromCategory($fCategoryName);
70   - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
71   - $oPatternCustom = & new PatternCustom();
72   - //$oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fStandardSearchString)));
73   - $oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, $fStandardSearchString));
74   - $main->setCentralPayload($oPatternCustom);
75   - $main->render();
76   - }
77   - break;
78   -
  51 + }
  52 + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
  53 + $oPatternCustom = & new PatternCustom();
  54 + $oPatternCustom->setHtml(getSearchResultsByCategory($fFolderID, $fStandardSearchString, $fStartIndex, $fCategoryName));
  55 + $main->setCentralPayload($oPatternCustom);
  56 + $main->render();
  57 + break;
79 58 case "documentType" :
80 59 //user was browsing by document type - search all documents in that doc type
81 60 if (!$fDocTypeID) {
82 61 //no document type specified, so just start at the root folder
83 62 $fFolderID = 0;
84   - $sFolderString = getApprovedFolderString($fFolderID);
85   - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
86   - $oPatternCustom = & new PatternCustom();
87   - //$oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fStandardSearchString)));
88   - $oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, $fStandardSearchString));
89   - $main->setCentralPayload($oPatternCustom);
90   - $main->render();
91   - } else {
92   - $sDocumentString = getApprovedDocsDocType($fDocTypeID);
93   - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
94   - $oPatternCustom = & new PatternCustom();
95   - //$oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sDocumentString, $fStartIndex, getSQLSearchString($fStandardSearchString), true));
96   - $oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sDocumentString, $fStartIndex, $fStandardSearchString, true));
97   - $main->setCentralPayload($oPatternCustom);
98   - $main->render();
99   - }
  63 + }
  64 + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
  65 + $oPatternCustom = & new PatternCustom();
  66 + $oPatternCustom->setHtml(getSearchResultsByDocumentType($fFolderID, $fStandardSearchString, $fStartIndex, $fDocTypeID));
  67 + $main->setCentralPayload($oPatternCustom);
  68 + $main->render();
100 69 break;
101 70 default:
102 71 //search from the root folder down i.e. all documents
103 72 break;
104   - }
  73 + }
105 74 } else if (strlen($fFolderID) > 0) {
106   - //the user was browsing a folder, search that folder
107   - $sFolderString = getFolderString($fFolderID);
  75 + //the user was browsing a folder, search that folder
108 76 require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
109 77 $oPatternCustom = & new PatternCustom();
110   - $oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, $fStandardSearchString));
  78 + $oPatternCustom->setHtml(getSeachResultsByFolder($fFolderID, $fStartIndex, $fStandardSearchString));
111 79 $main->setCentralPayload($oPatternCustom);
112 80 $main->render();
113 81  
114 82 } else if (strlen($fDocumentID) > 0) {
115 83 //the user was viewing a document, search in that document's folder
116 84 $oDocument = Document::get($fDocumentID);
117   - //$sFolderString = getApprovedFolderString($oDocument->getFolderID());
118   - $sFolderString = getFolderString($oDocument->getFolderID());
119 85 require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
120   - $oPatternCustom = & new PatternCustom();
121   - //$oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fStandardSearchString)));
122   - $oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, $fStandardSearchString));
123   - $main->setCentralPayload($oPatternCustom);
124   - $main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
125   - $main->setHasRequiredFields(true);
  86 + $oPatternCustom = & new PatternCustom();
  87 + $oPatternCustom->setHtml(getSeachResultsByFolder($oDocument->getFolderID(), $fStartIndex, $fStandardSearchString));
  88 + $main->setCentralPayload($oPatternCustom);
126 89 $main->render();
127 90 } else {
128   - //search from the root folder down i.e. all documents
  91 + //search from the root folder down i.e. all documents
129 92 $fFolderID = 0;
130   - //$sFolderString = getApprovedFolderString($fFolderID);
131   - $sFolderString = getFolderString($fFolderID);
132 93 require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
133 94 $oPatternCustom = & new PatternCustom();
134   - //$oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fStandardSearchString)));
135   - $oPatternCustom->setHtml(getPage($fStandardSearchString, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, $fStandardSearchString));
136   - $main->setCentralPayload($oPatternCustom);
137   - $main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
138   - $main->setHasRequiredFields(true);
  95 + $oPatternCustom->setHtml(getSeachResultsByFolder($fFolderID, $fStartIndex, $fStandardSearchString));
  96 + $main->setCentralPayload($oPatternCustom);
139 97 $main->render();
140 98 }
141 99 }
142   -
143   -function getFolderString($iFolderID) {
144   - $aChildren = Folder::getChildren($iFolderID);
145   - //add the folder we started on
146   - $aChildren[count($aChildren)] = $iFolderID;
147   - return implode(",", $aChildren);
148   -}
149   -
150   -/*
151   -function getApprovedFolderString($iFolderID) {
152   - $aChildren = Folder::getChildren($iFolderID);
153   - $aApprovedChildren = array();
154   - //filter out all the folders the user does
155   - //not have permission to see
156   - for ($i = 0; $i < count($aChildren); $i++) {
157   - $oFolder = Folder::get($aChildren[$i]);
158   -
159   - //if the folder is already approved, continue
160   - if (in_array($oFolder->getID(), $aApprovedChildren)) {
161   - //echo "Already in: " . $oFolder->getID() . "<br>";
162   - continue;
163   - }
164   -
165   - $aParentFolderIDs = explode(",",$oFolder->getParentFolderIDs());
166   -
167   - //if one of the folder's parents is already approved, add the folder
168   - for ($j = 0; $j < count($aParentFolderIDs); $j++) {
169   - if (in_array($aParentFolderIDs[$j], $aApprovedChildren)) {
170   - if (in_array($oFolder->getID(), $aApprovedChildren)) {
171   - $aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID();
172   - }
173   - continue;
174   - }
175   - }
176   -
177   - //check if the user has read permission for this folder
178   - if (Permission::userHasFolderReadPermission($oFolder->getID())) {
179   - $aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID();
180   - continue;
181   - }
182   -
183   - }
184   - return implode(",", $aApprovedChildren);
185   -}
186   -
187   -
188   -*/
189   -
190   -function getFolderStringFromCategory($sCategory) {
191   - global $default;
192   - $sQuery = "SELECT DISTINCT D.folder_id " .
193   - "FROM $default->owl_documents_table AS D inner join $default->owl_document_fields_table AS DFL ON D.id = DFL.document_id " .
194   - "INNER JOIN $default->owl_fields_table AS DF ON DF.id = DFL.document_field_id " .
195   - "WHERE DF.name LIKE 'Category' " .
196   - "AND DFL.value LIKE '$sCategory'";
197   -
198   - $sql = $default->db;
199   - $sql->query($sQuery);
200   -
201   - if ($sql->next_record()) {
202   - //get all the folders in the category
203   - $aFolders = array($sql->f("folder_id"));
204   - while ($sql->next_record()) {
205   - $aFolders[count($aFolders)] = $sql->f("folder_id");
206   - }
207   - return implode(",", $aFolders);
208   - }
209   - return "0";
210   -
211   -}
212   -
213   -/*function getApprovedFolderStringFromCategory($sCategory) {
214   - global $default;
215   - $sQuery = "SELECT DISTINCT D.folder_id " .
216   - "FROM $default->owl_documents_table AS D inner join $default->owl_document_fields_table AS DFL ON D.id = DFL.document_id " .
217   - "INNER JOIN $default->owl_fields_table AS DF ON DF.id = DFL.document_field_id " .
218   - "WHERE DF.name LIKE 'Category' " .
219   - "AND DFL.value LIKE '$sCategory'";
220   -
221   - $sql = $default->db;
222   - $sql->query($sQuery);
223   - if ($sql->next_record()) {
224   - //get all the folders in the category
225   - $aFolders = array($sql->f("folder_id"));
226   - while ($sql->next_record()) {
227   - $aFolders[count($aFolders)] = $sql->f("folder_id");
228   - }
229   -
230   - $aApprovedChildren = array();
231   - //filter out all the folders the user does
232   - //not have permission to see
233   - for ($i = 0; $i < count($aFolders); $i++) {
234   - $oFolder = Folder::get($aFolders[$i]);
235   -
236   - //if the folder is already approved, continue
237   - if (in_array($oFolder->getID(), $aApprovedChildren)) {
238   - //echo "Already in: " . $oFolder->getID() . "<br>";
239   - continue;
240   - }
241   -
242   - $aParentFolderIDs = explode(",",$oFolder->getParentFolderIDs());
243   -
244   - //if one of the folder's parents is already approved, add the folder
245   - for ($j = 0; $j < count($aParentFolderIDs); $j++) {
246   - if (in_array($aParentFolderIDs[$j], $aApprovedChildren)) {
247   - if (in_array($oFolder->getID(), $aApprovedChildren)) {
248   - $aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID();
249   - }
250   - continue;
251   - }
252   - }
253   -
254   - //check if the user has read permission for this folder
255   - if (Permission::userHasFolderReadPermission($oFolder->getID())) {
256   - $aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID();
257   - continue;
258   - }
259   -
260   - }
261   - return implode(",", $aApprovedChildren);
262   - }
263   - return "0";
264   -}*/
265   -
266   -function getSQLSearchString($sSearchString) {
267   - $aWords = explode(" ", $sSearchString);
268   - $sSQLSearchString;
269   - for ($i = 0; $i < count($aWords) - 1; $i++) {
270   - $sSQLSearchString .= "(WL.word LIKE '%" . $aWords[$i] . "%') OR ";
271   - }
272   - $sSQLSearchString .= "(WL.word LIKE '%" . $aWords[count($aWords) -1] . "%')";
273   - return $sSQLSearchString;
274   -}
275   -
276   -function searchByCategory($sCategoryName) {
277   -
278   -}
279   -
280   -function getApprovedDocsDocType($iDocTypeID) {
281   - global $default;
282   - $sQuery = "SELECT D.id " .
283   - "FROM $default->owl_documents_table AS D " .
284   - "WHERE D.document_type_id = $iDocTypeID";
285   -
286   - $sql = $default->db;
287   - $sql->query($sQuery);
288   - while ($sql->next_record()) {
289   - if (Permission::userHasDocumentReadPermission($sql->f("id"))) {
290   - $aDocuments[count($aDocuments)] = $sql->f("id");
291   - }
292   - if (count($aDocuments) > 0) {
293   - return implode(",", $aDocuments);
294   - }
295   - }
296   - return "0";
297   -}
298   -
299 100 ?>
300 101  
... ...
presentation/lookAndFeel/knowledgeTree/search/standardSearchUI.inc
... ... @@ -9,23 +9,104 @@
9 9 * @package presentation.lookAndFeel.documentmanagement
10 10 */
11 11  
12   -function getPage($sSearchText, $sBrowseType, $iFolderID, $iDocumentID, $sCategoryName, $iDocType, $sFolderIDs, $iStartIndex, $sSQLSearchString, $bSearchByDocument = false) {
13   - $sRefreshMessage = "<table><tr><td align=\"center\">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</td></tr></table>";
14   - return renderHeading("Standard Search") . getSearchResults($sFolderIDs, $sSQLSearchString, $iStartIndex, $bSearchByDocument) . $sRefreshMessage . getSearchVariablesHtml($sSearchText, $sBrowseType, $iFolderID, $iDocumentID, $sCategoryName, $iDocType);
  12 +function getHeading() {
  13 + return renderHeading("Standard Search");
15 14 }
16 15  
17   -function getSearchResults($sFolderIDs, $sKeywords, $iStartIndex) {
  16 +function getMessage() {
  17 + $sRefreshMessage = "<table><tr><td align=\"center\">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</td></tr></table>";
  18 +}
  19 +
  20 +function getSearchResultsByCategory($iFolderID, $sKeywords, $iStartIndex, $sCategory) {
  21 + global $default;
  22 + $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 " .
  23 + "FROM documents AS D INNER JOIN document_text AS DT ON D.id = DT.document_id " .
  24 + "INNER JOIN $default->owl_fields_table AS DF ON DF.id = DFL.document_field_id " .
  25 + "INNER JOIN status_lookup AS SL ON D.status_id = SL.id " .
  26 + "INNER JOIN folders AS F on F.ID = D.folder_id " .
  27 + "INNER JOIN search_document_user_link AS SDUL ON SDUL.document_id = D.id " .
  28 + "WHERE MATCH(DT.document_text) AGAINST ('" . $sKeywords . "') " .
  29 + "AND SDUL.user_id = " . $_SESSION["userID"] . " " .
  30 + "AND SL.name='Live' ";
  31 + //only check in the parent_folder_ids if we're not searching from the
  32 + //root folder down
  33 + if ($iFolderID != 0) {
  34 + $sQuery .= "AND (F.parent_folder_ids LIKE '%,$iFolderID,%' OR F.id = $iFolderID) ";
  35 + }
  36 + $sQuery .= "AND DF.name LIKE 'Category' ";
  37 + if (isset($sCategory)) {
  38 + $sQuery .= "AND DFL.value LIKE '$sCategory' ";
  39 + }
  40 + $sQuery .= "ORDER BY score DESC";
  41 +
  42 +
  43 + //var_dump($sQuery);
  44 +
  45 + $aColumns = array("folder_image_url", "document_name","score");
  46 + $aColumnTypes = array(4,3,3);
  47 + $aColumnHeaders = array("<font color=\"ffffff\">Folder</font>","<font color=\"ffffff\">Document</font>","<font color=\"ffffff\">Score</font>");
  48 + $aLinkURLs = array("$default->rootUrl/control.php?action=browse","$default->rootUrl/control.php?action=viewDocument");
  49 + $aDBQueryStringColumns = array("document_id","folder_id","score");
  50 + $aQueryStringVariableNames = array("fDocumentID", "fFolderID");
  51 +
  52 + $oPatternBrowse = & new PatternBrowseableSearchResults($sQuery, 10, $aColumns, $aColumnTypes, $aColumnHeaders, $aLinkURLs, $aDBQueryStringColumns, $aQueryStringVariableNames);
  53 + $oPatternBrowse->setStartIndex($iStartIndex);
  54 + return getHeading() . $oPatternBrowse->render() . getSearchVariablesHtml($sKeywords, "category", $iFolderID, "", $sCategory, "") . getMessage();
  55 +}
  56 +
  57 +function getSearchResultsByDocumentType($iFolderID, $sKeywords, $iStartIndex, $iDocTypeID) {
  58 + global $default;
  59 + $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 " .
  60 + "FROM documents AS D INNER JOIN document_text AS DT ON D.id = DT.document_id " .
  61 + "INNER JOIN status_lookup AS SL ON D.status_id = SL.id " .
  62 + "INNER JOIN folders AS F on F.ID = D.folder_id " .
  63 + "INNER JOIN search_document_user_link AS SDUL ON SDUL.document_id = D.id " .
  64 + "WHERE MATCH(DT.document_text) AGAINST ('" . $sKeywords . "') " .
  65 + "AND SDUL.user_id = " . $_SESSION["userID"] . " ";
  66 + if (isset($iDocTypeID)) {
  67 + $sQuery .= "AND D.document_type_id = $iDocTypeID ";
  68 + }
  69 + $sQuery .= "AND SL.name='Live' ";
  70 + //only check in the parent_folder_ids if we're not searching from the
  71 + //root folder down
  72 + if ($iFolderID != 0) {
  73 + $sQuery .= "AND (F.parent_folder_ids LIKE '%,$iFolderID,%' OR F.id = $iFolderID) ";
  74 + }
  75 + $sQuery .= "ORDER BY score DESC";
  76 +
  77 + //var_dump($sQuery);
  78 +
  79 + $aColumns = array("folder_image_url", "document_name","score");
  80 + $aColumnTypes = array(4,3,3);
  81 + $aColumnHeaders = array("<font color=\"ffffff\">Folder</font>","<font color=\"ffffff\">Document</font>","<font color=\"ffffff\">Score</font>");
  82 + $aLinkURLs = array("$default->rootUrl/control.php?action=browse","$default->rootUrl/control.php?action=viewDocument");
  83 + $aDBQueryStringColumns = array("document_id","folder_id","score");
  84 + $aQueryStringVariableNames = array("fDocumentID", "fFolderID");
  85 +
  86 + $oPatternBrowse = & new PatternBrowseableSearchResults($sQuery, 10, $aColumns, $aColumnTypes, $aColumnHeaders, $aLinkURLs, $aDBQueryStringColumns, $aQueryStringVariableNames);
  87 + $oPatternBrowse->setStartIndex($iStartIndex);
  88 + return getHeading() . $oPatternBrowse->render() . getSearchVariablesHtml($sKeywords, "documentType", $iFolderID, "", "", $iDocTypeID) . getMessage();
  89 +
  90 +}
  91 +
  92 +function getSeachResultsByFolder($iFolderID, $iStartIndex, $sKeywords) {
18 93 global $default;
19 94 $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 " .
20   - "FROM search_document_user_link AS SDUL INNER JOIN document_text AS DT ON SDUL.document_id = DT.document_id " .
21   - "INNER JOIN documents AS D ON D.id = SDUL.document_id " .
  95 + "FROM documents AS D INNER JOIN document_text AS DT ON D.id = DT.document_id " .
22 96 "INNER JOIN status_lookup AS SL ON D.status_id = SL.id " .
23 97 "INNER JOIN folders AS F on F.ID = D.folder_id " .
  98 + "INNER JOIN search_document_user_link AS SDUL ON SDUL.document_id = D.id " .
24 99 "WHERE MATCH(DT.document_text) AGAINST ('" . $sKeywords . "') " .
25 100 "AND SDUL.user_id = " . $_SESSION["userID"] . " " .
26   - "AND SL.name='Live' " .
27   - "AND F.id IN ($sFolderIDs) " .
28   - "ORDER BY score DESC";
  101 + "AND SL.name='Live' ";
  102 + //only check in the parent_folder_ids if we're not searching from the
  103 + //root folder down
  104 + if ($iFolderID != 0) {
  105 + $sQuery .= "AND (F.parent_folder_ids LIKE '%,$iFolderID,%' OR F.id = $iFolderID) ";
  106 + }
  107 + $sQuery .= "ORDER BY score DESC";
  108 +
  109 + //var_dump($sQuery);
29 110  
30 111 $aColumns = array("folder_image_url", "document_name","score");
31 112 $aColumnTypes = array(4,3,3);
... ... @@ -36,7 +117,7 @@ function getSearchResults($sFolderIDs, $sKeywords, $iStartIndex) {
36 117  
37 118 $oPatternBrowse = & new PatternBrowseableSearchResults($sQuery, 10, $aColumns, $aColumnTypes, $aColumnHeaders, $aLinkURLs, $aDBQueryStringColumns, $aQueryStringVariableNames);
38 119 $oPatternBrowse->setStartIndex($iStartIndex);
39   - return $oPatternBrowse->render();
  120 + return getHeading() . $oPatternBrowse->render() . getSearchVariablesHtml($sKeywords, "", $iFolderID, "", "", "") . getMessage();
40 121 }
41 122  
42 123 function getSearchVariablesHtml($sSearchText, $sBrowseType, $iFolderID, $iDocumentID, $sCategoryName, $iDocType) {
... ...