משהו שרשמתי: (אין פה סידור של רלוונטיות)
PHP קוד:
<?php
$connect = mysql_connect("localhost","username","pass");
$db_select = mysql_select_db("db", $connect);
$query = "how to amazing hello man are you"; // מילות חיפוש
$col = "title"; // העמודה
$density = 2; // אחד או שתיים - צפיפות המילים
//---------------------------------------
$where = array();
$exploded = explode(" ", $query); // preg_split("/\s{1}/", $query);
$explode = array();
if( $density == 2 )
{
for( $x = 0; $x < count($exploded); ++$x )
{
if( $x % 2 )
{
continue;
}
$explode[$x] = trim($exploded[$x] . " " . $exploded[$x + 1]);
}
}
else
{
$explode = explode(" ", $query);
}
foreach( $explode as $q )
{
if( empty($q) )
continue;
$where[] = $col. " LIKE '%" .$q. "%'";
}
$whereSyntax = implode(" OR ", $where);
if( !empty($whereSyntax) )
{
$whereSyntax = " WHERE " .$whereSyntax;
}
if( strtoupper(trim($whereSyntax)) == "WHERE" )
{
$whereSyntax = null;
}
//---------------------------------------
$result = mysql_query("SELECT " .$col. " FROM tutorials" . $whereSyntax);
while( $row = mysql_fetch_array($result, MYSQL_ASSOC) )
{
echo $row[$col] . "<br />\n";
}
?>
אין פה סידור של רלוונטיות, יש לך אפשרות לשחק עם הצפיפות (המשתנה $density ) יכול להיות על אחד או שתיים, אם זה שתיים זה מחלק את המשפט מכל שתי מילים, אם זה על אחד זה מחלק אותו על כל מילה.
אבל כמו שאמרו לך פה, MATCH AGAINST זה הכי נוח לדעתי.