Fudging Google Results


Although Google is an excellent tool for searching the Net at large, there may be instances where you disagree with Google's ranking of certain items within your own domain, or even across the Net at large. By using the previous caching example, fudging results couldn't be easier. Just edit the database!

For example, doing a search (restricted to my domain) for "MetaMachine" (a previous employer) yields the following results:

 1) mysql_connect() [function.mysql-connect]: Can't connect to MySQL server... 2) I am a big fan of ?distributed? downloads (as I should be, being a past... 3) or use: forgot your password? or send a check or money order for $20 US... 

The first result is obviously a big embarrassment — it points to a broken page. You can definitely do better than that for a past employer. You could just fix the page, but it would probably be easier just to fudge the results a little bit.

First, pick the target page. In this case, I have chosen the homepage of one of MetaMachine's software programs, eDonkey. Finally, update the record in the database to contain the fudged information:

 INSERT INTO `06_google_cache` VALUES ('95b63f2c42287a18a4552f061acac3ed', 0, 'MetaMachine', 0, 'MetaMachine are the authors of the eDonkey file sharing program, fast error-free downloads every time!', 'eDonkey', 'http://www.edonkey.com/'); 

Next update the meta table, because it contains the timestamp:

 UPDATE 06_google_cache_meta SET time = '20090118215927' WHERE query = 'metamachine' 

Now that result set will not expire until 2009. I think it is safe to assume that this code will be long gone by then.

Generally, when I want to fudge results, it is to insert a particularly relevant result that Google has either missed or ranked more poorly; however, the opposite is also possible. If there is a result that you do not want to appear, but do not have a suggested replacement (other than the next relevant result), simply delete the row and increment the other results. You may either leave only nine results on that page, or duplicate the last result from the next page of results.

Imitating Google Adwords

Though the previous methods of fudging examples work, they either necessitate freezing a result set or taking a more complicated approach. There is a simple replacement: copying the design of Google Adwords. While Google accepts paid advertisements, it does not allow these advertisements to produce search results (unlike several competing search engines). Paid advertisements are placed on the same page as the results, but are clearly identified, as shown in Figure 6-4.

image from book
Figure 6-4

Note 

When trying to determine how to best handle a search-related situation, just ask yourself WWGD? (What Would Google Do?)

Advertiser (or "sponsor") links are highlighted in Figure 6-4.

Although fudged results likely don't constitute sponsors, a change in terminology to suggested will suit the situation perfectly. Creating a suggested word table and using it when presenting results gives the advantages of fudged results, because the preferred results are clearly presented without locking result sets.

 function getSuggested($query) {   $suggestions = array();   $query = explode("", $query); 

Explode is a terrific function. It will turn the query string supplied by the user into an array, with each element in the array consisting of one of the words from the query string. Each word can then be iterated through quite easily. If you want (or need) to include phrases rather than just individual words, the code will need to get a bit more complex. Rather than iterate through the query words, you will need to iterate through the possible phrases, and see if the phrases exist within the query with something like strripos().

   foreach($query AS $word)   {     $word = mysql_real_escape_string($word, $linkID); 

It is very easy to forget to escape short strings like this, especially when running a lookup query. Train yourself to always escape before a query, always.

     $query = "SELECT * FROM 06_google_suggest WHERE `word` = '$word'";     $suggest = getAssoc($query, 2); 

The second parameter sent to getAssoc specifies that you want an array of results in return, so should there be only a single result, it can be iterated through once, rather than accidentally iterating through the result itself. The full code for the function is available in Appendix A.

     if (count($suggest) > 0)     {       foreach ($suggest as $suggestion)       {         $suggestions[] = $suggestion;       }     }   }   return $suggestions; } 

Finally, if there are any suggestions, they are added to the suggestions array, and the results (if any) are returned to the calling function. With this information in hand, the calling function can present the information independently of the real search results, in whatever manner best suits the page template overall.

You can see the suggested and regular results displayed clearly in Figure 6-5.

image from book
Figure 6-5




Professional Web APIs with PHP. eBay, Google, PayPal, Amazon, FedEx, Plus Web Feeds
Professional Web APIs with PHP. eBay, Google, PayPal, Amazon, FedEx, Plus Web Feeds
ISBN: 764589547
EAN: N/A
Year: 2006
Pages: 130

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net