Index: openacs-4/packages/tsearch2-driver/tsearch2-driver.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/tsearch2-driver/tsearch2-driver.info,v diff -u -r1.19.2.2 -r1.19.2.3 --- openacs-4/packages/tsearch2-driver/tsearch2-driver.info 3 May 2020 18:00:42 -0000 1.19.2.2 +++ openacs-4/packages/tsearch2-driver/tsearch2-driver.info 24 Feb 2021 12:51:17 -0000 1.19.2.3 @@ -9,14 +9,14 @@ f t - + Dave Bauer Full text search support for Search via Tsearch2. 2017-08-06 Provides an implementation for the search packages service contract for searching on PostgreSQL. 3 - + @@ -28,6 +28,7 @@ + Fisheye: Tag 1.1 refers to a dead (removed) revision in file `openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-init.tcl'. Fisheye: No comparison available. Pass `N' to diff? Index: openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-procs.tcl,v diff -u -r1.41.2.4 -r1.41.2.5 --- openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-procs.tcl 3 May 2020 18:00:42 -0000 1.41.2.4 +++ openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-procs.tcl 24 Feb 2021 12:51:17 -0000 1.41.2.5 @@ -135,6 +135,7 @@ # Clean up query for tsearch2 # set query [tsearch2::build_query -query $query] + # ns_log notice "-----build_query returned: $query" set where_clauses "" set from_clauses "" @@ -240,7 +241,7 @@ return [list package_key tsearch2-driver version 2 automatic_and_queries_p 0 stopwords_p 1] } -ad_proc tsearch2::build_query { -query } { +ad_proc tsearch2::build_query_tcl { -query } { Convert conjunctions to query characters for tsearch2 and => & not => ! @@ -302,6 +303,60 @@ return $query } +ad_proc tsearch2::build_query_postgres { -query } { + Convert conjunctions to query characters for tsearch2 + use websearch_to_tsquery which is integrated in postgres >= 11 + + websearch_to_tsquery creates a tsquery value from querytext using + an alternative syntax in which simple unformatted text is a valid + query. Unlike plainto_tsquery and phraseto_tsquery, it also + recognizes certain operators. Moreover, this function should never + raise syntax errors, which makes it possible to use raw user-supplied + input for search. The following syntax is supported: + + + For further documentation see also: + https://www.postgresql.org/docs/11/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES + + @param query string to convert + @return returns formatted query string for tsearch2 tsquery +} { + ad_try { + ::xo::dc 1row build_querystring {select websearch_to_tsquery(:query) as query from dual} + } on error {errorMsg} { + ns_log warning "tsearch2 websearch_to_tsquery failed, fall back to tcl query builder query was: $query errorMsg: $errorMsg" + set query [tsearch2::build_query_tcl -query $query] + } + return $query +} + +ad_proc tsearch2::build_query { + -query +} { + Build query string for tsearch2 + + @param query string to convert + @return returns formatted query string for tsearch2 tsquery +} { + if {$::tsearch2_driver::use_web_search_p + && [db_compatible_rdbms_p postgresql] + && [lindex [split [db_version] .] 0] >= 11 + } { + set query [tsearch2::build_query_postgres -query $query] + } else { + set query [tsearch2::build_query_tcl -query $query] + } + + return $query +} + ad_proc -public tsearch2::separate_query_and_operators { -query } {