changes to search function
This commit is contained in:
parent
38ce91e332
commit
b99c55275b
@ -37,6 +37,88 @@ class SearchPage extends Page {
|
||||
return $out;
|
||||
}
|
||||
|
||||
private function search($type, $terms) {
|
||||
/*
|
||||
|
||||
==================================================
|
||||
|
||||
ORIGINAL CODE || BACKUP || FOR REFERENCE
|
||||
|
||||
$items = get_items($type);
|
||||
$out = array();
|
||||
foreach($items as $item) {
|
||||
$result = $item->matches($terms);
|
||||
if($result) {
|
||||
$out[] = array($item, $result);
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
|
||||
==================================================
|
||||
|
||||
*/
|
||||
|
||||
$mustIncludeArray = array();
|
||||
$mustExcludeArray = array();
|
||||
$canIncludeArray = array();
|
||||
|
||||
foreach($terms as $term) {
|
||||
switch ($term[$i][0]) {
|
||||
case "+":
|
||||
$mustIncludeArray[] = array(substr($term[$i], 1));
|
||||
case "!":
|
||||
case "-":
|
||||
$mustExcludeArray[] = array(substr($term[$i], 1));
|
||||
case "~":
|
||||
$canIncludeArray[] = array(substr($term[$i], 1));
|
||||
default:
|
||||
$canIncludeArray[] = array($term);
|
||||
}
|
||||
}
|
||||
|
||||
var_dump($mustIncludeArray);
|
||||
var_dump($mustExcludeArray);
|
||||
var_dump($canIncludeArray);
|
||||
|
||||
$items = get_items($type);
|
||||
$out = array();
|
||||
|
||||
/*
|
||||
foreach($items as $item) {
|
||||
$mustExcludeCheck = True;
|
||||
$resultExclude = $item->matches($mustExcludeArray);
|
||||
if($resultExclude) {
|
||||
|
||||
// if resultExclude is matching, do === nothing ===
|
||||
|
||||
} else {
|
||||
$mustIncludeCheck = False;
|
||||
if(count($mustIncludeArray) > 0) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
private function translate_terms($terms) {
|
||||
$matches = array();
|
||||
if(isset($terms['q']) && preg_match('/([^:]+):(.*)/',
|
||||
@ -127,95 +209,6 @@ class SearchPage extends Page {
|
||||
}
|
||||
return $translated;
|
||||
}
|
||||
|
||||
/*
|
||||
Takes two arrays ($type, $terms)
|
||||
Returns an array ($out) of products ($type) based on matches with search query terms ($terms)
|
||||
|
||||
*/
|
||||
|
||||
private function search($type, $terms) {
|
||||
/*
|
||||
|
||||
==================================================
|
||||
|
||||
ORIGINAL CODE || BACKUP || FOR REFERENCE
|
||||
|
||||
$items = get_items($type);
|
||||
$out = array();
|
||||
foreach($items as $item) {
|
||||
$result = $item->matches($terms);
|
||||
if($result) {
|
||||
$out[] = array($item, $result);
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
|
||||
==================================================
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
Break down terms into mustIncludeArray (MUST be included),
|
||||
mustExcludeArray (CANT be included),
|
||||
canIncludeArray (can be included)
|
||||
|
||||
Then matches all items based on specific MUST/CANT/Can include logic and adds to $out[] if passing the logic checks
|
||||
|
||||
*/
|
||||
|
||||
$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));
|
||||
} else if($term[$i][0] == "!" || $term[$i][0] == "-") {
|
||||
// adds to mustExcludeArray
|
||||
$mustExcludeArray[] = array(substr($term[$i], 1));
|
||||
} else {
|
||||
// adds to canIncludeArray
|
||||
$canIncludeArray[] = array($term);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($items as $item) {
|
||||
$mustExcludeCheck = True;
|
||||
$resultExclude = $item->matches($mustExcludeArray);
|
||||
if($resultExclude) {
|
||||
|
||||
} else {
|
||||
$mustIncludeCheck = False;
|
||||
if(count($mustIncludeArray) > 0) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
protected function render_body() {
|
||||
$hidden = 'hidden';
|
||||
|
Loading…
x
Reference in New Issue
Block a user