From 88c098c83fbe306e9c08f107229a80506dff0036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Nicolaysen=20S=C3=B8rnes?= Date: Wed, 18 Jun 2008 00:14:27 +0200 Subject: [PATCH] Search for partial app names --- include/application_queue.php | 5 ++++- include/util.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/application_queue.php b/include/application_queue.php index 0c7f2f3..d20dca8 100644 --- a/include/application_queue.php +++ b/include/application_queue.php @@ -276,8 +276,11 @@ class application_queue function displayDuplicates() { - echo "Like matches\n"; + echo "Like matches
\n"; $this->displayDuplicateTable(searchForApplication($this->oApp->sName)); + echo "
\n"; + echo "Partial matches
\n"; + $this->displayDuplicateTable(searchForApplicationPartial($this->oApp->sName)); } function displayDuplicateTable($hResult) diff --git a/include/util.php b/include/util.php index 57576ae..4009d1c 100644 --- a/include/util.php +++ b/include/util.php @@ -412,6 +412,34 @@ function cleanupSearchWords($search_words) return $search_words; } +/* A common error for users is to submit a new app entry for a new app version, + such as C&C Red Alert 2 Yuri's Revenge when we already have C&C Red Alert 2. + Search for the first word in the search query */ +function searchForApplicationPartial($sSearchWords) +{ + $sSearchWords = cleanupSearchWords($sSearchWords); + $aWords = explode(' ', $sSearchWords); + $sSearchString = ''; + + for($i = 0; $i < sizeof($aWords); $i++) + { + if($i) + $sSearchString .= '%'; + $sSearchString .= $aWords[$i]; + if(strlen($aWords[$i]) > 4) + { + if($i < (sizeof($aWords) - 1)) + $sSearchString .= ' '; + break; + } + } + + $hResult = query_parameters("SELECT * FROM appFamily WHERE state = 'accepted' AND + appName LIKE '?%'", $sSearchString); + + return $hResult; +} + /* search the database and return a hResult from the query_appdb() */ function searchForApplication($search_words) { @@ -524,6 +552,10 @@ function perform_search_and_output_results($search_words) echo "
Like matches
"; $hResult = searchForApplication($search_words); outputSearchTableForhResult($search_words, $hResult); + + echo "
Partial matches
"; + $hResult = searchForApplicationPartial($search_words); + outputSearchTableForhResult($search_words, $hResult); } function display_page_range($iCurrentPage=1, $iPageRange=1, $iTotalPages=1, $sLinkurl=NULL)