Google AJAX Search Plugin
Wrapper plugin for a dynamic search service provided by Google.
About Google AJAX Search
The
Google AJAX Search API
is an experimental API that lets you integrate a dynamic Google search module into your web pages so your users can mash up Google search results with other content on your site or add search results clippings to their own content.
Note that this service (as stated by Google themselves):
- Is in BETA
- Will likely change in the future, so the current implementation may break
- Future versions may contain ads
If you want to put this service on your own site you need to
obtain a (free) unique key
from Google.
NOTE: the Google key must be valid for the directory/directories you will be searching in. If you are going to search all webs, pass
http://yourdomain/twiki/bin/view/ as url.
Set
GOOGLEKEY below in
Settings.
Restricting search to a site or Web
To obtain results from a particular website, set variable
GOOGLESEARCHSITE.
To get results from one TWiki Web only, set variable
GOOGLESEARCHWEB in combination with
GOOGLESEARCHSITE.
For example:
* Set GOOGLESEARCHWEB = TWiki
* Set GOOGLESEARCHSITE = http://twiki.org/cgi-bin/view/
Set the variables below in
Settings.
Putting a search box
Start a search box with
%GOOGLEAJAXSEARCH%.
The JavaScript code written by the plugin assumes a html container element exists with id
googleAjaxSearchControl. The results will be written to this element.
The input field should have the id
googleAjaxSearchInputElement.
Current limitation: there may only be one search box on a page.
Example:
%GOOGLEAJAXSEARCH%
<div class="googleAjaxSearch">
<strong>Search %GOOGLESEARCHWEB% </strong><input class="twikiInputField" size="55" id="googleAjaxSearchInputElement" value=""/>
<span class="twikiGrayText twikiSmallish">(results by Google !AJAX - Beta)</span>
<div id="googleAjaxSearchControl"></div>
</div><!--//googleAjaxSearch-->
An input field with id 'googleAjaxSearchWeb' may override
GOOGLESEARCHWEB. For example:
<input type="hidden" id="googleAjaxSearchWeb" value="Main" />
An input field with id 'googleAjaxSearchLabel' may override
GOOGLESEARCHLABEL. For example:
<input type="hidden" id="googleAjaxSearchlabel" value="twiki.org TWiki Web" />
Re-use
To show the search box in another topic, write this:
%INCLUDE{"%TWIKIWEB%.GoogleAjaxSearchPlugin" section="default" query="" web="%BASEWEB%" label="%BASEWEB% Web (results by Google)"}%
This will include the following section (leave as is, no need to copy this):
%STARTSECTION{"default"}%%GOOGLEAJAXSEARCH%<div class="googleAjaxSearch"><strong>Search %BASEWEB% </strong><input class="twikiInputField" size="50" id="googleAjaxSearchInputElement" value="%query%" /><input type="hidden" id="googleAjaxSearchWeb" value="%BASEWEB%" /><input type="hidden" id="googleAjaxSearchlabel" value="%label%" />
<div id="googleAjaxSearchControl"></div></div><!--//googleAjaxSearch-->%ENDSECTION{"default"}%
Start search automatically
To start off with a search, pass a default search string to the input field.
Start search automatically by URL parameter
Pass parameter
googleAjaxQuery to the url to start off a default search. For example:
https://twiki.org/cgi-bin/view/Plugins/GoogleAjaxSearchPlugin?googleAjaxQuery=htaccess
Test this:
https://twiki.org/cgi-bin/view/Plugins/GoogleAjaxSearchPlugin?googleAjaxQuery=htaccess
A URL parameter will override a locally set search input value.
Customizing
Setting a custom label
You can set the label of the search results to a custom string by defining
GOOGLESEARCHLABEL in
Settings.
Settings
For an explanation of the following variables read above. These are example variable values:
- Set GOOGLEKEY = XXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXX
- Set GOOGLESEARCHWEB =
- Set GOOGLESEARCHSITE = http://twiki.org/cgi-bin/view/
- Set GOOGLESEARCHLABEL = twiki.org
- Set SHORTDESCRIPTION = Dynamic Google AJAX search service for public TWiki sites
You can set these values in this topic, or in any other topic where
%GOOGLEAJAXSEARCH% is written. Note that you will need to use the syntax GOOGLEAJAXSEARCHPLUGIN_MYVARIABLE if you set the variable in a different web.
Example
To see it work (if installed and the right Google key is set):
Warning: Can't find topic TWiki06x01.GoogleAjaxSearchPlugin
Plugin Installation Instructions
- Download the ZIP file from the Plugin web (see below)
- Unzip
GoogleAjaxSearchPlugin.zip in your root ($TWIKI_ROOT) directory. Content: | File: | Description: |
data/TWiki/GoogleAjaxSearchPlugin.txt | |
lib/TWiki/Plugins/GoogleAjaxSearchPlugin/build.pl | |
lib/TWiki/Plugins/GoogleAjaxSearchPlugin.pm | |
pub/TWiki/GoogleAjaxSearchPlugin/googleAjaxSearch.css | |
pub/TWiki/GoogleAjaxSearchPlugin/googleAjaxSearch.js | |
- Optionally, if it exists, run
GoogleAjaxSearchPlugin_installer to automatically check and install other TWiki modules that this module depends on. You can also do this step manually.
- Alternatively, manually make sure the dependencies listed in the table below are resolved. None
- (Dakar) Visit
configure in your TWiki installation, and enable the plugin in the {Plugins} section.
Contrib Info
Related Topics: TWikiPreferences