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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/tsearch2-driver/tsearch2-driver.info 6 Jun 2004 01:33:17 -0000 1.1 @@ -0,0 +1,26 @@ + + + + + Tsearch2 Driver + Tsearch2 Drivers + f + t + + + Dave Bauer + Full text search support for Search via Tsearch2. + Provides an implementation for the search packages service contract for searching on postgresql. + 0 + + + + + + + + + + + + Index: openacs-4/packages/tsearch2-driver/sql/postgresql/tsearch2-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/tsearch2-driver/sql/postgresql/Attic/tsearch2-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/tsearch2-driver/sql/postgresql/tsearch2-create.sql 6 Jun 2004 01:33:18 -0000 1.1 @@ -0,0 +1,20 @@ +-- +-- tsearch2 based FTSEngineDriver for Search package +-- +-- @author Dave Bauer (dave@thedesignexperience.org) +-- @creation-date 2004-06-05 +-- @arch-tag: 25662a8a-e960-4888-bd9f-3e7a8fff5637 +-- @cvs-id $Id: tsearch2-create.sql,v 1.1 2004/06/06 01:33:18 daveb Exp $ +-- + +-- FIXME need to load tsearch2.sql from postgresql/share/contrib +-- (on debian /usr/share/postgresql/contrib) +--create table txt ( +-- object_id integer +-- constraint txt_object_id_fk +-- references acs_objects, +-- fti tsvector +--); + +--create index fti_idx on txt using gist(fti); + Index: openacs-4/packages/tsearch2-driver/sql/postgresql/tsearch2-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/tsearch2-driver/sql/postgresql/Attic/tsearch2-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/tsearch2-driver/sql/postgresql/tsearch2-drop.sql 6 Jun 2004 01:33:18 -0000 1.1 @@ -0,0 +1,10 @@ +-- +-- +-- +-- @author Dave Bauer (dave@thedesignexperience.org) +-- @creation-date 2004-06-05 +-- @arch-tag: da4f668f-eba3-40a1-8efb-23c347e312c9 +-- @cvs-id $Id: tsearch2-drop.sql,v 1.1 2004/06/06 01:33:18 daveb Exp $ +-- + +drop table txt; 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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-install-procs.tcl 6 Jun 2004 01:33:18 -0000 1.1 @@ -0,0 +1,57 @@ +# + +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 + @cvs-id $Id: tsearch2-driver-install-procs.tcl,v 1.1 2004/06/06 01:33:18 daveb Exp $ +} + +namespace eval tsearch2_driver::install {} + +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 +} { + 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 +} { + + 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::info + } + contract_name "FtsEngineDriver" + owner "tsearch2-driver" + } + + acs_sc::impl::new_from_spec -spec $spec + +} + 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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-procs.tcl 6 Jun 2004 01:33:18 -0000 1.1 @@ -0,0 +1,172 @@ +# + +ad_library { + + Procedures for tsearch full text enginge driver + + @author Dave Bauer (dave@thedesignexperience.org) + @creation-date 2004-06-05 + @arch-tag: 49a5102d-7c06-4245-8b8d-15a3b12a8cc5 + @cvs-id $Id: tsearch2-driver-procs.tcl,v 1.1 2004/06/06 01:33:18 daveb Exp $ +} + +namespace eval ::tsearch2 {} + +ad_proc -private tsearch2::index { + object_id + txt + title + keywords +} { + + add object to full text index + + @author Dave Bauer (dave@thedesignexperience.org) + @creation-date 2004-06-05 + + @param object_id + @param txt + @param title + @param keywords + + @return + + @error +} { + set index_exists_p [db_0or1row object_exists "select 1 from txt where object_id=:object_id"] + if {!$index_exists_p} { + db_dml index "insert into txt (object_id,fti) values ( :object_id, to_tsvector('default',:txt))" + + } else { + tsearch2::update_index $object_id $txt $title $keywords + } + +} + +ad_proc -private tsearch2::unindex { + object_id +} { + Remove item from FTS index + + @author Dave Bauer (dave@thedesignexperience.org) + @creation-date 2004-06-05 + + @param object_id + + @return + + @error +} { + db_dml unindex "delete from txt where object_id=:object_id" +} + +ad_proc -private tsearch2::update_index { + object_id + txt + title + keywords +} { + + update full text index + + @author Dave Bauer (dave@thedesignexperience.org) + @creation-date 2004-06-05 + + @param object_id + @param txt + @param title + @param keywords + + @return + + @error +} { + set index_exists_p [db_0or1row object_exists "select 1 from txt where object_id=:object_id"] + if {!$index_exists_p} { + db_dml index "insert into txt (object_id,fti) values ( :object_id, to_tsvector('default',:txt))" + } else { + db_dml update_index "update txt set fti = to_tsvector('default',:txt) where object_id=:object_id" + } + +} + +ad_proc -private tsearch2::search { + query + offset + limit + user_id + df + dt +} { + + ftsenginedriver search operation implementation for tsearch2 + + @author Dave Bauer (dave@thedesignexperience.org) + @creation-date 2004-06-05 + + @param query + + @param offset + + @param limit + + @param user_id + + @param df + + @param dt + + @return + + @error +} { + # clean up query + # turn and into & + # turn or into | + # turn not into ! + + # FIXME actually write the regsub to do that, string map will + # probably be too tricky to use + + set results_ids [db_list search "select object_id from txt where fti @@ to_tsquery(:query) order by rank(fti,to_tsquery(:query));"] + + 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 [llength $results_ids]] +} + +ad_proc -private tsearch2::summary { + query + txt +} { + + + @author Dave Bauer (dave@thedesignexperience.org) + @creation-date 2004-06-05 + + @param query + + @param txt + + @return summary containing search query terms + + @error +} { + return [db_string summary "select headline(:txt,to_tsquery(:query))"] +} + +ad_proc -private tsearch2::info { +} { + + + @author Dave Bauer (dave@thedesignexperience.org) + @creation-date 2004-06-05 + + @return + + @error +} { + return [list package_key tsearch2-driver version 2 automatic_and_queries_p 0 stopwords_p 1] +} +