Add fuzzy matching using php's similar_text. Default to using 60% minimum

match. Show fuzzy matches below the 'like matches' table so users can tell
the results apart. Exclude like matches from fuzzy match results to avoid
duplicate results.
This commit is contained in:
Chris Morgan
2005-06-03 04:37:40 +00:00
committed by WineHQ
parent a80a97db33
commit 717ebf0f5e
2 changed files with 63 additions and 1 deletions

View File

@@ -315,9 +315,64 @@ function searchForApplication($search_words)
return $hResult; return $hResult;
} }
function searchForApplicationFuzzy($search_words, $minMatchingPercent)
{
$foundAValue = false;
$excludeAppIdArray = array();
$appIdArray = array();
/* add on all of the like matches that we can find */
$hResult = searchForApplication($search_words);
while($oRow = mysql_fetch_object($hResult))
{
array_push($excludeAppIdArray, $oRow->appId);
}
/* add on all of the fuzzy matches we can find */
$sQuery = "SELECT appName, appId FROM appFamily WHERE queued = 'false'";
foreach ($excludeAppIdArray as $key=>$value)
{
$sQuery.=" AND appId != '$value'";
}
$sQuery.=";";
$hResult = query_appdb($sQuery);
while($oRow = mysql_fetch_object($hResult))
{
similar_text($oRow->appName, $search_words, $similarity_pst);
if(number_format($similarity_pst, 0) > $minMatchingPercent)
{
$foundAValue = true;
array_push($appIdArray, $oRow->appId);
}
}
if($foundAValue == false)
return null;
$sQuery = "SELECT * from appFamily WHERE ";
$firstEntry = true;
foreach ($appIdArray as $key=>$value)
{
if($firstEntry == true)
{
$sQuery.="appId='$value'";
$firstEntry = false;
} else
{
$sQuery.=" OR appId='$value'";
}
}
$sQuery.=" ORDER BY appName;";
$hResult = query_appdb($sQuery);
return $hResult;
}
function outputSearchTableForhResult($search_words, $hResult) function outputSearchTableForhResult($search_words, $hResult)
{ {
if(mysql_num_rows($hResult) == 0) if(($hResult == null) || (mysql_num_rows($hResult) == 0))
{ {
// do something // do something
echo html_frame_start("","98%"); echo html_frame_start("","98%");

View File

@@ -13,7 +13,14 @@ require(BASE."include/application.php");
apidb_header("Search Results"); apidb_header("Search Results");
echo "<center><b>Like matches</b></center>";
$hResult = searchForApplication($_REQUEST['q']); $hResult = searchForApplication($_REQUEST['q']);
outputSearchTableForhResult($_REQUEST['q'], $hResult); outputSearchTableForhResult($_REQUEST['q'], $hResult);
$minMatchingPercent = 60;
echo "<center><b>Fuzzy matches - minimum ".$minMatchingPercent."% match</b></center>";
$hResult = searchForApplicationFuzzy($_REQUEST['q'], $minMatchingPercent);
outputSearchTableForhResult($_REQUEST['q'], $hResult);
apidb_footer(); apidb_footer();
?> ?>