tsearch2::separate_query_and_operators (private)
tsearch2::separate_query_and_operators [ -query query ]
Defined in packages/tsearch2-driver/tcl/tsearch2-driver-procs.tcl
Separates special operators from full text query
- Switches:
- -query (optional)
- Returns:
- list of query and operators
- Error:
- Author:
- Dave Bauer <dave@thedesignexperience.org>
- Created:
- 2004-07-10
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
Source code: # remove evil characters regsub {\[|\]|\{|\}} $query {} query # match quotes set quote_count [regexp -all {\"} $query] # if quotes don't match, just remove all of them if {$quote_count % 2 == 1} { regsub -all {\"} $query {} query } set main_query "" set operators "" set last_operator "" set start_q 0 set end_q 0 set valid_operators [tsearch2_driver::valid_operators] foreach e [split $query] { if {[regexp {(^\w*):} $e discard operator] && $operator in $valid_operators } { # query element contains an operator, split operator from # query fragment set e [split $e ":"] set e [list $operator [lindex $e 1]] } # count quotes to see if this element # is part of a phrase if {$start_q ne 1} { set start_q [regexp {^\"} $e] } set end_q [regexp {\"$} $e] if {$start_q} { 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 lassign $e last_operator e } else { set last_operator "" } # regular search term 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) } { lappend ${last_operator}_phrase [regsub -all {\"} $e {}] } else { lappend $last_operator [regsub -all {\"} ${e} {}] } } else { if {$start_q || $end_q} { lappend phrase $e } else { lappend main_query $e } } } foreach op $valid_operators { if {[info exists $op] && [set $op] ne ""} { lappend operators $op $title } } lappend result $main_query if {$operators ne ""} { lappend result $operators } return $resultXQL Not present: Generic, Oracle PostgreSQL XQL file: packages/tsearch2-driver/tcl/tsearch2-driver-procs-postgresql.xql