what about the percentage how much accurate the result returned??
I'm not sure what kind of keywords or text you're searching, but here's the algorithm i used a while back, for plain-text search:
given: $query $text
/* curve() maps values between 0 and 1 to.. a curve: 0% -> 0% 25% -> 43% 50% -> 75% 75% -> 93% 100% -> 100% */ function curve($x){ $x = 1 - $x; $x = $x * $x; return 1 - $x; }
/* given a number between 0 and +INFINITY, strength returns a value between 0 and 1 (0% and 100%) the higher $n is, the closer to 1 the result. 0 -> 0% 6 -> 85.7% 1 -> 50% 7 -> 87.5% 2 -> 66.6% 8 -> 88.8% 3 -> 75% 9 -> 90% 4 -> 80% 19 -> 95% 5 -> 83.3% 100 -> 99% */ function strength($x){ return ($x / ($x + 1)) }
$count = 0
$keywords = (split $query into array of whole words)
for (each word in $query) {
$n = (number of times $word found in $text);
// add the size of $word to $count, or more depending on $n
$count += (length of $word) * (1 + strength($n));
}
$score = ($count + $count) / (length of $query + length of $text );
$score = curve($score); // repeat a few times if needed, to get decent scores
and there you have it.
------------------------------------- mikon
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php