changed search algoritm

This commit is contained in:
Viktor Pedersen 2021-08-05 16:23:34 +02:00
parent 5e5c7971de
commit ec86baae19

@ -139,7 +139,7 @@ class SearchPage extends Page {
==================================================
ORIGINAL CODE BACKUP || FOR REFERENCE
ORIGINAL CODE || BACKUP || FOR REFERENCE
$items = get_items($type);
$out = array();
@ -168,25 +168,26 @@ class SearchPage extends Page {
$mustIncludeArray = array();
$mustExcludeArray = array();
$canIncludeArray = array();
$items = get_items($type);
$out = array();
$resultIsFine = False;
foreach($terms as $term) {
if($term[$i][0] == "+") {
// adds to mustIncludeArray
$mustIncludeArray[] = array(substr($term[$i], 1));
//echo "test print " substr($term[$i], 1);
} elseif($term[$i][0] == "!" || $term[$i][0] == "-") {
} else if($term[$i][0] == "!" || $term[$i][0] == "-") {
// adds to mustExcludeArray
$mustExcludeArray[] = array(substr($term[$i], 1));
//echo "test print " substr($term[$i], 1);
} else {
// adds to canIncludeArray
$canIncludeArray[] = array($term);
}
}
$items = get_items($type);
$out = array();
$result = False;
foreach($items as $item) {
/* version 1
if(($item->matches($mustExcludeArray) == False)) {
if(($item->matches($canIncludeArray)) || (count($canIncludeArray == 0))){
if(count($mustIncludeArray) > 0) {
@ -202,10 +203,38 @@ class SearchPage extends Page {
$result = True;
}
}
} */
// version 2
$resultExclude = $item->matches($mustExcludeArray)
if ($resultExclude) {
} else {
$mustIncludeCheck = False;
foreach ($mustIncludeArray as $mustIncludeArgument) {
$resultInclude = $item->matches($mustIncludeArgument)
if ($resultInclude) {
$mustIncludeCheck = True;
} else {
$mustIncludeCheck = False;
break;
}
}
if ($mustIncludeCheck) {
if (count($canIncludeArray) > 0) {
$canIncludeResult = $item->matches($canIncludeArray)
$out[] = array($item, $canIncludeResult);
} else {
$mustIncludeResult = $item->matches($mustIncludeArray)
$out[] = array($item, $mustIncludeResult);
}
}
}
if($result) {
/* if($result) {
$out[] = array($item, $result);
}
} */
}
return $out;
}