This will allow the search string to contain quoted strings that are
treated as a single search term. (Since it uses tcl's eval, braces
work as well as quotes but you don't need to confuse your users by
telling them that. :) We're getting to the point on the openacs
boards that IMO this would help a lot in narrowing down search
results a bit.
drop function rank_for_search(varchar, varchar);
-- escape out all ,$,[,],;,
with backslash
-- then use eval list instead of split to preserve quoted terms
create function rank_for_search(varchar, varchar) returns integer as '
set candidate_string [string tolower $2]
regsub -all {[$[];
]} $1 {&} search_string
set search_words [eval list $search_string]
set max_possible_score [expr [llength $search_words] * 10.0]
set score 0
foreach search_word $search_words {
if { [string first $search_word $candidate_string] != -1 } {
set score [expr $score+10]
}
}
set score [expr int(($score/$max_possible_score) * 100.0)]
return $score
' language 'pltcl';