From d6b5f8b21030dc596f950f789bb70c694ef121aa Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 25 Feb 2024 09:07:57 +0200 Subject: [PATCH] build combined search query --- src/webui/search.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/webui/search.php b/src/webui/search.php index c59d90e..d6c6740 100644 --- a/src/webui/search.php +++ b/src/webui/search.php @@ -140,8 +140,37 @@ switch (true) // http://sphinxsearch.com/docs/current/extended-syntax.html else { + // Escape special chars + $q = @\Manticoresearch\Utils::escape( + $q + ); + + // Remove separator duplicates + $q = preg_replace( + '/[\s]+/ui', + ' ', + $q + ); + + // Explode search phrase + $words = []; + foreach ((array) explode(' ', $q) as $word) + { + $words[] = trim( + $word + ); + } + + // Build combined query $query = $index->search( - @\Manticoresearch\Utils::escape($q) + sprintf( + '"%s"|%s', + $q, + implode( + '|', + $words + ) + ) ); } }