Index: search.php
===================================================================
RCS file: /opt/cvs-commit/appdb/search.php,v
retrieving revision 1.14
diff -u -r1.14 search.php
--- search.php 14 May 2005 00:42:25 -0000 1.14
+++ search.php 3 Jun 2005 04:33:24 -0000
@@ -13,7 +13,14 @@
apidb_header("Search Results");
+echo "
Like matches";
$hResult = searchForApplication($_REQUEST['q']);
outputSearchTableForhResult($_REQUEST['q'], $hResult);
+
+$minMatchingPercent = 60;
+echo "Fuzzy matches - minimum ".$minMatchingPercent."% match";
+$hResult = searchForApplicationFuzzy($_REQUEST['q'], $minMatchingPercent);
+outputSearchTableForhResult($_REQUEST['q'], $hResult);
+
apidb_footer();
?>
Index: include/util.php
===================================================================
RCS file: /opt/cvs-commit/appdb/include/util.php,v
retrieving revision 1.26
diff -u -r1.26 util.php
--- include/util.php 20 May 2005 02:45:55 -0000 1.26
+++ include/util.php 3 Jun 2005 04:33:24 -0000
@@ -315,9 +315,64 @@
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)
{
- if(mysql_num_rows($hResult) == 0)
+ if(($hResult == null) || (mysql_num_rows($hResult) == 0))
{
// do something
echo html_frame_start("","98%");