cleaned up search function

This commit is contained in:
Viktor Pedersen 2021-09-02 10:56:54 +02:00
parent 37530311b3
commit f0faaa52c0

@ -29,10 +29,10 @@ class SearchPage extends Page {
return $out;
}
foreach(array('user', 'product') as $type) {
print('=== DEBUG $type:');
print_r($type);
print(' ===<br>');
print('<br>');
// print('=== DEBUG $type:');
// print_r($type);
// print(' ===<br>');
// print('<br>');
$result = $this->search($type, $this->terms);
if($result) {
$out[$type] = $result;
@ -42,8 +42,8 @@ class SearchPage extends Page {
}
private function search($type, $terms) {
/*
==================================================
ORIGINAL CODE || BACKUP || FOR REFERENCE
@ -59,7 +59,21 @@ class SearchPage extends Page {
return $out;
==================================================
*/
/*
==================================================
$terms = array(??,??,??)
$term = tbd
$key = e.g. "Fritext", "Tag", etc
$parsedTerm = e.g. "c426", "Dell"
$value = ????
$i = ????
$type = users, products
==================================================
*/
$mustIncludeArray = array();
@ -67,127 +81,48 @@ class SearchPage extends Page {
$canIncludeArray = array();
foreach($terms as $key => $term) {
print('DEBUG VAR_DUMP $terms: ');
var_dump($terms);
print('<br>');
print('DEBUG $terms: ');
print_r($terms);
print('<br>');
print('DEBUG $terms[$key]: ');
print_r($terms[$key]);
print('<br>');
print('DEBUG $key: ');
print_r($key);
print('<br>');
print('<br>');
foreach($term as $value => $i) {
switch ($i[0]) {
foreach($term as $value => $parsedTerm) {
switch ($parsedTerm[0]) {
case "+":
$mustIncludeArray[] = array($key, (substr($i, 1)));
print('DEBUG CASE $mustIncludeArray[] = array(');
print($key);
print(', ');
print(substr($i, 1));
print(') <br>');
$mustIncludeArray[] = array($key, substr($parsedTerm, 1));
break;
case "!":
case "-":
$mustExcludeArray[] = array($key, (substr($i, 1)));
print('DEBUG CASE $mustExcludeArray[] = array(');
print($key);
print(', ');
print(substr($i, 1));
print(') <br>');
break;
$mustExcludeArray[] = array($key, substr($parsedTerm, 1));
case "~":
$canIncludeArray[] = array($key, (substr($i, 1)));
print('DEBUG CASE $canIncludeArray[] = array(');
print($key);
print(', ');
print(substr($i, 1));
print(') <br>');
$canIncludeArray[] = array($key, substr($parsedTerm, 1));
break;
default:
$canIncludeArray[] = array($key, $i);
print('DEBUG CASE $canIncludeArray[] = array(');
print($key);
print(', ');
print($i);
print(') <br>');
$canIncludeArray[] = array($key, $parsedTerm);
break;
}
}
print('DEBUG VAR_DUMP $mustIncludeArray: ');
var_dump($mustIncludeArray);
print('<br>');
print('DEBUG VAR_DUMP $mustExcludeArray: ');
var_dump($mustExcludeArray);
print('<br>');
print('DEBUG VAR_DUMP $canIncludeArray: ');
var_dump($canIncludeArray);
print('<br>');
print('<br>');
}
print('DEBUG mustIncludeArray: ');
print_r($mustIncludeArray);
print('<br>');
print('DEBUG VARDUMP $terms: ');
var_dump($terms);
print('<br>');
print('<br>');
$items = get_items($type);
$sanitizedDB = array();
foreach($items as $item) {
print('DEBUG Foreach $item: ');
var_dump($item);
print('<br>');
print('<br>');
$mustMatchCheck = array();
foreach($mustIncludeArray as $mustIncludeTerm) { // pajar om Arrayen enbart har ett item???
print('DEBUG $mustIncludeTerm: ');
print_r($mustIncludeTerm);
print('<br>');
print('DEBUG VARDUMP $mustIncludeTerm: ');
var_dump($mustIncludeTerm);
print('<br>');
$res = $item->matches($mustIncludeTerm);
print('DEBUG VARDUMP $res: ');
var_dump($res);
print('<br>');
$mustIncludeTermCheck = $item->matches($mustIncludeTerm); // matchar inte korrekt???
if ($mustIncludeTermCheck) {
$mustMatchCheck[] = array(True);
print('DEBUG TRUE added to $mustMatchCheck[] ');
print('<br>');
}
else {
$mustMatchCheck[] = array(False);
print('DEBUG FALSE added to $mustMatchCheck[] ');
print('<br>');
}
print('<br>');
// $mustIncludeTermCheck = $item->matches($mustIncludeTerm); // matchar inte korrekt???
// if ($mustIncludeTermCheck) {
// $mustMatchCheck[] = array(True);
// print('DEBUG TRUE added to $mustMatchCheck[] ');
// print('<br>');
// }
// else {
// $mustMatchCheck[] = array(False);
// print('DEBUG FALSE added to $mustMatchCheck[] ');
// print('<br>');
// }
// print('<br>');
}
print('<br>');
// if (array_product($mustMatchCheck)) {
// $sanitizedDB[] = array($item);
// $sanitizedDB[] = array($item, $mustIncludeTermCheck);
// }
}