Commit 091c51ce96155fb09d4161d4256c3f46cae6f2cf

Authored by kevin_fourie
1 parent 58e97e31

Merged in from DEV trunk...

KTS-2214
"Problem with simple search dashlet - database error on searches"
Fixed. Changed PartialQuery and Criteria.inc to cater for infinite search terms...

Committed By: Jalaloedien Abrahams
Reviewed By: Conrad Vermeulen


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@7031 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/browse/Criteria.inc
... ... @@ -1036,8 +1036,11 @@ class SearchableTextCriterion extends BrowseCriterion {
1036 1036 continue;
1037 1037 }
1038 1038 $keywords[$i] = '%'.$keywords[$i].'%';
  1039 + if($i > 0){
  1040 + $p[0] .= ' AND ';
  1041 + }
  1042 + $p[0] .= "DST.document_text LIKE ?";
1039 1043 }
1040   - $p[0] = "DST.document_text LIKE ? AND DST.document_text LIKE ? ";
1041 1044 $p[1] = $keywords;
1042 1045 }else{
1043 1046 $p[0] = "DST.document_text LIKE ? ";
... ...
lib/browse/PartialQuery.inc.php
... ... @@ -306,8 +306,11 @@ class SimpleSearchQuery extends PartialQuery {
306 306 if(count($keywords) > 1){
307 307 for($i=0; $i<count($keywords); $i++){
308 308 $keywords[$i] = '%'.$keywords[$i].'%';
309   - }
310   - $aPotentialWhereString = 'FST.folder_text LIKE ? AND FST.folder_text LIKE ? ';
  309 + if($i > 0){
  310 + $aPotentialWhereString .= ' AND ';
  311 + }
  312 + $aPotentialWhereString .= 'FST.folder_text LIKE ?';
  313 + }
311 314 }else{
312 315 $aPotentialWhereString = 'FST.folder_text LIKE ? ';
313 316 }
... ... @@ -339,7 +342,8 @@ class SimpleSearchQuery extends PartialQuery {
339 342 $aParams = array($this->searchable_text);
340 343 }
341 344  
342   - $aParams = kt_array_merge($aPermissionParams, $aParams);
  345 + $aParams = kt_array_merge($aPermissionParams, $aParams);
  346 +
343 347 return array($sQuery, $aParams);
344 348 }
345 349  
... ...
lib/search/searchutil.inc.php
... ... @@ -56,7 +56,7 @@ class KTSearchUtil {
56 56 $type = KTUtil::arrayGet($dataset, "type");
57 57 $sql = KTUtil::arrayGet($dataset, "sql");
58 58 if (!empty($type)) {
59   - $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
  59 + $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
60 60 $oCriterion = $oCriteriaRegistry->getCriterion($dataset['type']);
61 61 if (PEAR::isError($oCriterion)) {
62 62 return PEAR::raiseError(_kt('Invalid criteria specified.'));
... ... @@ -75,6 +75,7 @@ class KTSearchUtil {
75 75 foreach ($criteria_set as $oCriterionPair) {
76 76 $oCriterion = $oCriterionPair[0];
77 77 $aReq = $oCriterionPair[1];
  78 +
78 79 if (is_object($oCriterion)) {
79 80 $res = $oCriterion->searchSQL($aReq);
80 81 if (!is_null($res)) {
... ... @@ -136,6 +137,7 @@ class KTSearchUtil {
136 137 * subgroups at the top level, even though we most often only
137 138 * have a single "subgroup".
138 139 */
  140 +
139 141 foreach ($aCriteriaSet["subgroup"] as $k => $aOneCriteriaSet) {
140 142 /*
141 143 * Each subgroup will either have values or it will have
... ... @@ -144,15 +146,15 @@ class KTSearchUtil {
144 146 $aValues = KTUtil::arrayGet($aOneCriteriaSet, "values");
145 147 $aSubgroup = KTUtil::arrayGet($aOneCriteriaSet, "subgroup");
146 148 if (!empty($aValues)) {
147   - $res = KTSearchUtil::_oneCriteriaSetToSQL($aOneCriteriaSet["values"]);
148   - if(PEAR::isError($res)) {
149   - return $res;
150   - }
151   - list($aThisCritQueries, $aThisParams, $aThisJoinSQL) = $res;
152   - $aJoinSQL = kt_array_merge($aJoinSQL, $aThisJoinSQL);
153   - $aParams = kt_array_merge($aParams, $aThisParams);
154   - $tabs = str_repeat("\t", ($iRecurseLevel + 2));
155   - $aSearchStrings[] = "\n$tabs(\n$tabs\t" . join("\n " . KTUtil::arrayGet($aOneCriteriaSet, 'join', "AND") . " ", $aThisCritQueries) . "\n$tabs)";
  149 + $res = KTSearchUtil::_oneCriteriaSetToSQL($aOneCriteriaSet["values"]);
  150 + if(PEAR::isError($res)) {
  151 + return $res;
  152 + }
  153 + list($aThisCritQueries, $aThisParams, $aThisJoinSQL) = $res;
  154 + $aJoinSQL = kt_array_merge($aJoinSQL, $aThisJoinSQL);
  155 + $aParams = kt_array_merge($aParams, $aThisParams);
  156 + $tabs = str_repeat("\t", ($iRecurseLevel + 2));
  157 + $aSearchStrings[] = "\n$tabs(\n$tabs\t" . join("\n " . KTUtil::arrayGet($aOneCriteriaSet, 'join', "AND") . " ", $aThisCritQueries) . "\n$tabs)";
156 158 } else if (!empty($aSubgroup)) {
157 159 /*
158 160 * Recurse if we have a criteria set with subgroups.
... ... @@ -170,6 +172,7 @@ class KTSearchUtil {
170 172 $sJoinSQL = join(" ", $aJoinSQL);
171 173 $tabs = str_repeat("\t", $iRecurseLevel + 1);
172 174 $sSearchString = "\n$tabs(" . join("\n$tabs\t" . $aCriteriaSet['join'] . " ", $aSearchStrings) . "\n$tabs)";
  175 +
173 176 return array($sSearchString, $aParams, $sJoinSQL);
174 177 }
175 178 // }}}
... ... @@ -260,12 +263,14 @@ class KTSearchUtil {
260 263 }
261 264  
262 265 $res = KTSearchUtil::criteriaSetToSQL($aCriteriaSet);
  266 +
263 267 if(PEAR::isError($res)) return $res;
264 268 list($sSQLSearchString, $aCritParams, $sCritJoinSQL) = $res;
265   -
  269 +
266 270 $sToSearch = KTUtil::arrayGet($aOrigReq, 'fToSearch', 'Live'); // actually never present in this version.
267 271  
268 272 $res = KTSearchUtil::permissionToSQL($oUser, $sPermissionName);
  273 +
269 274 if (PEAR::isError($res)) { // only occurs if the group has no permissions.
270 275 return $res;
271 276 } else {
... ... @@ -278,6 +283,7 @@ class KTSearchUtil {
278 283 * trailing ANDs.
279 284 */
280 285 $aPotentialWhere = array($sPermissionString, 'SL.name = ?', "($sSQLSearchString)");
  286 +
281 287 $aWhere = array();
282 288 foreach ($aPotentialWhere as $sWhere) {
283 289 if (empty($sWhere)) {
... ... @@ -287,6 +293,7 @@ class KTSearchUtil {
287 293 continue;
288 294 }
289 295 $aWhere[] = $sWhere;
  296 +
290 297 }
291 298 $sWhere = "";
292 299 if ($aWhere) {
... ... @@ -320,7 +327,6 @@ class KTSearchUtil {
320 327 $aParams = kt_array_merge($aParams, $aPermissionParams);
321 328 $aParams[] = $sToSearch;
322 329 $aParams = kt_array_merge($aParams, $aCritParams);
323   -
324 330 return array($sQuery, $aParams);
325 331 }
326 332 // }}}
... ...