15 November 2010

When Google Fails to Search

::
It all started when I decided to write a new blog. As I had done it many times before, setup, widgets and plug-ins of my choice and a suitable template swiftly took their places. Additional code was minimal for Blogger now does many things natively.



One of my all-time favorite widgets is related posts service. Sadly, maintainer of brps did not accept any more users. Instead, he was directing newcomers to another but similar plug-in which uses Google Web Search API. Since I was already using it in an another blog, I quickly grabbed it.

For the first couple of posts, I ignored the "no related posts found" warnings as it was my understanding that it used Google's search index instead of json/feed combination and it was normal for the posts to appear in search engines with a little delay. Some 20 posts later, when the plug-in still failed to load any related posts, I decided to take a closer look. The code was fine, it was and still is working in an older blog. The posts were indexed by Googlebot, so no problem there, either. Just as I was about to shoot a message to developer, I discovered Google was deprecating its API and there was nothing developer could do.

Leaving aside the mystery of why it functions in one and not the other, I began a search for alternatives. Among a plethora of posts advocating a bunch of similar applications having a flaw (subjective view) one way or another, I have finally found one and implemented it successfully. In case you are not happy with yours or looking for a lean and mean related posts widget like the one here (they are not the same, brps is more sophisticated), here is the way to do it:

1. Go to design, edit html and click the box to expand your widget templates.
2. Insert the following code before the closing head tag

<!--Related Posts Scripts and Styles Start-->
<!--Remove--><b:if cond='data:blog.pageType == &quot;item&quot;'>
<script type='text/javascript'>
var relatedpoststitle=&quot;&quot;;
</script>
<script src='http://blogergadgets.googlecode.com/files/related-posts-for-blogger.js' type='text/javascript'/>
<!--Remove--></b:if>
<!--Related Posts Scripts and Styles End-->
</head> <--- the closing head tag

3. Find "post-footer-line-3" and insert following after the tag

<div class='post-footer-line post-footer-line-3'> <-- The tag you're looking for
<!--code starts here-->
<b:if cond='data:blog.pageType == &quot;item&quot;'>

<h4>Related Posts:</h4>

<div id='related-posts'>
<b:loop values='data:post.labels' var='label'>
<b:if cond='data:label.isLast != &quot;true&quot;'>
</b:if>
<script expr:src='&quot;/feeds/posts/default/-/&quot; + data:label.name + &quot;?alt=json-in-script&amp;callback=related_results_labels&amp;max-results=6&quot;' type='text/javascript'/>
</b:loop>
<script type='text/javascript'>

var maxresults=5;
removeRelatedDuplicates(); printRelatedLabels(&quot;&quot;);
</script>
</div>
</b:if>
<!--code ends here-->

4. Customize the title between h4 tags (currently Related Posts:) and "var maxresults" (currently set to 5 posts) to your liking.

I am looking for the true author of the script to give due credit. If you happen to know, just drop a comment here.

After solving this, I could not help but think Google's change of API was an ominous sign. So, I decided to run a query in the search box similar to the one here at the top of sidebar. Boy, was I right! The search did not return any results. The presumably native search did (and still does) not work; it finds nothing.

Here too, we have a mysterious puzzle. The same search happens to function perfectly inside the dashboard but miserably fails if you or your readers use it on your blog. Why does it work in blog 1 but not in blog 2? Neither I nor Google had apparently any clue as this has been going on for more than a year, July 2009 to be exact. Interestingly, they are problems with the so called custom search engine, too. Google can not search. Who would have thought?


2 comments:

  1. I have found a fix for the flaw I mentioned but not give any details. If you are using the version which annoyingly lists current post as related (not brps or the version mentioned here) you can take a look. I did not try it myself, though.

    ReplyDelete