Forum OpenACS Q&A: simple improvement to rank_for_search

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';
Collapse
Posted by Don Baccus on
Yeah, this is a nice improvement...Roberto, wanna test it and verify
it works and include it with 3.2.5?
Collapse
Posted by Dave Bauer on
This is totally off-topic, but of concern to bboard users. Opera 5.02 for Windows 98, and probably other platforms, does not render preformatted text if there is a blockquote INSIDE of it. The blockquote tag first works fine and has the same result.