Page 1 of 1

score on fulltext search converted to percantage

Posted: Fri Oct 08, 2004 3:03 am
by mudkicker
hey people,

Code: Select all

<?php
	public function searchQuery($query) {
		$sql = mysql_query("SELECT filename, fileurl, MATCH (keywords) AGAINST ('".addslashes($query)."') AS score FROM mudcrawl WHERE MATCH (keywords, filename, fileurl) AGAINST ('".addslashes($query)."' IN BOOLEAN MODE) ORDER BY score DESC");
		if($sql) {
			$this->resultcount = mysql_num_rows($sql);
			if($this->resultcount > 0) {
				echo $this->resultcount." results found:<br>";
				while ($row = @mysql_fetch_assoc($sql)) {
						echo "<a href="".$row["fileurl"]."">".$row["filename"]."</a> - Score: ".$row["score"]."<br>";
				}
			}
			else {
				echo "No results found, click <a href="index.php">here</> to search again.";
			}
		}
		else {
			die(mysql_error());
		}
	}
?>
this is my code snipper for searching. Here i want to show the score by percentaqge but i couldn't find a way to do this? how can I do it? it shows for example 3.43957395759 ;) thanks for your help.

Posted: Fri Oct 08, 2004 3:16 am
by twigletmac

Posted: Fri Oct 08, 2004 3:19 am
by mudkicker
oops, sorry twiglet i forgot to search! :(

Posted: Fri Oct 08, 2004 4:08 am
by mudkicker
well i think i've done it, but some enhancements would be great. In my sql above how can I select only the results which has a relevance greater than zero?

Posted: Fri Oct 08, 2004 4:30 am
by feyd
where x > 0

:P

Posted: Fri Oct 08, 2004 4:35 am
by mudkicker
well i tested it and it gives sql syntax error, tells that there's no column named score..

Posted: Fri Oct 08, 2004 4:38 am
by feyd
uhm.. x = 'MATCH (keywords, filename, fileurl) AGAINST ('".addslashes($query)."' IN BOOLEAN MODE)'

:D

untested though.. I would imagine you'll need to round/truncate the result in some fashion first ;)

Posted: Fri Oct 08, 2004 4:42 am
by mudkicker
well it doesn't work either. :(
it's quite annoying that some results are printed out and with score : 0% ;)

Posted: Fri Oct 08, 2004 6:09 am
by feyd
most of this issue, I believe was solved via IM :(

anyways, hopefully mudkicker will fix the one part I told him how to fix and he'll post if he has further problems, or has indeed fixed it.

Posted: Fri Oct 08, 2004 6:13 am
by mudkicker
yeah sure :)