Jump to content

Related items


The Little Guy

Recommended Posts

I would like to search a database for users that are similar to the current user. I don't know If this can be done with MySQL, or PHP. So, for example, say I have the following user: billy123

 

Some similar users could be as follow:

billy

billy1

billy2010

bill

billybobjoe

 

What is a way this can be done, because I am stumped here.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/207041-related-items/
Share on other sites

Investigate the use of levenshtein()  & similar_text(). A combination of those two may get what you want.

 

I used this simple search to go through folders and give similar and possible matches... very rudimentary but works super fast and returned matches deemed good for what I was using it on as a search of documents in a folder library. 

<?php
//this function returns if one of the strings is actually with the other string
// returns yes if same or one string is found within the second.
function Weigh_Results($One, $Two)
{

if ( stristr( $One, $Two ) ) 
{
  		$ser_results = "yes";
} 
else 
{
  		$ser_results = "no";
}

return $ser_results;
}
?>

//percentage tests of two combined that give similiar phonotic and similiar spelling adjust this to your liking
//returns yes or no as to whether the it's close enough to be a return
<?php
function Meta_Lev($One , $Two)
{

$str1 = $One;
$str2 = $Two;
$meta_one=metaphone($str1);
$meta_two=metaphone($str2);	
$lev = levenshtein($meta_one, $meta_two);
//echo "metaphone code for ".$str1." is ". $meta_one;
//echo "<br />";
//echo "metaphone code for ".$str2." is ". $meta_two."<br>";
//echo "<br />";
//echo "levenshtein of the two metaphones is:".$lev.".<br>";
$length = strlen($str1);
$match = $lev / $length;
//echo "percentage of length is: ".$match.".<br>";

if($match < .2)
{
	$ret = "yes";
}
if($match >= .2)
{
	//echo "metaphone codes are not matching<br>";
	similar_text($str1,$str2,$percent);
	//echo "Percentage of similar texts are: ".$percent.".<br>";
	if($percent > 40)
	{
		$ret = "yes";
	}
	else
	{
		$ret = "no";
	}
}

return $ret;
}	
?>

Link to comment
https://forums.phpfreaks.com/topic/207041-related-items/#findComment-1082636
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.