OpenSearch
Questions answered by this recipe
- How can my site be searched using the browser's own search box?
- How can I quickly go to a page on my site by just typing a few characters from its name?
Description
This recipe implements the OpenSearch description document, its autodiscovery from wiki pages, and the OpenSearch suggestions extension that allows for search term autocompletion/autosuggestion.
To install this recipe
- download opensearch.phpΔ to your cookbook directory
- add the following to your config file:
include_once("$FarmD/cookbook/opensearch.php");
Configuration
The following variables may be set in your config file to configure the way OpenSearch works.
$OpenSearchUrl
- default:
$ScriptUrl
The base URL to add the actions to. For example, if you have a separate search page you might want to set this to"
or whatever else is applicable.$ScriptUrl
/Search"$OpenSearchData
- default:
array( 'ShortName' => substr(
$WikiTitle
, 0, 16 ), 'Description' => "Search$WikiTitle
" )
An array of XML elements to include on the OpenSearch description document, accessible usingaction=opensearchdescription
. Please see the specification for details. The only required elements are the two included by default, along with theUrl
element that is added automatically.
Notes
The autocompletion only works for page names at the moment, in order to make the script as fast as possible. As eg. Firefox doesn't support the Query URL part of the JSON autocompletion reply, the default search
action is overloaded to recognise a fully valid page name as a search term, and redirect to it.
At least for now, search results are only provided in the same HTML output as PmWiki normally produces. RSS and/or Atom feeds could be done, using customized PageList output.
As the recipe doesn't include any JavaScript or other front-end code, functionality is largely left to the user client (for now!). Autocompletion ought to work in Firefox and Google Chrome, everything else should also work in IE7 and up. Please refer to the browsers' own documentation for instructions how to add search engines.
Release Notes
- 2009-02-20Δ — first public release
See Also
- PITS:00871 Implement opensearch
- OpenSearch 1.1 (Draft 3) specification
- OpenSearch Suggestions extension
- Cookbook.FeedLinks - Add HTML-header links to enable autodiscovery of RSS/Atom feeds.
Contributors
Comments
See discussion at OpenSearch-Talk?
User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.