Welcome non-DNN developers!
 |
This blog is aimed at the DNN community but anyone can add Google AJAX Search to most any website following the steps below
(non-DNN users can skip step "2a").
We added a special welcome since we've had so many visitors for this particular topic. Enjoy the info and feel free to post questions and comments even if you don't use DNN.
This page can now be linked as: http://GoogleAJAXSearch.com
The internal DNN search engine, while convienient, still leaves much to be desired in the realm of content search. It is restricted to its own portal, returns only what is specifically made "searchable" by module developers and has no inherent feature for generating reports of what users have been searching for. With a (free) Google site search, however, you not only get the power of Google's vastly superior search algorithms but you also get to define WHAT gets serached on WHICH portals/domains and also influence HOW the results get ranked and displayed. Plus you can get free reports on what your users searched for and when they searched for it. All it takes is a small bit of text editing...
Parts 1, 2 and 3
In this, Part 1, we'll see how to get the DNN Search out of your skin and get the (free) Google AJAX search in to your skin. You can see a working example right now: try typing "DNN" in the text entry field inside the "Custom Site Search" box on this page. Google AJAX goodness inserts search results right above this blog entry without ever leaving (or refreshing) the page. You can even click through multiple pages of search results without a page postback/refresh. Sweet!
In Part 2 we will examine a few of the many options for customizing Google searches as well as ways to influence the ranking of results. Finally, in Part 3, we'll see how to tie it all in with a Google web account (totally free) so you can define and manage custom engine criteria online and get user search info reported to you via Google Analytics (also totally free).
Part 2 is now available:
http://eguanasolutions.com/Blog/tabid/54/EntryID/9/Default.aspx
A special topic, "Preventing ENTER key from Clearing Search Results" is now available:
http://eguanasolutions.com/Blog/tabid/54/EntryID/14/Default.aspx
Google Site Search
In a nutshell, a "site search" is a search that only returns results for the websites you specify. DNN Search does this for it's host portal by default. DNN Search cannot, however, return results for multiple portals and/or other specific websites -- it can only show your site, all of the web or both. This can be a problem if you operate multiple related sites and would like your users to get results from all of your sites but no other sites.
Google search, on the other hand, offers many search options as well as some fine-tuning of results. All of this can be defined as part of the underlying search code so your users don't have to do anything special -- it just happens. We'll cover a few of the more useful options in Part 2.
Example search configurations:
Suppose you have three websites: "Mine.com", "Yours.com" and "Ours.com"
- Your Google site search (GSS) on "Mine.com" could return search results from "Mine.com" and "Ours.com" with higher rankings for "Mine.com" results.
- Your GSS on "Mine.com" could return results from all three websites with highest results being the best content matches regardless of the source domain.
- Your GSS on "Mine.com" could return results from all three sites and present special "refine results" links that allow users to re-run the search and give greater weight to either "Mine", "Yours" or "Ours".
Doing More with AJAX
Besides the usual post-and-update method (submitting a form and then refreshing the page with the results), Google provides search via AJAX. This allows you to perform searches and display results without refreshing the current webpage. By contrast, DNN Search forces users to leave the current webpage and navigate to a special "Search Results" page.
AJAX also enables another great feature: mutliple searches at once. Why multiple searches at once? Imagine: your user can enter a search term and you can return blocks of results featuring matching web pages, matching files, matching blogs, etc. In short, you can return search results pre-sorted by content type. Returning two sets of results is no harder than returning one (as we'll see in Part 2 of "Add a Google Site Search").
The Nitty-Gritty: Adding Google Search to your Skin
Ok, if you're not at all familiar with DNN skins then you might want to stop here and go get familiar with the very basics of skin files. You don't need to know how to create a skin or even how to upload a skin -- you just need to figure out how to tell what skin you're using (hint: look under ADMIN->SKINS) and where that skin's files sit on your DNN server. To add Google search to the skin itself you're going to need to open and edit (via Notepad) one of your skin's files.
(1) Find Your Skin Files
For our walkthrough, let's use one of the default DNN skins as our example skin: "DNN-Blue".
The "DNN-Blue" skin physically resides on our DNN server in the following location:
(DNN root folder)\Portals\_default\Skins\DNN-Blue
There are several variations of this skin: fixed with, variable width, left-hand menu, top-menu, etc. We're going to use the file called "Vertical Menu - Fixed Width.ascx". Remember: in practice, you would actually navigate to whatever skin directory and file YOU are using for your portal. Also be sure to save a backup copy of any file you edit BEFORE you edit it!
(2) Edit Your Skin in Four Easy Steps
Use Notepad (or your favorite text editor) to open the file "Vertical Menu - Fixed Width.ascx". TIP: If you are using Notepad, select VIEW -> STATUS BAR so you'll be able to tell what line and column your cursor is on. If the "STATUS BAR" option is greyed-out and not selectable, make sure "Word Wrap" is not selected under FORMAT -> WORD WRAP.
NOTE: For formatting purposes, all HTML tags are shown with an extra space just after the "<" symbol and just before the closing ">" symbol. You may need to remove the extra spaces if you copy-and-paste code directly from this page.
(2a) On line 4, remove the following tag:
< %@ Register TagPrefix="dnn" TagName="SEARCH" Src="~/Admin/Skins/Search.ascx" % >
(2b) Now for two replacements: On line 33, column 67, replace the following tag:
< dnn:SEARCH runat="server" id="dnnSEARCH" showWeb="True" showSite="True" / ><%@ Register TagPrefix="dnn" TagName="SEARCH" Src="~/Admin/Skins/Search.ascx" %>
with this tag:
< input id="gss_input" size="10" type="text" / >
Then on line 55, replace the following:
< TD class="contentpane" id="ContentPane" runat="server" valign="top" align="center" >< /TD >
with this:
< TD valign="top" align="center" >
< div id="gcsResults" >< /div >
< div class="contentpane" id="ContentPane" runat="server" >< /div >
< /TD >
(2c) Now add a reference to the Google AJAX library. Place the following line at the top of your file (before all other lines):
< script src="http://www.google.com/jsapi" type="text/javascript" >< /script >
(2d) Finally, the nitty-gritty. In Part 2 we'll go over this piece in more detail but for now, just add the following code starting with the line immediately after the line we just added in step 2c:
< script language="Javascript" type="text/javascript" >
< !--
google.load('search', '1.0');
function OnLoad()
{
var searchControl = new google.search.SearchControl();
var drawOptions = new google.search.DrawOptions();
drawOptions.setInput(document.getElementById("gss_input"));
var options = new google.search.SearcherOptions();
options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
options.setRoot(document.getElementById("gcsResults"));
// options.setNoResultsString("No results found."); <-- This option is broken as of 11/10/2008
searchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF);
searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
var siteSearch = new google.search.WebSearch();
siteSearch.setSiteRestriction("YOUR WEBSITE URL GOES HERE");
searchControl.addSearcher(siteSearch, options);
searchControl.draw(null, drawOptions);
}
google.setOnLoadCallback(OnLoad, true);
-- >
< /script >
Your Website's URL:
Be sure to put your website's URL in place of "YOUR WEBSITE URL GOES HERE". If you would prefer to allow the search to return results from any website (i.e., a regular Google search) simply leave out the entire line of code beginning with "siteSearch.setSiteRestriction".
Where Search Results Appear:
This code will place search results in the "gcsResults" DIV we inserted just above the DNN skin's "Content" pane. Nothing will appear in the "gcsResults" DIV until an actual search is performed. If you prefer the results to appear elsewhere, move the DIV with the ID value "gcsResults" to a position just before the desired target area. For instance, to have the results appear above any content in the skin's TOP pane, make the second replacement in step 2B to line 48 ("TopPane") instead of line 55 ("ContentPane") and substitute "TopPane" for "ContentPane" in the CLASS and ID values.
That's it! Save your updated "Vertical Menu - Fixed Width.ascx" file back to the server (you DID make a copy of it first, right?) and your Google Site Search should be all set -- it's now part of the site skin.
Coming in Part 2 and Part 3
In "Part 2" we'll pick through the "nitty-gritty" code from step 2D. I'll cover how to customize Google search options to span multiple sites and how to influence the order of results. We'll also learn how to perform multiple searches at once, retuning the results in categories based on content type. Click here to continue to Part 2.
Finally, in "Part 3", we'll tie it all in with a (free) Google web account so we can employ online management of our custom search engines as well as access reports on what our users are searching for.