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.7 -r1.8 --- openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-procs.tcl 3 Jul 2004 21:10:22 -0000 1.7 +++ openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-procs.tcl 30 Dec 2004 14:10:47 -0000 1.8 @@ -125,8 +125,7 @@ # turn or into | # turn not into ! set query [tsearch2::build_query -query $query] - # FIXME actually write the regsub to do that, string map will - # probably be too tricky to use + set limit_clause "" set offset_clause "" if {[string is integer $limit]} { @@ -135,7 +134,10 @@ if {[string is integer $offset]} { set offset_clause " offset :offset " } - set query_text "select object_id from txt where fti @@ to_tsquery('default',:query) order by rank(fti,to_tsquery('default',:query)) ${limit_clause} ${offset_clause}" + set query_text "select object_id from txt where fti @@ to_tsquery('default',:query) and exists (select 1 from from acs_object_party_privilege_map m + where m.object_id = txt.object_id + and m.party_id = :user_id + and m.privilege = 'read')order by rank(fti,to_tsquery('default',:query)) ${limit_clause} ${offset_clause}" set results_ids [db_list search $query_text] set count [db_string count "select count(*) from txt where fti @@ to_tsquery('default',:query)"] set stop_words [list] @@ -162,7 +164,7 @@ @error } { set query [tsearch2::build_query -query $query] - return [db_string summary "select headline(:txt,to_tsquery('default',:query))"] + return [db_string summary "select headline('default',:txt,to_tsquery('default',:query))"] } ad_proc -public tsearch2::driver_info { @@ -188,15 +190,19 @@ @param string string to convert @return returns formatted query string for tsearch2 tsquery } { + # get rid of everything that isn't a letter or number + regsub -all {[^?\d\w\s]} $query {} query + # replace boolean words with boolean operators set query [string map {" and " & " or " | " not " !} $query] # remove leading and trailing spaces so they aren't turned into | set query [string trim $query] # remove any spaces between words and operators regsub -all {\s+([!&|])\s+} $query {\1} query # all remaining spaces between words turn into | - regsub -all {\s+} $query {|} query + regsub -all {\s+} $query {\&} query # if a ! is by itself then prepend & regsub {(\w)([!])} $query {\1\&!} query + return $query -} \ No newline at end of file +}