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.33 -r1.34 --- openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-procs.tcl 7 Aug 2017 23:48:29 -0000 1.33 +++ openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-procs.tcl 28 Feb 2018 08:35:16 -0000 1.34 @@ -9,6 +9,29 @@ namespace eval tsearch2 {} +ad_proc -private tsearch2::trunc_to_max {txt} { + + tsearch has (at least up to PostgreSQL 10) the limitation that + the length of tsvector is 1MB. so make sure, we do not raise + errors, when this happens. + + https://www.postgresql.org/docs/current/static/textsearch-limitations.html +} { + set max_size_to_index [db_string get_max_size_to_index { + select min(default_value) from apm_parameters + where package_key = 'tsearch2-driver' and + parameter_name = 'max_size_to_index' + } -default "1048575"] + if {$max_size_to_index == 0} { + set max_size_to_index 1048575 + } + if {$max_size_to_index > 0 && [string length $txt] > $max_size_to_index} { + ns_log notice "tsearch2: truncate overlong string to $max_size_to_index bytes" + set txt [string range $txt 0 $max_size_to_index-1] + } + return $txt +} + ad_proc -public tsearch2::index { object_id txt @@ -29,11 +52,8 @@ } { set index_exists_p [db_0or1row object_exists "select 1 from txt where object_id=:object_id"] if {!$index_exists_p} { - set max_size_to_index [db_string get_max_size_to_index "select min(default_value) from apm_parameters where package_key = 'tsearch2-driver' and parameter_name = 'max_size_to_index'" -default "0"] - if {$max_size_to_index > 0} { - set txt [string range $txt 0 $max_size_to_index] - } - db_dml index {} + set txt [tsearch2::trunc_to_max $txt] + db_dml index {} } else { tsearch2::update_index $object_id $txt $title $keywords } @@ -76,10 +96,7 @@ if {!$index_exists_p} { tsearch2::index $object_id $txt $title $keywords } else { - set max_size_to_index [db_string get_max_size_to_index "select min(default_value) from apm_parameters where package_key = 'tsearch2-driver' and parameter_name = 'max_size_to_index'" -default "0"] - if {$max_size_to_index > 0} { - set txt [string range $txt 0 $max_size_to_index] - } + set txt [tsearch2::trunc_to_max $txt] db_dml update_index "" } }