chak
committed
on 24 Jul 02
postgres stuff
openacs-4/.../acs-api-browser/www/proc-search.tcl (+26 -4)
2 2
3 3 ad_page_contract {
4 4     Searches for procedures with containing query_string
5 5     if lucky redirects to best match
6 6     Weight the different hits with the propper weights
7 7
8 8     Shows a list of returned procs with links to proc-view
9 9
10 10     Note: api documentation information taken from nsv array
11 11
12 12     @author Todd Nightingale (tnight@arsdigita.com)
13 13     @creation-date Jul 14, 2000
14 14     @cvs-id $Id$
15 15 } {
16 16     {name_weight:optional 0}
17 17     {doc_weight:optional 0}
18 18     {param_weight:optional 0}
19 19     {source_weight:optional 0}
20 20     {search_type:optional 0}
21 21     {show_deprecated_p 0}
  22     {show_private_p 0}
22 23     query_string
23 24 } -properties {
24 25     title:onevalue
25 26     context:onevalue
26 27     name_weight:onevalue
27 28     doc_weight:onevalue
28 29     param_weight:onevalue
29 30     source_weight:onevalue
30 31     query_string:onevalue
31 32     results:multirow
32 33 }
33 34
34 35 ##########################################################
35 36 ##  Begin Page
36 37
37 38 set quick_view [string equal $search_type "Only best match"]
38 39
39 40 #########################
40 41 ## Optimizes quick search
41 42 if {$quick_view && [nsv_exists api_proc_doc $query_string]} {
42 43     ad_returnredirect [api_proc_url $query_string]
43 44     ad_script_abort
44 45 }
45 46
46 47 ###########################
47 48 # No weighting use default:
48 49 if { ($name_weight == 0) && ($doc_weight == 0) && ($param_weight == 0) && ($source_weight ==0) } {
49 50     set name_weight 1
50 51 }
51 52
52 53 # Exact name search
53 54 if { [string equal $name_weight "exact"] } {
54 55     set name_weight 5
55 56     set exact_match_p 1
56 57 } else {
57 58     set exact_match_p 0
58 59 }
59 60
60 61 set counter 0
61 62 set matches [list]
62 63 set deprecated_matches [list]
  64 set private_matches [list]
63 65
64 66 # place a [list proc_name score positionals] into matches for every proc
65 67 foreach proc [nsv_array names api_proc_doc] {
66 68
67 69     set score 0
68 70     array set doc_elements [nsv_get api_proc_doc $proc]
69 71
70 72     ###############
71 73     ## Name Search:
72 74     ###############
73 75     if {$name_weight} {
74 76         # JCD: this was a little perverse since exact matches were
75 77         # actually worth less than matches in the name (if there were
76 78         # 2 or more, which happens with namespaces) so I doubled the
77 79         # value of an exact match.
78 80
79 81         ##Exact match:
80 82         if {[string tolower $query_string] == [string tolower $proc]} {
81 83             incr score [expr $name_weight * 2]
82 84         } elseif { ! $exact_match_p } {
 
113 115     #################
114 116     ## Source Search:
115 117     #################
116 118     if {$source_weight} {
117 119         if {![catch {set source [info body $proc]}]} {
118 120             incr score [expr $source_weight * [ad_keywords_score $query_string $source]]
119 121         }   
120 122     }
121 123
122 124     #####
123 125     ## Place Needed info in matches
124 126     if {$score} {
125 127         if {$doc_elements(varargs_p)} {
126 128             set args "$doc_elements(positionals) \[ args... \]"
127 129         } else {
128 130             set args $doc_elements(positionals)
129 131         }  
130 132         if { $doc_elements(deprecated_p) } {
131 133             lappend deprecated_matches [list $proc $score $args]
132 134         } else {
  135             if { $doc_elements(public_p) } {
133 136                 lappend matches [list $proc $score $args]
  137             } else {
  138                 lappend private_matches [list $proc $score $args]
134 139             }
135 140         }
136 141     }
  142 }
137 143
138 144 set matches [lsort -command ad_sort_by_score_proc $matches]
139 145
140 146 if {$quick_view && ![empty_string_p $matches] || [llength $matches] == 1 } {
141 147     ad_returnredirect [api_proc_url [lindex [lindex $matches 0] 0]]
142 148     ad_script_abort
143 149 }
144 150
145 151 set title "Procedure Search for: \"$query_string\""
146 152 set context [list "Search: $query_string"]
147 153
148 154 multirow create results score proc args url
149 155
150 156 foreach output $matches {
151 157     incr counter
152 158     set proc  [lindex $output 0]   
153 159     set score [lindex $output 1]
154 160     set args  [lindex $output 2]
155 161     set url   [api_proc_url $proc]
156 162     multirow append results $score $proc $args $url
157 163 }
158 164
159 165 multirow create deprecated_results score proc args url
160 166
161 167 foreach output $deprecated_matches {
162 168     incr counter
163 169     set proc  [lindex $output 0]   
164 170     set score [lindex $output 1]
165 171     set args  [lindex $output 2]
166 172     set url   [api_proc_url $proc]
167 173     multirow append deprecated_results $score $proc $args $url
168 174 }
169 175
170   set show_deprecated_url [export_vars -base [ad_conn url] -override { { show_deprecated_p 1 } } { name_weight doc_weight param_weight source_weight search_type query_string }]
  176 set show_deprecated_url [export_vars -base [ad_conn url] -override { { show_deprecated_p 1 } } { name_weight doc_weight param_weight source_weight search_type query_string show_private_p }]
171 177
172   set hide_deprecated_url [export_vars -base [ad_conn url] -override { { show_deprecated_p 0 } } { name_weight doc_weight param_weight source_weight search_type query_string }]
  178 set hide_deprecated_url [export_vars -base [ad_conn url] -override { { show_deprecated_p 0 } } { name_weight doc_weight param_weight source_weight search_type query_string show_private_p }]
  179
  180
  181 multirow create private_results score proc args url
  182
  183 foreach output $private_matches {
  184     incr counter
  185     set proc  [lindex $output 0]   
  186     set score [lindex $output 1]
  187     set args  [lindex $output 2]
  188     set url   [api_proc_url $proc]
  189     multirow append private_results $score $proc $args $url
  190 }
  191
  192 set show_private_url [export_vars -base [ad_conn url] -override { { show_private_p 1 } } { name_weight doc_weight param_weight source_weight search_type query_string show_deprecated_p }]
  193
  194 set hide_private_url [export_vars -base [ad_conn url] -override { { show_private_p 0 } } { name_weight doc_weight param_weight source_weight search_type query_string show_deprecated_p }]