A Google Search:
If you would like to make available a Google search of your public / anonymous access site you can replace the SharePoint search box with a custom control you create.
How it works:
First you need a URL to Google that passes your list of keywords and the “site:” option with the name of your site:
http://www.google.com/search?hl=en&q=yourkeywords site:http://yourSiteURL
(I guess “q” is short for “query”???)
To be “proper” the URL should be encoded:
http://www.google.com/search?hl=en&q=yourkeywords+site%3Ahttp%3A%2F%2F
Then all you need is a Web User Control that you can create in Visual Studio or Notepad. This control can either redirect to Google using JavaScript or a little C# code.
Steps:
Note: This example requires deployment of files to the web server.
1) Create the Web User Control: (Name it GoogleSearch.ascx)
Replace “site:techtrainingnotes.blogspot.com” with your site URL.
<%@ Control Language="VB" ClassName="GoogleSearchReplacement" %> <script runat="server"> Protected Sub btnGoSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGoSearch.Click Response.Redirect("http://www.google.com/search?hl=en&q=" & search.Text + " site:techtrainingnotes.blogspot.com") End Sub </script> <asp:TextBox ID="search" runat="server"></asp:TextBox><asp:Button ID="btnGoSearch" runat="server" Text="Search Google" />
or if you prefer a JavaScript version:
<%@ Control %> <input name="q" type="text"/><a href="" onclick="javascript:GoogleSearch();return false"><img src="/_layouts/images/gosearch.gif"/></a> <script> function GoogleSearch() { document.location.href="http://www.google.com/search?q=" + document.all("q").value + " site:techtrainingnotes.blogspot.com" } </script>
2) Create a feature to for the new control:
Create a Feature.xml file (you can use your own GUID for the ID if you like)
Note: this example has the scope set to Web (activated at the individual site level)
<?xml version="1.0" encoding="utf-8" ?> <Feature xmlns="http://schemas.microsoft.com/sharepoint/" Id="1AAC958B-FF05-4d96-B678-A14F581D187A" Description="Replace SharePoint search with Google search" Scope="Web" Title="Google Search" Version="1.0.0.0" > <ElementManifests> <ElementManifest Location="elements.xml"/> </ElementManifests> </Feature>
Create the elements.xml file:
<?xml version="1.0" encoding="utf-8" ?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Control Id="SmallSearchInputBox" ControlSrc="~/_ControlTemplates/GoogleSearch.ascx" Sequence="10"> </Control> </Elements>
Notes:
- this feature replaces the existing search ASCX file normally displayed in the Delegate Control named SmallSearchInputBox
Deploy the files to the 12 hive (to all of the web servers in the farm):
- Copy GoogleSearch.ascx to ..\12\TEMPLATE\ControlTemplates folder in ..\12\
- Create a new folder in ..\12\TEMPLATE\Features named GoogleSearch
- Copy feature.xml and elements.xml to this folder
- Run this STSADM from the command prompt to install the feature.
STSADM –o installfeature –name GoogleSearch - Go to a site, select Site Actions, Site Settings and click Site features. Find this feature and activate it.
- Test the search!
.
No comments:
Post a Comment