From a413175e40d59d74bec4d0f1e047e6d21abf1098 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Tue, 14 Jun 2005 19:38:36 +0000 Subject: [PATCH] Improve search results by seeing if any of the search words match a vendor name or a vendor url. If so we should return all of the vendors applications in our search results. --- include/util.php | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/include/util.php b/include/util.php index 6eabed0..4d4fdc1 100644 --- a/include/util.php +++ b/include/util.php @@ -304,13 +304,40 @@ function outputTopXRowAppsFromRating($rating, $num_apps) /* search the database and return a hResult from the query_appdb() */ function searchForApplication($search_words) { + /* split search words up so we can see if any of them match a vendor name or vendor url */ + $split_words = split(" ", $search_words); + $vendorIdArray = array(); + + /* find all of the vendors whos names or urls match words in our */ + /* search parameters */ + foreach ($split_words as $key=>$value) + { + $sQuery = "SELECT vendorId from vendor where vendorName LIKE '%".addslashes($value)."%' + OR vendorURL LIKE '%".addslashes($value)."%'"; + $hResult = query_appdb($sQuery); + while($oRow = mysql_fetch_object($hResult)) + { + array_push($vendorIdArray, $oRow->vendorId); + } + } + + /* base query */ $sQuery = "SELECT * - FROM appFamily + FROM appFamily, vendor WHERE appName != 'NONAME' + AND appFamily.vendorId = vendor.vendorId AND queued = 'false' AND (appName LIKE '%".addslashes($search_words)."%' - OR keywords LIKE '%".addslashes($search_words)."%') - ORDER BY appName"; + OR keywords LIKE '%".addslashes($search_words)."%'"; + + /* append to the query any vendors that we matched with */ + foreach($vendorIdArray as $key=>$value) + { + $sQuery.=" OR appFamily.vendorId=$value"; + } + + $sQuery.=" ) ORDER BY appName"; + $hResult = query_appdb($sQuery); return $hResult; }