OpenSearch is a standard format for sharing search results across different systems. It helps various search engines and search clients to communicate, by introducing a common set of formats for performing search requests and syndicating search results.
Refer to the OpenSearch web site at http://www.opensearch.org for specifications and documentation.
Alfresco has adopted open standards throughout its framework, and OpenSearch is one such standard. This enables a standards-based interface for searching the content in the repository. For example, you can search the content in Alfresco from any application, which may be written in any other programming language and/or running on any other platform.
Alfresco exposes its search engines via OpenSearch and also provides a new aggregate open search feature in the Alfresco Explorer.
You
can see the available open search engines by navigating to the following URL, http://<servername>:<port>/alfresco/service/api/search/engines
.
There are two open search engines available out of the box. One is a keyword (Google-like) search and the other is a person (registered member) search. Click on a specific Engine to view its description and usage.
This search is similar to the keyword search of the Alfresco Explorer. Documents containing the specified keywords in their name or content are returned.
The search URL format is as follows:
http://<servername>:<port>/alfresco/service/api/search/keyword?q={searchTerms}&p={startPage?}&c={count?}&l={language?}
The following parameters needs to be provided. The optional parameters are usually listed with a question mark.
searchTerms
: keyword or keywords to search on startPage
(optional): the page number of the search results required by the client count
(optional): the number of search results per page (default: 10) language
(optional): the locale to search with (XML 1.0 Language Id, for example, en-GB)The output response can either be in HTML, ATOM or RSS. The default output format is HTML.
Consider the following sample keyword search:
http://localhost:8080/alfresco/service/search/keyword.html?q=alfresco&c=5
In the URL, keyword.html
indicates that the desired output is HTML. The search term is alfresco
and the number of search results to be listed per page should be 5
. The following screenshot displays the search results. If the search returns more results than the count specified (which is 5 in our example), then you will see links to subsequent results pages at the bottom of the screen.
You can also consider using the RSS output if you have the RSS reader, or if you would like to display the search results in a custom application, such as a Portal. The URL format remains the same, except that the file extension is rss
.
The search interface is provided through Alfresco web scripts. You can customize the search result format by customizing these web scripts. More information about web scripts is provided in Chapter 9.
The
Alfresco Explorer can be used as an OpenSearch aggregator in order to search across multiple repositories. When you log in to the Alfresco Explorer, you will notice the OpenSearch
box on the left-hand side, along with a navigation window.
New search engines can be registered with Alfresco by placing them in the <extension>/web-scripts-config-custom.xml
file.
Let us register the following search engines with Alfresco.
There is a sample file that you can use in the <extension>
folder. Rename the sample file web-scripts-config-custom.xml.sample
to web-scripts-config-custom.xml
and edit it as follows.
<!-- File: extension/web-scripts-config-custom.xml --> <!-- Example configuration of multiple OpenSearch engines --> <!-- --> <alfresco-config> <config evaluator="string-compare" condition="OpenSearch"> <opensearch> <engines> <!-- --> <!-- Example: Remote Alfresco Server --> <!-- --> <engine label="Remote Alfresco Repository" proxy="remote"> <url type="application/atom+xml"> http://partners.alfresco.com/alfresco/api/service/search/keyword.atom?q={searchTerms}&p={startPage?}&c={count?}&l={language?}&guest=true </url> <url type="application/rss+xml"> http://partners.alfresco.com/alfresco/api/service/search/keyword.rss?q={searchTerms}&p={startPage?}&c={count?}&l={language?}&guest=true </url> </engine> <!-- --> <!-- Example: Yahoo Search Engine --> <!-- --> <engine label="Yahoo Search" proxy="yahoo"> <url type="application/rss+xml"> http://api.search.yahoo.com/WebSearchService/rss/webSearch.xml?appid=yahoosearchwebrss&query={searchTerms}&start={startIndex?}&results={count?} </url> </engine> <!-- --> <!-- Example: Registration of Wikipedia --> <!-- --> <engine label="Wikipedia Search" proxy="wikipedia"> <url type="application/rss+xml"> http://api.search.yahoo.com/WebSearchService/rss/webSearch.xml?appid=yahoosearchwebrss&query={searchTerms}&site=wikipedia.org&start={startIndex?}&results={count?} </url> </engine> </engines> </opensearch> </config> </alfresco-config>
You can configure Alfresco's OpenSearch to directly submit the search request to the external search engine. It may be necessary to configure a search engine proxy. This means that the OpenSearch client indirectly submits a search request via the Alfresco Web Server (i.e. the proxy), rather than directly to the search engine. This is particularly useful in scenarios where the client is an AJAX-based browser, which is limited by cross-domain scripting locks.
Creating a search engine proxy is as simple as adding the proxy attribute to the engine configuration. The value of this attribute is a unique name that identifies the engine.
After creating and editing the web-scripts-config-custom.xml
file, restart Alfresco.
Log in to the Alfresco Explorer to view the OpenSearch features that you have added. You will notice the new entries for Remote Alfresco Repository, Yahoo Search, and Wikipedia Search. When you search for keywords, the search is federated across multiple content sources and unified results are provided, as shown in the following screenshot: