Index: openacs-4/packages/contacts/tcl/contact-search-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contact-search-procs.tcl,v
diff -u -r1.3 -r1.4
--- openacs-4/packages/contacts/tcl/contact-search-procs.tcl 7 Jun 2005 19:18:49 -0000 1.3
+++ openacs-4/packages/contacts/tcl/contact-search-procs.tcl 10 Jun 2005 09:23:27 -0000 1.4
@@ -36,18 +36,6 @@
return [package_instantiate_object -var_list $var_list contact_search]
}
-ad_proc -public contact::search::results_count {
- {-search_id ""}
- {-rel_type ""}
- {-object_type}
-} {
- create a contact search
-} {
-
- return [db_string get_total_count {}]
-
-}
-
ad_proc -public contact::search::update {
{-search_id ""}
{-title ""}
@@ -87,7 +75,100 @@
}
}
+ad_proc -public contact::search::results_count {
+ {-search_id}
+ {-query ""}
+} {
+ Get the total number of results from a search. Cached.
+} {
+ return [util_memoize [list ::contact::search::results_count_not_cached -search_id $search_id -query $query]]
+}
+
+ad_proc -public contact::search::results_count_not_cached {
+ {-search_id}
+ {-query ""}
+} {
+ Get the total number of results from a search
+} {
+ return [db_string select_results_count {}]
+}
+
+
+
+
+ad_proc -public contact::search_clause {
+ {-and:boolean}
+ {-search_id}
+ {-query ""}
+ {-party_id "party_id"}
+ {-revision_id "revision_id"}
+} {
+ Get the search clause for a search_id
+
+ @param and Set this flag if you want the result to start with an 'and' if the list of where clauses returned is non-empty.
+} {
+ set query [string trim $query]
+ set search_clauses [list]
+ set where_clause [contact::search::where_clause -search_id $search_id -party_id $party_id -revision_id $revision_id]
+
+ if { [exists_and_not_null where_clause] } {
+ lappend search_clauses $where_clause
+ }
+ if { [exists_and_not_null query] } {
+ lappend search_clauses [contact::search::query_clause -query $query -party_id $party_id]
+ }
+
+ set result {}
+ if { [llength $search_clauses] > 0 } {
+ if { $and_p } {
+ append result "and "
+ }
+ if { [llength $search_clauses] > 1 } {
+ append result "( [join $search_clauses "\n and "] )"
+ } else {
+ append result [join $search_clauses "\n and "]
+ }
+ }
+ return $result
+}
+
+ad_proc -public contact::search::query_clause {
+ {-and:boolean}
+ {-query ""}
+ {-party_id "party_id"}
+} {
+ create a contact search query. If the query supplied is an integer
+ it searches for the party_id otherwise the search is for contacts
+ that match all
+
+ @param and Set this flag if you want the result to start with an 'and' if the list of where clauses returned is non-empty.
+} {
+ set query [string trim $query]
+ set query_clauses [list]
+
+ if { [string is integer $query] } {
+ lappend query_clauses "$party_id = $query"
+ } elseif { [exists_and_not_null query] } {
+ foreach term $query {
+ lappend query_clauses "upper(contact__name($party_id)) like upper('%${term}%')"
+ }
+ }
+
+ set result {}
+ if { [llength $query_clauses] > 0 } {
+ if { $and_p } {
+ append result "and "
+ }
+ if { [llength $query_clauses] > 1 } {
+ append result "( [join $query_clauses "\n and "] )"
+ } else {
+ append result [join $query_clauses "\n and "]
+ }
+ }
+ return $result
+}
+
ad_proc -public contact::search::condition::new {
{-search_id}
{-type}
@@ -132,41 +213,70 @@
-ad_proc -public contact::search::where_clauses {
+ad_proc -public contact::search::where_clause {
{-search_id}
{-and:boolean}
{-party_id}
{-revision_id}
} {
} {
- db_1row get_em { select title, owner_id, all_or_any, object_type from contact_searches where search_id = :search_id }
- if { $all_or_any == "any" } {
- set operator "or"
+ if { $and_p } {
+ return [util_memoize [list ::contact::search::where_clause_not_cached \
+ -search_id $search_id \
+ -and \
+ -party_id $party_id \
+ -revision_id $revision_id]]
} else {
- set operator "and"
+ return [util_memoize [list ::contact::search::where_clause_not_cached \
+ -search_id $search_id \
+ -party_id $party_id \
+ -revision_id $revision_id]]
}
- set where_clause ""
- set first_condition_p 1
- db_foreach selectqueries {
- select type, var_list from contact_search_conditions where search_id = :search_id
- } {
- if { [string is false $first_condition_p] } {
- append where_clause "\n${operator} "
+}
+
+ad_proc -public contact::search::where_clause_not_cached {
+ {-search_id}
+ {-and:boolean}
+ {-party_id}
+ {-revision_id}
+} {
+} {
+ db_0or1row get_search_info {}
+ set where_clauses [list]
+
+ if { [exists_and_not_null all_or_any] } {
+ if { $all_or_any == "any" } {
+ set operator "or"
+ } else {
+ set operator "and"
}
- append where_clause [contact::search::translate -type $type -var_list $var_list -to code -revision_id $revision_id -party_id $party_id]
- set first_condition_p 0
+ if { $object_type == "person" } {
+ lappend where_clauses "$party_id in ( select person_id from persons )"
+ } elseif { $object_type == "organization" } {
+ lappend where_clauses "$party_id in ( select organization_id from organizations )"
+ }
+ db_foreach select_queries {} {
+ lappend where_clauses [contact::search::translate -type $type -var_list $var_list -to code -revision_id $revision_id -party_id $party_id]
+ }
+ } else {
+ set operator "and"
}
- if { [exists_and_not_null where_clause] } {
+
+ set result {}
+ if { [llength $where_clauses] > 0 } {
if { $and_p } {
- set where_clause "\n and ( $where_clause )"
+ append result "and "
+ }
+ if { [llength $where_clauses] > 1 } {
+ append result "( [join $where_clauses "\n $operator "] )"
} else {
- set where_clause "\n ( $where_clause )"
+ append result [join $where_clauses "\n $operator "]
}
}
- return $where_clause
-
+ return $result
}
+
ad_proc -public contact::search::translate {
{-type}
{-var_list}
Index: openacs-4/packages/contacts/www/contact-add.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/contact-add.adp,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/contacts/www/contact-add.adp 25 May 2005 16:23:51 -0000 1.2
+++ openacs-4/packages/contacts/www/contact-add.adp 10 Jun 2005 09:23:27 -0000 1.3
@@ -5,5 +5,17 @@
party_ae.first_names
+
+
+
Index: openacs-4/packages/contacts/www/index.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/index.adp,v
diff -u -r1.6 -r1.7
--- openacs-4/packages/contacts/www/index.adp 28 May 2005 15:44:06 -0000 1.6
+++ openacs-4/packages/contacts/www/index.adp 10 Jun 2005 09:23:27 -0000 1.7
@@ -8,11 +8,12 @@
search.query
Index: openacs-4/packages/contacts/www/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/index.tcl,v
diff -u -r1.5 -r1.6
--- openacs-4/packages/contacts/www/index.tcl 7 Jun 2005 18:55:37 -0000 1.5
+++ openacs-4/packages/contacts/www/index.tcl 10 Jun 2005 09:23:27 -0000 1.6
@@ -85,7 +85,7 @@
}
}
} elseif { $query_type == "search" } {
- lappend search_clause [contact::search::where_clauses -and -search_id $search_id -party_id "parties.party_id" -revision_id "revision_id"]
+ lappend search_clause [contact::search::where_clause -and -search_id $search_id -party_id "parties.party_id" -revision_id "revision_id"]
}
@@ -214,12 +214,15 @@
}
}
+# At least with openacs 5.1.5 list paginator does not use limit and offset commands.
+# this will likely be fixed in a future version, but until that is done we do not
+# need the overhead of the search clause in the multirow since the pagination proc
+# returns a list of valid party_ids the meet the search clause parameters. This
+# should increase the speed with which this query can be run
db_multirow -unclobber contacts contacts_select {}
+set contacts_total_count [contact::search::results_count -search_id $query_id -query $query]
-# TOTAL COUNT CODE
-set contacts_total_count [db_string contacts_total_count {}]
-
if { [exists_and_not_null query] && [template::multirow size contacts] == 1 } {
if { $query_type == "group" } {
set query_name [db_string get_it { select group_name from groups where group_id = :group_id }]
Index: openacs-4/packages/contacts/www/index.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/index.xql,v
diff -u -r1.3 -r1.4
--- openacs-4/packages/contacts/www/index.xql 18 May 2005 16:45:50 -0000 1.3
+++ openacs-4/packages/contacts/www/index.xql 10 Jun 2005 09:23:27 -0000 1.4
@@ -12,16 +12,6 @@
-
-
-select count(*)
- from parties left join cr_items on (parties.party_id = cr_items.item_id) left join cr_revisions on (cr_items.latest_revision = cr_revisions.revision_id ) , group_distinct_member_map
- where parties.party_id = group_distinct_member_map.member_id
- and group_distinct_member_map.group_id = '-2'
-$search_clause
-
-
-
@@ -71,7 +61,6 @@
from parties left join cr_items on (parties.party_id = cr_items.item_id) left join cr_revisions on (cr_items.latest_revision = cr_revisions.revision_id ) , group_distinct_member_map
where parties.party_id = group_distinct_member_map.member_id
and group_distinct_member_map.group_id = '-2'
-$search_clause
[template::list::page_where_clause -and -name "contacts" -key "party_id"]
[template::list::orderby_clause -orderby -name "contacts"]
Index: openacs-4/packages/contacts/www/my-searches.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/Attic/my-searches.adp,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/contacts/www/my-searches.adp 18 May 2005 16:45:50 -0000 1.1
+++ openacs-4/packages/contacts/www/my-searches.adp 10 Jun 2005 09:23:27 -0000 1.2
@@ -4,6 +4,16 @@
+
Index: openacs-4/packages/contacts/www/my-searches.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/Attic/my-searches.tcl,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/contacts/www/my-searches.tcl 7 Jun 2005 07:45:40 -0000 1.2
+++ openacs-4/packages/contacts/www/my-searches.tcl 10 Jun 2005 09:23:27 -0000 1.3
@@ -17,9 +17,7 @@
-multirow "searches" \
-row_pretty_plural "[_ contacts.searches]" \
-selected_format "normal" \
- -key party_id \
- -actions [list \
- "[_ contacts.Add_Search]" "search" "[_ contacts.Add_Search]"] \
+ -key search_id \
-elements {
object_type {
label {Type}
@@ -34,6 +32,18 @@
label {Query}
display_col query;noquote
}
+ results {
+ label {Results}
+ display_col results
+ link_url_eval $search_url
+ }
+ action {
+ label ""
+ display_template {
+ #contacts.Search#
+ #contacts.Make_Public#
+ }
+ }
} -filters {
} -orderby {
} -formats {
@@ -50,7 +60,8 @@
set owner_id [ad_conn user_id]
-db_multirow -extend {query} -unclobber searches get_searches {
+set search_ids [list]
+db_multirow -extend {query search_url make_public_url results} -unclobber searches get_searches {
( select search_id, title, upper(title) as order_title, all_or_any, object_type
from contact_searches
where owner_id = :owner_id
@@ -65,6 +76,10 @@
)
order by order_title
} {
+ lappend search_ids $search_id
+ set search_url [export_vars -base ./ -url {{query_id $search_id}}]
+ set make_public_url [export_vars -base search-public-toggle -url {search_id}]
+
db_foreach selectqueries {
select type as query_type, var_list as query_var_list from contact_search_conditions where search_id = :search_id
} {
@@ -73,5 +88,12 @@
}
append query "[contact::search::translate -type $query_type -var_list $query_var_list -to pretty -party_id "party_id" -revision_id "cr.revisions.revision_id"]"
}
+
}
+# Since contact::search::results_count can if not cached required two db queries
+# when this is included in the multirow code block above it can hang due to a lack
+# of db pools. So it has to be done here.
+template::multirow foreach searches {
+ set results [contact::search::results_count -search_id $search_id]
+}
Index: openacs-4/packages/contacts/www/search.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/search.adp,v
diff -u -r1.3 -r1.4
--- openacs-4/packages/contacts/www/search.adp 28 May 2005 15:44:06 -0000 1.3
+++ openacs-4/packages/contacts/www/search.adp 10 Jun 2005 09:23:27 -0000 1.4
@@ -5,10 +5,20 @@
+
-#contacts.My_Searches#
+
#contacts.lt_Debugging_Code_-_Only#
Index: openacs-4/packages/contacts/www/search.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/search.tcl,v
diff -u -r1.4 -r1.5
--- openacs-4/packages/contacts/www/search.tcl 7 Jun 2005 19:19:12 -0000 1.4
+++ openacs-4/packages/contacts/www/search.tcl 10 Jun 2005 09:23:27 -0000 1.5
@@ -23,8 +23,14 @@
{title ""}
{owner_id ""}
} -validate {
+ valid_object_type -requires {object_type} {
+ if { [lsearch [list party person organization] $object_type] < 0 } {
+ ad_complain "[_ contacts.You_have_specified_an_invalid_object_type]"
+ }
+ }
}
+
set page_title "[_ contacts.Advanced_Search]"
set context [list $page_title]
set sw_admin_p [acs_user::site_wide_admin_p]
@@ -57,17 +63,12 @@
} else {
set action "next"
}
-switch $object_type {
- party { set object_type_pretty "[_ contacts.lt_People_or_Organizatio]" }
- person { set object_type_pretty "[_ contacts.People]" }
- organization { set object_type_pretty "[_ contacts.Organizations]" }
- default {
- if { [exists_and_not_null object_type] } {
- ad_return_error "[_ contacts.Invalid_Object_Type]" "[_ contacts.lt_You_have_specified_an]"
- }
- }
-}
+
+set object_type_pretty_name(party) [_ contacts.People_or_Organizations]
+set object_type_pretty_name(person) [_ contacts.People]
+set object_type_pretty_name(organization) [_ contacts.Organizations]
+
if { ![exists_and_not_null owner_id] } {
set owner_id [ad_conn user_id]
}
@@ -79,18 +80,19 @@
{owner_id:integer(hidden)}
}
if { [exists_and_not_null object_type] } {
+ set object_type_pretty $object_type_pretty_name($object_type)
append form_elements {
{object_type:text(hidden) {value $object_type}}
{object_type_pretty:text(inform) {label {Search for}} {value "$object_type_pretty "} {after_html "[_ contacts.which_match]"}}
{all_or_any:text(select),optional {label ""} {options {{All all} {Any any}}} {after_html "[_ contacts.lt_of_the_following_cond] "}}
}
} else {
-# {{People or Organizations} party}
+ set object_type_options [list]
+ foreach object_type_temp [list party person organization] {
+ lappend object_type_options [list $object_type_pretty_name($object_type_temp) $object_type_temp]
+ }
append form_elements {
- {object_type:text(select) {label {Search for}} {options {
- {{People} person}
- {{Organizations} organization}
- }} {html {onClick "javascript:acs_FormRefresh('advanced_search')"}}}
+ {object_type:text(select) {label {Search for}} {options $object_type_options} {html {onClick "javascript:acs_FormRefresh('advanced_search')"}}}
}
}
@@ -118,7 +120,7 @@
from parties, cr_items, cr_revisions
where party_id = cr_items.item_id
and cr_items.latest_revision = cr_revisions.revision_id
-[contact::search::where_clauses -and -search_id $search_id -party_id "party_id" -revision_id "cr.revisions.revision_id"]
+[contact::search::where_clause -and -search_id $search_id -party_id "party_id" -revision_id "cr.revisions.revision_id"]
@@ -417,12 +419,15 @@
}
if { $search_exists_p } {
+ set results_count [contact::search::results_count -search_id $search_id]
+
append form_elements {
{title:text(text),optional {label " [_ contacts.save_this_search_]"} {html {size 40 maxlength 255}}}
{save:text(submit) {label "[_ contacts.Save]"} {value "save"}}
{search:text(submit) {label "[_ contacts.Search]"} {value "search"}}
{clear:text(submit) {label "[_ contacts.Clear]"} {value "clear"}}
{delete:text(submit) {label "[_ contacts.Delete]"} {value "delete"}}
+ {results_count_widget:text(inform) {label " [_ contacts.Results] "} {value {$results_count }}}
}
}
ad_form -name "advanced_search" -method "GET" -form $form_elements \
Index: openacs-4/packages/contacts/www/settings.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/settings.adp,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/contacts/www/settings.adp 28 May 2005 15:44:06 -0000 1.2
+++ openacs-4/packages/contacts/www/settings.adp 10 Jun 2005 09:23:27 -0000 1.3
@@ -1,6 +1,19 @@
@title@
@context@
+
+
+
+
#contacts.Add_Signature#