//IF WORD SUGGESTIONS HAVE BEEN REQUESTED DISPLAY ALTERNATIVES
 if (isset($_POST['reWrite']) && $_POST['reWrite'] != '') {
     //ONLY WANT THE FIRST WORD FOR OUR LOOKUP
     $firstQueryWord = getFirstWord($cleanedQuery);
     //LOOKUP THE WORD
     getSynonyms($firstQueryWord, $synonyms);
     //INCLUDE PHP FUNCTION WHICH CREATES A FORM BASED ON THE SYNONYM ARRAY
     include 'functions/synonymForm.php';
     //RUN FUNCTION TO CREATE FORM OF SYNONYMS
     listSynonyms($synonyms);
 } else {
     //IF REWRITE IS NOT REQUESTED, PROCESS QUERY:
     //CALL FUNCTIONS TO GET RESULTS FROM SEARCH ENGINES
     getBlekkoResults($blekkoResultsOrig);
     //get Blekko
     getGoogleResults($googleResultsOrig);
     //get Google
     getBingResults($bingResultsOrig);
     //get Bing
     //**************************************************************************
     //**************************************************************************
     //CALL FUNCTIONS TO REMOVE DUPLICATE URLS AND RE-SCORE DOCUMENTS
     removeDuplicates($blekkoResultsOrig, $blekkoResults);
     removeDuplicates($googleResultsOrig, $googleResults);
     removeDuplicates($bingResultsOrig, $bingResults);
     //**************************************************************************
     //**************************************************************************
     //(IF NON-AGGREGATED CHOSEN THEN DISPLAY RESULTS:)
     if ($_POST['result_type'] === 'Non-Aggregated') {
         echo "<div class=\"row-fluid\">" . "<div class=\"span4\">";
         echo "<h2 class=\"text-center\">Bing</h2>";
 $bingResultsOrig = array();
 //original results (may contain duplicates)
 $blekkoResults = array();
 //results with duplicates removed
 $googleResults = array();
 //results with duplicates removed
 $bingResults = array();
 //results with duplicates removed
 $aggregatedResults = array();
 //array to store aggregated results in
 $weights = array();
 //array to store weights applied
 //CALL FUNCTIONS TO GET RESULTS FROM SEARCH ENGINES
 getBlekkoResults($blekkoResultsOrig, $query);
 //get Blekko
 getGoogleResults($googleResultsOrig, $query);
 //get Google
 getBingResults($bingResultsOrig, $query);
 //get Bing
 //CALL FUNCTIONS TO REMOVE DUPLICATE URLS AND RE-SCORE DOCUMENTS
 removeDuplicates($blekkoResultsOrig, $blekkoResults);
 removeDuplicates($googleResultsOrig, $googleResults);
 removeDuplicates($bingResultsOrig, $bingResults);
 //*********************************************
 //Write results to files
 writeToFile($blekkoResults, "metrics/blekkoResults", $query);
 writeToFile($bingResults, "metrics/bingResults", $query);
 writeToFile($googleResults, "metrics/googleResults", $query);
 //AGGREGATE the Results using Borda-Fuse
 //NOTE THAT THE ORDER THE ARRAYS ARE SENT IN TO BE AGGREGATED MATTERS
 //FOR ANY RESULTS THAT HAVE THE SAME COMBINED SCORE/RANK