Handle errors on search query + Make search work better

This commit is contained in:
Bofh 2022-12-12 23:18:49 +01:00
parent 725f2ab476
commit 5b00931878
2 changed files with 8 additions and 2 deletions

View File

@ -453,14 +453,19 @@ function matches_comparing_expression($expr, $text) {
} else if (strpos($t, 'contains ') === 0) {
$w = substr($t, strlen('contains')+1);
$w = trim(trim($w, '"'));
$contains = strpos($text, normalize_for_search($w)) !== false;
$contains = strpos(' '.$text.' ',
' '.normalize_for_search($w).' ') !== false;
$result = str_replace($t, $contains ? 'true' : 'false', $result);
}
}
}
$result = str_replace('OR', '|', $result);
$result = str_replace('AND', '&', $result);
eval('$result = '.$result.';');
try {
eval('$result = '.$result.';');
} catch (\Throwable $e) {
return apiresult(['error' => 'Query contains errors, please correct it and try again.']);
}
return in_array($result, [0,false]) ? false : true;
}

View File

@ -198,6 +198,7 @@ window.view.instance = {
http.get(`api/v1/database/${hargs.software}/accounts/search?${payload}&paging=${page},${items_per_page}`, data, function(js) {
if (js === undefined) return toast.error('Could not process the query result');
if (js.ok !== undefined) return toast.info(js.ok);
if (js.error !== undefined) return toast.error(js.error);
E.template('users-all', function(TPL) {
var html = '';
for (var i = 0; i < js['data'].length; i++) {