From ccc0315ef0a115fb9111823b351bbcbdf3182f66 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 30 Apr 2019 14:39:08 +0300 Subject: better tsquery support: 1. report query syntax errors properly 2. fall back to implicit &-joining only if no joiners are detected in user query, otherwise permit full tsquery syntax --- include/functions.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'include/functions.php') diff --git a/include/functions.php b/include/functions.php index 963018858..6dc9990e8 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1486,11 +1486,19 @@ } if (count($search_query_leftover) > 0) { - $search_query_leftover = $pdo->quote(implode(" & ", $search_query_leftover)); if (DB_TYPE == "pgsql") { + + // if there's no joiners consider this a "simple" search and + // concatenate everything with &, otherwise don't try to mess with tsquery syntax + if (preg_match("/[&|]/", implode(" " , $search_query_leftover))) { + $tsquery = $pdo->quote(implode(" ", $search_query_leftover)); + } else { + $tsquery = $pdo->quote(implode(" & ", $search_query_leftover)); + } + array_push($query_keywords, - "(tsvector_combined @@ to_tsquery($search_language, $search_query_leftover))"); + "(tsvector_combined @@ to_tsquery($search_language, $tsquery))"); } } -- cgit v1.2.3