Index: openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-install-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-install-procs.tcl,v diff -u -r1.7 -r1.8 --- openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-install-procs.tcl 7 Aug 2017 23:48:29 -0000 1.7 +++ openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-install-procs.tcl 1 Mar 2018 08:32:03 -0000 1.8 @@ -1,9 +1,7 @@ -# - ad_library { - + tsearch2 search engine driver installation procedures - + @author Dave Bauer (dave@thedesignexperience.org) @creation-date 2004-06-05 @arch-tag: 2006927e-7f1d-41c9-a111-ac552a4da185 @@ -16,101 +14,107 @@ ad_proc -public tsearch2_driver::install::preinstall_checks { } { - + Make sure postgresql_contrib and tsearch are installed before allowing the installation of tsearch2_package - + @author Hamilton Chua (hchua@8tons.dyndns.biz) @creation-date 2004-07-02 - + } { - ns_log Notice " ********** STARTING BEFORE-INSTALL CALLBACK ****************" + ns_log Notice " ********** STARTING BEFORE-INSTALL CALLBACK ****************" - # check if tsearch2 is installed - # in psql we do this by checking the presence of a data type tsvector - # select typname from pg_type where typename='tsvector'; + # check if tsearch2 is installed + # in psql we do this by checking the presence of a data type tsvector + # select typname from pg_type where typename='tsvector'; - if { [db_0or1row tsearch_compile_check { - select distinct(typname) from pg_type where typname='tsvector' - }] } { - # if tsearch is installed - ns_log Notice "******* Tsearch2 is compiled and installed. ***********" - # continue with installation - } else { - - # tsearch not installed - ns_log Notice "******* Tsearch2 is not installed. ***********" + if { [db_0or1row tsearch_compile_check { + select distinct(typname) from pg_type where typname='tsvector' + }] } { + # if tsearch is installed + ns_log Notice "******* Tsearch2 is compiled and installed. ***********" + # continue with installation + } else { - # RPM, Debian, source default locations - set locs [list "/usr/share/pgsql/contrib/tsearch2.sql" \ - "/usr/local/pgsql/contrib/tsearch2.sql" \ - "/usr/local/pgsql/share/contrib/tsearch2.sql" \ - "/usr/share/postgresql/contrib/tsearch2.sql"] - foreach loc $locs { - if { [file exists $loc] } { - set sql_file_loc $loc - break - } - } - # Check if we've found it, run the sql file - if { ([info exists sql_file_loc] && $sql_file_loc ne "") } { - # we found tsearch2.sql let's run it - db_source_sql_file $sql_file_loc - } else { - # we could not find tserach2.sql, abort the install - ns_log Notice "************************************************" - ns_log Notice "********* Can't locate tsearch2.sql. ***********" - ns_log Notice "********* Install tsearch2.sql manually ********" - ns_log Notice "************************************************" - ad_script_abort - } - - } - ns_log Notice " ********** ENDING BEFORE-INSTALL CALLBACK ****************" - + # tsearch not installed + ns_log Notice "******* Tsearch2 is not installed. ***********" + + # RPM, Debian, source default locations + set locs [list "/usr/share/pgsql/contrib/tsearch2.sql" \ + "/usr/local/pgsql/contrib/tsearch2.sql" \ + "/usr/local/pgsql/share/contrib/tsearch2.sql" \ + "/usr/share/postgresql/contrib/tsearch2.sql"] + foreach loc $locs { + if { [file exists $loc] } { + set sql_file_loc $loc + break + } + } + # Check if we've found it, run the sql file + if { [info exists sql_file_loc] && $sql_file_loc ne "" } { + # we found tsearch2.sql let's run it + db_source_sql_file $sql_file_loc + } else { + # we could not find tserach2.sql, abort the install + ns_log Notice "************************************************" + ns_log Notice "********* Can't locate tsearch2.sql. ***********" + ns_log Notice "********* Install tsearch2.sql manually ********" + ns_log Notice "************************************************" + ad_script_abort + } + + } + ns_log Notice " ********** ENDING BEFORE-INSTALL CALLBACK ****************" + } ad_proc -public tsearch2_driver::install::package_install { } { - + Installation callback for tsearch2 search engine driver - + @author Dave Bauer (dave@thedesignexperience.org) @creation-date 2004-06-05 - - @error + + @error } { tsearch2_driver::install::register_fts_impl } ad_proc -private tsearch2_driver::install::register_fts_impl { } { - + Register FtsEngineDriver service contract implementation @author Dave Bauer (dave@thedesignexperience.org) @creation-date 2004-06-05 - - @return - - @error + + @return + + @error } { set spec { - name "tsearch2-driver" - aliases { - search tsearch2::search - index tsearch2::index - unindex tsearch2::unindex - update_index tsearch2::update_index - summary tsearch2::summary - info tsearch2::driver_info - } - contract_name "FtsEngineDriver" - owner "tsearch2-driver" + name "tsearch2-driver" + aliases { + search tsearch2::search + index tsearch2::index + unindex tsearch2::unindex + update_index tsearch2::update_index + summary tsearch2::summary + info tsearch2::driver_info + } + contract_name "FtsEngineDriver" + owner "tsearch2-driver" } acs_sc::impl::new_from_spec -spec $spec - + } +# +# Local variables: +# mode: tcl +# tcl-indent-level: 4 +# indent-tabs-mode: nil +# End: 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.34 -r1.35 --- openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-procs.tcl 28 Feb 2018 08:35:16 -0000 1.34 +++ openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-procs.tcl 1 Mar 2018 08:32:03 -0000 1.35 @@ -10,23 +10,23 @@ 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' + 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 + 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" + 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 @@ -52,8 +52,8 @@ } { set index_exists_p [db_0or1row object_exists "select 1 from txt where object_id=:object_id"] if {!$index_exists_p} { - set txt [tsearch2::trunc_to_max $txt] - db_dml index {} + set txt [tsearch2::trunc_to_max $txt] + db_dml index {} } else { tsearch2::update_index $object_id $txt $title $keywords } @@ -96,7 +96,7 @@ if {!$index_exists_p} { tsearch2::index $object_id $txt $title $keywords } else { - set txt [tsearch2::trunc_to_max $txt] + set txt [tsearch2::trunc_to_max $txt] db_dml update_index "" } } @@ -108,7 +108,7 @@ # limit # user_id # df -#} +#} ad_proc -callback search::search -impl tsearch2-driver { {-extra_args {}} -query @@ -133,9 +133,9 @@ @error } { set packages {} - # JCD: I have done something horrible. I took out dt and + # JCD: I have done something horrible. I took out dt and # made it packages. when you search there is no way to specify a date range just - # last six months, last year etc. I hijack what was the old dt param and make it + # last six months, last year etc. I hijack what was the old dt param and make it # the package_id list and just empty string for dt. set dt {} @@ -170,13 +170,13 @@ } foreach {arg value} $extra_args { - array set arg_clauses [lindex [callback -impl $arg search::extra_arg -value $value -object_table_alias "o"] 0] - if {[info exists arg_clauses(from_clause)] && $arg_clauses(from_clause) ne ""} { - lappend from_clauses $arg_clauses(from_clause) - } - if {[info exists arg_clauses(where_clause)] && $arg_clauses(where_clause) ne ""} { - lappend where_clauses $arg_clauses(where_clause) - } + array set arg_clauses [lindex [callback -impl $arg search::extra_arg -value $value -object_table_alias "o"] 0] + if {[info exists arg_clauses(from_clause)] && $arg_clauses(from_clause) ne ""} { + lappend from_clauses $arg_clauses(from_clause) + } + if {[info exists arg_clauses(where_clause)] && $arg_clauses(where_clause) ne ""} { + lappend where_clauses $arg_clauses(where_clause) + } } if {[llength $extra_args]} { # extra_args can assume a join on acs_objects @@ -199,13 +199,11 @@ } else { lappend from_clauses "txt" } - - set results_ids [db_list search {}] + set results_ids [db_list search {}] set count [db_string count {}] + set stop_words {} - set stop_words [list] - # lovely the search package requires count to be returned but the # service contract definition doesn't specify it! return [list ids $results_ids stopwords $stop_words count $count] @@ -239,13 +237,13 @@ ad_proc -public tsearch2::driver_info { } { - + @author Dave Bauer (dave@thedesignexperience.org) @creation-date 2004-06-05 - - @return - - @error + + @return + + @error } { return [list package_key tsearch2-driver version 2 automatic_and_queries_p 0 stopwords_p 1] } @@ -256,7 +254,7 @@ not => ! or => | space => | (or) - + @param string string to convert @return returns formatted query string for tsearch2 tsquery } { @@ -284,10 +282,10 @@ # remove empty () regsub -all {\(\s*\)} $query {} query - # remove "or" at beginning of query + # remove "or" at beginning of query regsub -nocase "^or " $query {} query - # remove "not" at end of query + # remove "not" at end of query regsub -nocase " not$" $query {} query # replace boolean words with boolean operators @@ -304,7 +302,7 @@ } # if a ! is by itself then prepend & regsub -all {(\w+?)\s*(!)} $query {\1 \& !} query - # if there is )( then insert an & between them + # if there is )( then insert an & between them # or if there is )\w or \w( insert an & between them regsub {(\))([\(\w])} $query {\1 \& \2} query regsub {([\)\w])(\()} $query {\1 \& \2} query @@ -318,19 +316,19 @@ -query } { Separates special operators from full text query - + @author Dave Bauer (dave@thedesignexperience.org) @creation-date 2004-07-10 - + @param query @return list of query and operators - - @error + + @error } { # remove evil characters regsub {\[|\]|\{|\}} $query {} query - + # match quotes set quote_count [regexp -all {\"} $query] # if quotes don't match, just remove all of them @@ -346,7 +344,7 @@ set valid_operators [tsearch2_driver::valid_operators] foreach e [split $query] { if {[regexp {(^\w*):} $e discard operator] - && $operator in $valid_operators + && $operator in $valid_operators } { # query element contains an operator, split operator from # query fragment @@ -364,18 +362,18 @@ set sq {"} } else { set sq {} - } + } if {$end_q} { set start_q 0 set eq {"} } else { set eq {} - } + } # now that we know if its parts of a phrase, get rid of the # quotes regsub -all {\"} $e {} e - + if {[llength $e] > 1} { # query element contains a valid operator set last_operator [lindex $e 0] @@ -388,9 +386,9 @@ if {$last_operator ne ""} { # FIXME need introspection for operator phrase support if { - ($last_operator eq "title:" || $last_operator eq "description:") - && ($start_q || $end_q) - } { + ($last_operator eq "title:" || $last_operator eq "description:") + && ($start_q || $end_q) + } { lappend ${last_operator}_phrase [regsub -all {\"} $e {}] } else { lappend $last_operator [regsub -all {\"} ${e} {}] @@ -405,7 +403,7 @@ } foreach op $valid_operators { - if {([info exists $op] && [set $op] ne "")} { + if {[info exists $op] && [set $op] ne ""} { lappend operators $op $title } } @@ -420,10 +418,17 @@ } { @author Dave Bauer (dave@thedesignexperience.org) @creation-date 2005-03-06 - + @return list of advanced operator names - - @error + + @error } { return {title description package_id parent_id} } + +# +# Local variables: +# mode: tcl +# tcl-indent-level: 4 +# indent-tabs-mode: nil +# End: