Commit 4cb4a1b3c3e70457be3cd48cf58af18800931f5b

Authored by Jalaloedien Abrahams
1 parent a5528633

KTS-1895

"Simple search should perform a "like" not an "equal to" comparison when returning results. "
Fixed.

Reviewed By: Conrad

KTS-1896
"Simple search should return results which match ALL rather than ANY terms within the query. "
Fixed.

Reviewed By: Conrad

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@6550 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/browse/Criteria.inc
... ... @@ -1012,11 +1012,35 @@ class SearchableTextCriterion extends BrowseCriterion {
1012 1012 } else {
1013 1013 $boolean_mode = "";
1014 1014 }
  1015 +
  1016 + $p = array();
  1017 + $temp = str_replace('%', '', $aRequest[$this->getWidgetBase()]);
  1018 + $keywords = explode(' ', $temp);
  1019 +
  1020 + for($i=0; $i<count($keywords); $i++){
  1021 + if($keywords[$i] == ' ' or $keywords[$i] == ''){
  1022 + continue;
  1023 + }else{
  1024 + $keywords_temp[] = trim($keywords[$i]);
  1025 + }
  1026 + }
  1027 + $keywords = $keywords_temp;
  1028 +
  1029 + if(count($keywords) > 1){
  1030 + for($i=0; $i<count($keywords); $i++){
  1031 + $word = trim($keywords[$i]);
  1032 + if(empty($word)){
  1033 + continue;
  1034 + }
  1035 + $keywords[$i] = '%'.$keywords[$i].'%';
  1036 + }
  1037 + $p[0] = "DST.document_text LIKE ? AND DST.document_text LIKE ? ";
  1038 + $p[1] = $keywords;
  1039 + }else{
  1040 + $p[0] = "DST.document_text LIKE ? ";
  1041 + $p[1] = $aRequest[$this->getWidgetBase()];
  1042 + }
1015 1043  
1016   - $p = array();
1017   - $p[0] = "MATCH(DST.document_text) AGAINST (? $boolean_mode)";
1018   - $p[1] = KTUtil::phraseQuote($aRequest[$this->getWidgetBase()]);
1019   -
1020 1044 // handle the boolean "not" stuff.
1021 1045 $want_invert = KTUtil::arrayGet($aRequest, $this->getWidgetBase() . '_not');
1022 1046 if (is_null($want_invert) || ($want_invert == "0")) {
... ...
lib/browse/PartialQuery.inc.php
... ... @@ -272,7 +272,11 @@ class SimpleSearchQuery extends PartialQuery {
272 272 // FIXME cache permission lookups, etc.
273 273 var $searchable_text;
274 274  
275   - function SimpleSearchQuery($sSearchableText) { $this->searchable_text = $sSearchableText; }
  275 + function SimpleSearchQuery($sSearchableText){
  276 + $sSearchableText = str_replace("\t", ' ', $sSearchableText);
  277 + $sSearchableText = '%'.$sSearchableText.'%';
  278 + $this->searchable_text = $sSearchableText;
  279 + }
276 280  
277 281 function _getFolderQuery($aOptions = null) {
278 282 $oUser = User::get($_SESSION['userID']);
... ... @@ -281,8 +285,29 @@ class SimpleSearchQuery extends PartialQuery {
281 285 return $res;
282 286 }
283 287 list($sPermissionString, $aPermissionParams, $sPermissionJoin) = $res;
284   -
285   - $aPotentialWhere = array($sPermissionString, 'MATCH (FST.folder_text) AGAINST (? IN BOOLEAN MODE) <> 0');
  288 +
  289 + $temp = str_replace('%', '', $this->searchable_text);
  290 + $keywords = explode(' ', $temp);
  291 +
  292 + for($i=0; $i<count($keywords); $i++){
  293 + if($keywords[$i] == ' ' or $keywords[$i] == ''){
  294 + continue;
  295 + }else{
  296 + $keywords_temp[] = trim($keywords[$i]);
  297 + }
  298 + }
  299 + $keywords = $keywords_temp;
  300 +
  301 + if(count($keywords) > 1){
  302 + for($i=0; $i<count($keywords); $i++){
  303 + $keywords[$i] = '%'.$keywords[$i].'%';
  304 + }
  305 + $aPotentialWhereString = 'FST.folder_text LIKE ? AND FST.folder_text LIKE ? ';
  306 + }else{
  307 + $aPotentialWhereString = 'FST.folder_text LIKE ? ';
  308 + }
  309 +
  310 + $aPotentialWhere = array($sPermissionString, $aPotentialWhereString);
286 311 $aWhere = array();
287 312 foreach ($aPotentialWhere as $sWhere) {
288 313 if (empty($sWhere)) {
... ... @@ -303,7 +328,12 @@ class SimpleSearchQuery extends PartialQuery {
303 328 $sQuery = "SELECT $sSelect FROM " . KTUtil::getTableName('folders') . ' AS F
304 329 LEFT JOIN ' . KTUtil::getTableName('folder_searchable_text') . " AS FST ON (F.id = FST.folder_id)
305 330 $sPermissionJoin $sWhere ";
306   - $aParams = array($this->searchable_text);
  331 + if(count($keywords) > 1){
  332 + $aParams = $keywords;
  333 + }else{
  334 + $aParams = array($this->searchable_text);
  335 + }
  336 +
307 337 $aParams = kt_array_merge($aPermissionParams, $aParams);
308 338 return array($sQuery, $aParams);
309 339 }
... ...