Fix bug where fields + note was not creating space, and therefore some regex where not working
This commit is contained in:
parent
6be8bd5564
commit
959a26c8ba
|
@ -189,7 +189,7 @@ if (isset($_GET['profile']) && trim($_GET['profile']) != '')
|
|||
if (gettype($a_fields) === 'array')
|
||||
foreach ($a_fields as $field)
|
||||
$fields .= $field['name'].' '.$field['value'].' ';
|
||||
$a_note = trim($fields) . $a_note;
|
||||
$a_note = trim(trim($fields) . ' ' . $a_note);
|
||||
|
||||
if ($qt === 'empty') {
|
||||
if ($a_note === '') {
|
||||
|
@ -202,6 +202,8 @@ if (isset($_GET['profile']) && trim($_GET['profile']) != '')
|
|||
continue;
|
||||
|
||||
$matches = false;
|
||||
$debug_search = (isset($_GET['debug_search']) && $account['id'] === trim($_GET['debug_search']));
|
||||
|
||||
if ($enable_caching && isset($match_data[$account['id']])) {
|
||||
$matches = $match_data[$account['id']];
|
||||
} else if ($qt === 'simple') {
|
||||
|
@ -221,7 +223,7 @@ if (isset($_GET['profile']) && trim($_GET['profile']) != '')
|
|||
}
|
||||
}
|
||||
} else if ($qt === 'expr')
|
||||
$matches = matches_comparing_expression($q, $a_note);
|
||||
$matches = matches_comparing_expression($q, $a_note, $debug_search);
|
||||
|
||||
if ($user_filter === 'remote' && $enable_caching)
|
||||
$match_data[$account['id']] = $matches;
|
||||
|
|
67
base.php
67
base.php
|
@ -453,11 +453,20 @@ function parse_comparing_expression($expr) {
|
|||
];
|
||||
}
|
||||
|
||||
function matches_comparing_expression($expr, $text) {
|
||||
function matches_comparing_expression($expr, $text, $debug=false) {
|
||||
if (gettype($expr) === 'string')
|
||||
$expr = parse_comparing_expression($expr);
|
||||
$result = $expr['original'];
|
||||
if ($debug) {
|
||||
echo '<h2>Original</h2>';
|
||||
echo '<pre>'.$text.'</pre>';
|
||||
}
|
||||
$text = normalize_for_search($text);
|
||||
if ($debug) {
|
||||
echo '<h2>Normalized</h2>';
|
||||
echo '<pre>'.$text.'</pre>';
|
||||
echo '<br><br>';
|
||||
}
|
||||
$text_words = explode(' ', $text);
|
||||
foreach ($expr['parsed'] as $t)
|
||||
{
|
||||
|
@ -479,6 +488,16 @@ function matches_comparing_expression($expr, $text) {
|
|||
}
|
||||
}
|
||||
$bool = $hasall;
|
||||
if ($debug) {
|
||||
echo '<br><br>';
|
||||
echo '<h3>words</h3>';
|
||||
echo '<pre>';
|
||||
echo $content;
|
||||
echo '</pre>';
|
||||
echo '<br>Result: ';
|
||||
var_dump($bool);
|
||||
echo '<br>';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'anyword':
|
||||
|
@ -492,6 +511,16 @@ function matches_comparing_expression($expr, $text) {
|
|||
}
|
||||
}
|
||||
$bool = $hasany;
|
||||
if ($debug) {
|
||||
echo '<br><br>';
|
||||
echo '<h3>hasany</h3>';
|
||||
echo '<pre>';
|
||||
echo $content;
|
||||
echo '</pre>';
|
||||
echo '<br>Result: ';
|
||||
var_dump($bool);
|
||||
echo '<br>';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'has':
|
||||
|
@ -499,7 +528,19 @@ function matches_comparing_expression($expr, $text) {
|
|||
case 'contains':
|
||||
$a = str_replace(' ', '', $text);
|
||||
$b = str_replace(' ', '', normalize_for_search($content));
|
||||
if ($debug) {
|
||||
echo '<br><br>';
|
||||
echo '<h3>contains</h3>';
|
||||
echo '<pre>';
|
||||
echo $content;
|
||||
echo '</pre>';
|
||||
}
|
||||
$bool = strpos($a, $b) !== false;
|
||||
if ($debug) {
|
||||
echo '<br>Result: ';
|
||||
var_dump($bool);
|
||||
echo '<br>';
|
||||
}
|
||||
unset($a); unset($b);
|
||||
break;
|
||||
|
||||
|
@ -528,7 +569,19 @@ function matches_comparing_expression($expr, $text) {
|
|||
$content = '^.*'.$content;
|
||||
if ($content[strlen($content)-1] != '$')
|
||||
$content .= '.*$';
|
||||
if ($debug) {
|
||||
echo '<br><br>';
|
||||
echo '<h3>regex</h3>';
|
||||
echo '<pre>';
|
||||
echo $content;
|
||||
echo '</pre>';
|
||||
}
|
||||
$bool = preg_match('#'.$content.'#', $text) === 1;
|
||||
if ($debug) {
|
||||
echo '<br>Result: ';
|
||||
var_dump($bool);
|
||||
echo '<br>';
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
@ -539,7 +592,19 @@ function matches_comparing_expression($expr, $text) {
|
|||
$result = str_replace('NOT ', '!', $result);
|
||||
$result = str_replace('NOT', '!', $result);
|
||||
try {
|
||||
if ($debug) {
|
||||
echo '<br><hr>';
|
||||
echo '<h3>Final result</h3>';
|
||||
echo '<br>eval: ';
|
||||
var_dump($result);
|
||||
}
|
||||
eval('$result = '.$result.';');
|
||||
if ($debug) {
|
||||
echo '<br>';
|
||||
echo '<br>result: ';
|
||||
var_dump($result);
|
||||
die;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
return apiresult(['error' => 'Query contains errors, please correct it and try again.']);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue