score on fulltext search converted to percantage

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

score on fulltext search converted to percantage

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

oops, sorry twiglet i forgot to search! :(
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

where x > 0

:P
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

well i tested it and it gives sql syntax error, tells that there's no column named score..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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 ;)
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

well it doesn't work either. :(
it's quite annoying that some results are printed out and with score : 0% ;)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

yeah sure :)
Post Reply