callback::search::search::impl::tsearch2-driver (private)
callback::search::search::impl::tsearch2-driver [ -query query ] \ [ -user_id user_id ] [ -offset offset ] [ -limit limit ] \ [ -df df ] [ -dt dt ] [ -package_ids package_ids ] \ [ -object_type object_type ] [ -extra_args extra_args ]
Defined in packages/tsearch2-driver/tcl/tsearch2-driver-procs.tcl
ftsenginedriver search operation implementation for tsearch2
- Switches:
- -query (optional)
- -user_id (optional, defaults to
"0"
)- -offset (optional, defaults to
"0"
)- -limit (optional, defaults to
"10"
)- -df (optional)
- -dt (optional)
- -package_ids (optional)
- -object_type (optional)
- -extra_args (optional)
- Returns:
- Error:
- Author:
- Dave Bauer <dave@thedesignexperience.org>
- Created:
- 2004-06-05
- See Also:
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
Source code: ::callback::search::search::contract__arg_parser {*}$args set packages $package_ids set orig_query $query # # Clean up query for tsearch2 # set query [tsearch2::build_query -query $query] # ns_log notice "-----build_query returned: $query" set where_clauses "" set from_clauses "" set limit_clause "" set offset_clause "" if {[string is integer -strict $limit]} { set limit_clause " limit $limit " } if {[string is integer -strict $offset]} { set offset_clause " offset $offset " } set need_acs_objects 0 set base_query [db_map base_query] if {$df ne ""} { set need_acs_objects 1 lappend where_clauses "o.creation_date > :df" } if {$dt ne ""} { set need_acs_objects 1 lappend where_clauses "o.creation_date < :dt" } 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) } } if {[llength $extra_args]} { # extra_args can assume a join on acs_objects set need_acs_objects 1 } # generate the package id restriction. set ids {} foreach id $packages { if {[string is integer -strict $id]} { lappend ids $id } } if {$ids ne ""} { set need_acs_objects 1 lappend where_clauses "o.package_id in ([ns_dbquotelist $ids])" } if {$need_acs_objects} { lappend from_clauses "txt" "acs_objects o" lappend where_clauses "o.object_id = txt.object_id" } else { lappend from_clauses "txt" } set results_ids [db_list search {}] set count [db_string count {}] set stop_words {} # # 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]XQL Not present: Generic, Oracle PostgreSQL XQL file: <fullquery name="callback::search::search::impl::tsearch2-driver.base_query"> <rdbms> <type>postgresql</type> <version>8.4</version> </rdbms> <querytext> where fti @@ to_tsquery(:query) </querytext> </fullquery> <fullquery name="callback::search::search::impl::tsearch2-driver.search"> <rdbms> <type>postgresql</type> <version>8.3</version> </rdbms> <querytext> select txt.object_id from [join $from_clauses ","] $base_query [expr {[llength $where_clauses] > 0 ? " and " : ""}] [join $where_clauses " and "] order by ts_rank(fti,to_tsquery(:query)) desc $limit_clause $offset_clause </querytext> </fullquery> <fullquery name="callback::search::search::impl::tsearch2-driver.search"> <rdbms> <type>postgresql</type> <version>8.4</version> </rdbms> <querytext> select distinct(orig_object_id) from acs_permission.permission_p_recursive_array(array( select txt.object_id from [join $from_clauses ","] $base_query [expr {[llength $where_clauses] > 0 ? " and [join $where_clauses { and }]" : ""}] order by ts_rank(fti,to_tsquery(:query)) desc ), :user_id, 'read') $limit_clause $offset_clause </querytext> </fullquery> <fullquery name="callback::search::search::impl::tsearch2-driver.count"> <rdbms> <type>postgresql</type> <version>8.3</version> </rdbms> <querytext> select count(*) from [join $from_clauses ","] $base_query [expr {[llength $where_clauses] > 0 ? " and [join $where_clauses { and }]" : ""}] </querytext> </fullquery> <fullquery name="callback::search::search::impl::tsearch2-driver.count"> <rdbms> <type>postgresql</type> <version>8.2</version> </rdbms> <querytext> select count(*) from [join $from_clauses ","] $base_query [expr {[llength $where_clauses] > 0 ? " and " : ""}] [join $where_clauses " and "] </querytext> </fullquery>packages/tsearch2-driver/tcl/tsearch2-driver-procs-postgresql.xql