I was having issues with the built-in search in CS2007. Basically it was loading a blank page (no HTML at all) instead of the search results page. I’m sure I could find some info about the issue in the forums, but decided I would take a few minutes to try to implement Google’s Custom Search instead. I spent more time futzing with the CS files than necessary to figure it out, but in the end the changes were pretty simple.
Step 1: First, sign up on Google to have a custom search engine. I’m not going to walk through this since it’s not that hard, and I’m sure you’re smart. After your site is setup, go to the Code link in the control panel. Expand the “Search box and search results code for your website” panel. I recommend using the watermark text box because it will most likely match your site better than the other options.
Step 2: Backup these two files: /Themes/Blogs/YOURTHEME/theme.master and /Themes/Blogs/YOURTHEME/search.aspx.
Step 3: Open /Themes/Blogs/YOURTHEME/theme.master and remove the section for <CSBlog:SearchForm … />. Replace that with code similar to the following, with variables changed based on what you get from Google:
<div id=”Search” align=”right”> <table cellpadding=”0″ cellspacing=”0″ border=”0″> <tr><td> <input name=”q” id=”q” type=”text” class=”searchBox”
Button=”SearchButton” onkeydown=”javascript:if((event.which
&& event.which == 13) || (event.keyCode && event.keyCode
== 13)) {GoogleSearch();return false;}else return true;” /> </td><td> <span class=”SearchButtonOuter”> <a id=”ctl00_ctl06_ctl00_SearchButton” class=”SearchButton”
href=”javascript:GoogleSearch2();”>Search</a> </span> </td></tr> </table> </div><script language=”JavaScript”>function GoogleSearch2(){window.location =
“http://www.tapmymind.com/blog/tap_my_mind/search.aspx” +“?q=” + document.getElementById(“q”).value +“&cx=014327199496625865409:3nxxz5mvxtw” +“&cof=FORID:10” +“&sa=search”;}function GoogleSearch() { window.setTimeout(“GoogleSearch2()”, 200);}</script><script type=”text/javascript”
src=”http://google.com/coop/cse/brand?form=aspnetForm”></script>
You may have to change some HTML for layout purposes. I am using the Paperclip theme and this worked for me. I basically copied the resulting HTML from a source view of the unmodified page, inserting stuff where I thought was appropriate.
Also, the setTimeout was to cause a delay before submitting the form with the Enter key (the whole bit about event.keyCode, etc.) due to some issues I found with IE’s autocomplete not, ummm, completing before the form was submitted. Also note that I am using the current search URL.
Step 4: Open /Themes/Blogs/YOURTHEME/theme.master and remove then contents of the <asp:Content … /> item — just the contents, leave the asp:Content element itself. In it’s place add code like this (again, based on what Google gives you):
<h2 class=”pageTitle”>Google Custom Search Results</h2>These results are coming directly from Google’s search engine.
Consequently, some items do not show up in the results right
away. If you are search for a post you expected to find, but
it is not listed, please try the same search on <a href=”http://blogsearch.google.com/blogsearch?as_q=<%
Response.Write(Server.UrlEncode(Request.QueryString[“q”]));
%>&bl_url=tapmymind.com”>Google’s Blog Search tool</a>.<br /><br /><!– Google Search Result Snippet Begins –><div id=”results_014327199496625865409:3nxxz5mvxtw”></div><script type=”text/javascript”> var googleSearchIframeName =
“results_014327199496625865409:3nxxz5mvxtw”; var googleSearchFormName = “aspnetForm”; var googleSearchFrameWidth = 500; var googleSearchFrameborder = 0; var googleSearchDomain = “google.com”; var googleSearchPath = “/cse”;</script><script type=”text/javascript”
src=”http://www.google.com/afsonline/show_afs_search.js”></script><!– Google Search Result Snippet Ends –>
Note that I specified the search form name as “aspnetForm” (here as well as in the previous step). This is the name/id the resulting HTML form has and correctly specifying this allows Google to properly add the watermark, as well as pre-populate the text box with the current search term automatically.
I also added a link to do the same search on Google’s Blog Search (GBS) tool. I noticed that a post I recently added was not showing in the results because it hadn’t been indexed yet (I assume), but it does show in GBS because of pings that CS2007 sends for me. So I coded the link to automatically search my site (you’ll want to change the value for bl_url) and the current search term.
Step 5: This step may or may not be important to you, but I also had to modify styles.css for the current theme so that the text box was wide enough to show the Google watermark. I don’t have that file handy at the moment, but I think I changed the width to 140 or 150px.
As far as I can remember, that’s all I did, and so far it works for me. I imagine many other people have already tried this and figured it out, but I didn’t bother searching for examples. I didn’t really test this heavily, so please let me know if you find bugs or have suggestions. I just have to remember this if I change themes or upgrade CS (hence this post).
Be sure to be aware of wrapping issues with the code I have posted here. Also, I strongly recommend you backup everything you are going to edit first. I’m not responsible for any damage you cause to your site. [:)]
If anyone has an easier way, let me know.
#1 — Francisco. Francisco is my trusty Dell XPS M140 laptop that I got about 19 months ago — that makes him middle-aged in computer years. A similarly equipped machine is now available from the same manufacturer for approximately 30% the cost I paid for Francisco, but our relationship is deeper than that. It’s not all about money, you know. And although he’s been feeling a little under the weather lately, and generally acting like someone suffering from some sort of bipolar disorder, we’ve been through a lot together, and have a strong bond. Really.
#2 — The 20″ Dell display. So I wanted to continue on for a moment with that thought you were having about me using my personal computer at work. I work at a startup company, and as you may be aware, it’s not 1999 anymore and I’m not in the Bay Area. As a result of the way the time-space continuum works, we are not funded with millions of dollars to spend on things like launch parties, massages, swanky lunches and high-end computers. Well, at least not at the beginning.
#3 — Photos of my kid. What proud father’s desk would be complete without photos of his most prized possession. This is my daughter, Charlize. We call her Charlie (named after my grandpa) and she’s the cutest baby ever. The way that you can tell is that everyone that does not have little kids says, “She is the cutest baby ever”, and the people that do have kids say, “She is the cutest baby ever except for my kids.”
#4 — A top secret drawing. I can’t tell you what this is, or I’d have to… you know. Actually I almost forgot what it was myself. It’s a good thing I didn’t forget because it’s very, very important.
#5 — My new patented “Memory Replacement”. This might not be a “Standard” yet, but trust me: it will catch on like wildfire and will be popping up on desks across the globe. To the uneducated and uninformed it looks like a simple pad of sticky notes and a pen. Not so! Recent research efforts have proven this handy little invention of mine to be an effective memory replacement for those of us who suffer from ultra-short-term memory loss (USTML). USTML can be caused by a variety of factors, including
#6 — A plastic fork. Not typically a “nonstandard” item, but I haven’t eaten anything with a fork at my desk at all in recent memory. I think I can remember how it found its home on my desk, but it’s just weird. I mean, think about it, who has a fork on their desk? Just sitting there?
#7 — A cool projectile toy. No, it’s not a fork, people; it’s a cool projectile toy. I can’t read Chinese, but the package says it’s called
#8 — An empty Live Cam box. What do you think I’m using to take these pictures with? Telepathy? A 5+ megapixel camera? My cell phone? Yeah right! Those are for losers! I use this fine piece of hardware that is currently set to take high quality photos at 240×180. It is a very versatile camera and it can be used to take pictures of computers, forks, toys, other pictures and even people. Try doing that with telepathy!
#9 — A QuickCam. What’s this? Another camera? Yes, but this one is still in it’s box. I’m sure there are many differences between this camera and the Live Cam. First, this one is called QuickCam instead of Live Cam. 2 – this one is still in the box. C) the QuickCam cost us about twice as much as the Live Cam and it is a round ball shape instead of a vertical-half-an-egg shape.
#10 — A cup of water and a cell phone in a cell phone recliner. I actually like to drink water a lot, and fortunately for me at work we have a reverse osmosis system hooked up to the fridge, so it’s like unlimited, free, good water. Woo hoo!
#11 — Some tape, lights, sensors and wire. Here is some work stuff:
#12 — An RFID reader. More work stuff. This thing is an RFID reader. That means it reads RFID. But not just any RFID, it reads passive, UHF, Class 1 Gen 2, EPCGlobal compliant RFID tags. Yeah, but the impressive part is that yellow cord hanging out of the side of it. That thing is awesome. It makes it so much easier to switch between different types of sensors. Previously, testing new sensors meant unwiring the current one and rewiring the new one, trying to remember which wire goes where. Fortunately most sensors use the same color scheme for wire colors, however, it was still a pain. Now we only use sensors that support this quick connect cable and life is easier. It kind of makes me wonder why we didn’t try this sooner.
#13 — My whiteboard. OK, yeah, this isn’t really on my desk. In fact, it’s behind me as I face my desk so it’s on a completely different side of the room. I just decided to include it so that I could have a bonus section. I always wanted to have a reason to have a bonus section in a list.
