HowTo: Use Google site search for MediaWiki search
HowTo: Use Google site search for MediaWiki search
By Eric Hartwell - latest update July 21, 2007
- The default MediaWiki search engine is adequate
- LuceneSearch extension
- Google search - more familiar interface
- Bonus: search results will only include public pages
The Google Custom Search Engine, you can harness the power of Google to create a search engine tailored to your needs.
- A Custom Search Engine is a tailored search experience, built using Google's core search technology, which prioritizes or restricts search results based on websites and pages that you specify, and which can be tailored to reflect your point of view or area of expertise.
- Google's mission is to connect people to information - no matter how specialized or specific - as quickly as possible. The Custom Search Engine allows you to combine Google's search algorithm with your own expertise to create a customized experience - thus making access to specific information across the web easier for your users.
- Apply your website's look and feel to the search results page. You can customize the look and feel of your Custom Search Engine (CSE) results to match the style of your website using the "Look and feel" tab in your search engine's control panel. You can choose to have a logo appear with the search box at the top of your search results pages and select the colors of the background and text.
- Customizing the search box logo on your search results pages: You can choose to have a logo appear next to the search box that appears at the top of your search results pages. This logo will only appear on search results pages hosted by Google; if you place your search results on your own website, the search box and logo will not appear in these results.
- Customizing the style of your search results: You can change the background color of your search results page, as well as the colors of all the text elements in a search result (e.g. title, text, and links). These changes will appear on both results pages hosted by Google and on results pages that you host on your own site.
[edit] Installing GoogleSiteSearch
The GoogleSiteSearch extension replaces built-in search with Google Site Search. The results are nearly seamless; go/search logic works as expected.
- This extension requires a small modification of the core MediaWiki files, namely a 2-line addition to
includes/SpecialSearch.php. - To make a fully generic function, you could create a new special page derived from
class SpecialSearch- but this complicates things to the point where a simple patch is probably more reliable.
[edit] Overriding Google's styles
The results of the Google search are displayed inside an <iframe>, which means they use their own styles.
The colors can be changed through $wgGoogleSiteSearchVars settings in LocalSettings.php:
# The default color scheme compliments MediaWiki well, but can be customized here. $wgGoogleSiteSearchVars['cof'] = 'GALT:#008000;GL:1;DIV:#336699;VLC:663399;' . 'AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;' . 'GFNT:0000FF;GIMP:0000FF;FORID:9';
For example, the syntax for accessing the border style of the iframe object is:
MSDN: The IFRAME element functions as a document within a document, or like a floating FRAME.
- You can access the iframe object's properties, but not its contents, through the object model of the page where the iframe object resides.
- The frames collection provides access to the contents of an IFRAME. Use the frames collection to read or write to elements contained in an IFRAME. For example, the syntax for accessing the backgroundColor style of the body object in an iframe is:
sColor = document.frames("sFrameName").document.body.style.backgroundColor;- Note Properties of the iframe must be accessed using the prefix, document.all, for example, document.all.iframeId.marginWidth.