- search input is now handled as whitespace separated list of search terms (was direct input)
- substrings prefixed with '-' must not be matched
- substrings with a content length of less than 3 are ignored
This commit is contained in:
Sarjuuk
2014-03-22 22:37:45 +01:00
parent 93cc42407c
commit e8c512a5e8
14 changed files with 188 additions and 128 deletions

View File

@@ -747,6 +747,55 @@ abstract class Filter
}
}
protected function modularizeString(array $fields, $string = '')
{
if (!$string)
$string = $this->fiData['v']['na'];
$qry = [];
$valid = false;
foreach ($fields as $n => $f)
{
$sub = [];
$parts = explode(' ', $string);
foreach ($parts as $p)
{
if ($p[0] == '-' && strlen($p) > 3)
$sub[] = [$f, substr($p, 1), '!'];
else if ($p[0] != '-' && strlen($p) > 2)
{
$valid = true;
$sub[] = [$f, $p];
}
}
// single cnd?
if (!$sub)
continue;
else if (count($sub) > 1)
array_unshift($sub, 'AND');
else
$sub = $sub[0];
$qry[] = $sub;
}
if (!$valid) // no +term with length >= 3 set
{
$this->error = 1;
return [];
}
// single cnd?
if (count($qry) > 1)
array_unshift($qry, 'OR');
else
$qry = $qry[0];
return $qry;
}
protected function int2Op(&$op)
{
switch ($op)
@@ -824,9 +873,10 @@ abstract class Filter
private function genericString($field, $value, $localized)
{
$field .= $localized ? '_loc'.User::$localeId : null;
if (!$localized)
return [$field, (string)$value];
return [$field, (string)$value];
return $this->modularizeString([$field.'_loc'.User::$localeId], $value);
}
private function genericNumeric($field, &$value, $op, $castInt)