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 -N -r1.29 -r1.30 --- openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-procs.tcl 30 Mar 2013 18:19:48 -0000 1.29 +++ openacs-4/packages/tsearch2-driver/tcl/tsearch2-driver-procs.tcl 27 Oct 2014 16:42:00 -0000 1.30 @@ -252,21 +252,31 @@ regsub -all {[^-/@.\d\w\s\(\)]+} $query { } query # match parens, if they don't match just throw them away - set p 0 - for {set i 0} {$i < [string length $query]} {incr i} { - if {[string index $query $i] eq "("} { - incr p - } - if {[string index $query $i] eq ")"} { - incr p -1 - } - } - if {$p != 0} { - regsub -all {\(|\)} $query {} query - } + # set p 0 + # for {set i 0} {$i < [string length $query]} {incr i} { + # if {[string index $query $i] eq "("} { + # incr p + # } + # if {[string index $query $i] eq ")"} { + # incr p -1 + # } + # } + # if {$p != 0} { + # regsub -all {\(|\)} $query {} query + # } - # remove or at beginning of query + # remove all parens + regsub -all {\(|\)} $query {} query + + # remove empty () + regsub -all {\(\s*\)} $query {} query + + # remove "or" at beginning of query regsub -nocase "^or " $query {} query + + # remove "not" at end of query + regsub -nocase " not$" $query {} query + # replace boolean words with boolean operators regsub -nocase "^not " $query {!} query set query [string map {" and " " & " " or " " | " " not " " ! "} " $query "] @@ -322,8 +332,9 @@ set end_q 0 set valid_operators [tsearch2_driver::valid_operators] foreach e [split $query] { - if {[regexp {(^\w*):} $e discard operator] \ - && [lsearch -exact $valid_operators $operator] != -1} { + if {[regexp {(^\w*):} $e discard operator] + && $operator in $valid_operators + } { # query element contains an operator, split operator from # query fragment set e [split $e ":"] @@ -363,7 +374,10 @@ ns_log debug "operator(e)='${e}' start_q=$start_q end_q=$end_q" if {$last_operator ne ""} { # FIXME need introspection for operator phrase support - if {($last_operator eq "title:" || $last_operator eq "description:") && ($start_q || $end_q)} { + if { + ($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} {}] @@ -378,7 +392,7 @@ } foreach op $valid_operators { - if {[exists_and_not_null $op]} { + if {([info exists $op] && [set $op] ne "")} { lappend operators $op $title } }