diff --git a/api/v1/database/mastodon/accounts/search/mod.php b/api/v1/database/mastodon/accounts/search/mod.php index c5a6d7d..d882b26 100644 --- a/api/v1/database/mastodon/accounts/search/mod.php +++ b/api/v1/database/mastodon/accounts/search/mod.php @@ -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; diff --git a/base.php b/base.php index 9723a8b..f7ee360 100644 --- a/base.php +++ b/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 '

Original

'; + echo '
'.$text.'
'; + } $text = normalize_for_search($text); + if ($debug) { + echo '

Normalized

'; + echo '
'.$text.'
'; + echo '

'; + } $text_words = explode(' ', $text); foreach ($expr['parsed'] as $t) { @@ -479,6 +488,16 @@ function matches_comparing_expression($expr, $text) { } } $bool = $hasall; + if ($debug) { + echo '

'; + echo '

words

'; + echo '
';
+					echo $content;
+					echo '
'; + echo '
Result: '; + var_dump($bool); + echo '
'; + } break; case 'anyword': @@ -492,6 +511,16 @@ function matches_comparing_expression($expr, $text) { } } $bool = $hasany; + if ($debug) { + echo '

'; + echo '

hasany

'; + echo '
';
+					echo $content;
+					echo '
'; + echo '
Result: '; + var_dump($bool); + echo '
'; + } 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 '

'; + echo '

contains

'; + echo '
';
+					echo $content;
+					echo '
'; + } $bool = strpos($a, $b) !== false; + if ($debug) { + echo '
Result: '; + var_dump($bool); + echo '
'; + } 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 '

'; + echo '

regex

'; + echo '
';
+					echo $content;
+					echo '
'; + } $bool = preg_match('#'.$content.'#', $text) === 1; + if ($debug) { + echo '
Result: '; + var_dump($bool); + echo '
'; + } 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 '

'; + echo '

Final result

'; + echo '
eval: '; + var_dump($result); + } eval('$result = '.$result.';'); + if ($debug) { + echo '
'; + echo '
result: '; + var_dump($result); + die; + } } catch (\Throwable $e) { return apiresult(['error' => 'Query contains errors, please correct it and try again.']); }