From f0b1c2cf400cb91fa2078641d7040e3c12d786d4 Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 21 Mar 2024 22:38:37 +0200 Subject: [PATCH] use native query builder --- src/webui/search.php | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/src/webui/search.php b/src/webui/search.php index be09220..ec27fed 100644 --- a/src/webui/search.php +++ b/src/webui/search.php @@ -115,12 +115,14 @@ if ($config->webui->search->index->request->url->enabled && filter_var($q, FILTE // Extended corrections switch (true) { + // Empty query case empty($q): $query = $index->search('')->sort('RAND()'); break; + // URL request case filter_var($q, FILTER_VALIDATE_URL): $query = $index->search('')->filter('id', crc32($q)); @@ -136,42 +138,12 @@ switch (true) $query = $index->search($q); } - // Escape reserved chars - // http://sphinxsearch.com/docs/current/extended-syntax.html + // Regular request else { - // Remove separator duplicates - $q = trim( - preg_replace( - '/[\s]+/ui', - ' ', - $q - ) - ); - - // Escape special chars - $request = @\Manticoresearch\Utils::escape( - $q - ); - - // Explode search phrase - $words = []; - foreach ((array) explode(' ', $request) as $word) - { - $words[] = trim( - $word - ); - } - - // Build combined query $query = $index->search( - sprintf( - '"%s"|%s', - $request, - implode( - '|', - $words - ) + @\Manticoresearch\Utils::escape( + $q ) ); }