Examples

The provided example uses a search for blog posts and medical records. A basic understanding of the OpenSearch specification is required.

The OpenSearch protocol is composed of two parts:

  • The OpenSearch XML description, which describes how to search the external search engine and which features it supports. The description is provided by the search engine itself at a public URL. The main element of the description is the <Url>, in which the template attribute provides the URL to call and the supported parameters with semantics.
  • The search results returned by the external search engine, in Atom or RSS format, as the response of the HTTP search request.

OpenSearch Description

1<?xml version="1.0" encoding="UTF-8"?>
2<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:sfdc="http://salesforce.com/2016/federatedsearch/1.0">
3  <ShortName>Document Search</ShortName>
4  <Contact>support@example.com</Contact>
5  <Url type="application/atom+xml" sfdc:maxTotalResults="500" 
6template="https://example.com/search?q={searchTerms}&amp;
7byId={sfdc:searchById?}&amp;type={sfdc:recordType}&amp;
8user={sfdc:userEmail}&amp;start={startIndex?}&amp;num={count?}&amp;
9sf={sfdc:sortField?}&amp;sd={sfdc:sortDirection?}"/>
10  <sfdc:RecordTypes>
11    <sfdc:RecordType name="Blog Post">
12      <sfdc:Field name="Author" type="string" sortable="true"/>
13      <sfdc:Field name="Expiration date" type="date" sortable="true"/>
14    </sfdc:RecordType>
15    <sfdc:RecordType name="Medical Record">
16      <sfdc:Field name="Main author" type="string" sortable="true"/>
17      <sfdc:Field name="Reviewed" type="boolean" sortable="false"/>
18    </sfdc:RecordType>
19  </sfdc:RecordTypes>
20  <Attribution>
21    Copyright 2016, All Rights Reserved
22  </Attribution>
23  <InputEncoding>UTF-8</InputEncoding>
24  <OutputEncoding>UTF-8</OutputEncoding>
25  <sfdc:Version>1</sfdc:Version>
26</OpenSearchDescription>

Atom Search Results

1<?xml version='1.0' encoding='UTF-8'?>
2<feed xmlns="http://www.w3.org/2005/Atom"
3xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"
4xmlns:sfdc="http://salesforce.com/2016/federatedsearch/1.0">
5  <title>Example Search: test</title>
6  <link>https://example.com</link>
7  <updated>2016-11-21T10:19:37.644Z</updated>
8  <author>
9    <name>Example</name>
10  </author>
11  <id>urn:uuid:6b63a81d-0a77-48e3-8a74-5d5f34b9da98</id>
12  <opensearch:totalResults>10</opensearch:totalResults>
13  <opensearch:startIndex>0</opensearch:startIndex>
14  <opensearch:itemsPerPage>2</opensearch:itemsPerPage>
15  <opensearch:Query role="request" searchTerms="test" startIndex="0" count="2"/>
16  <entry>
17    <title>Unit testing framework</title>
18    <id>https://example.com/id:GhITRcjf5go_JLero45</id>
19    <link href="https://www.example.com/library/unittest.html"/>
20    <sfdc:link>/apex/ExampleApp_view?id=GhITRcjf5go_JLero45&amp;q=test</sfdc:link>
21    <sfdc:recordType>Blog Post</sfdc:recordType>
22    <summary>The unit testing framework is ...</summary>
23    <updated>2016-07-13T15:24:57.000Z</updated>
24    <published>2016-07-13T15:24:57.000Z</published>
25    <sfdc:Author>Maker</sfdc:Author>
26    <sfdc:Expiration_date>2017-07-13T15:24:57.000Z</sfdc:Expiration_date>
27  </entry>
28  <entry>
29    <title>Cancer tests | Cancer Research</title>
30    <id>https://example.com/id:UCAuUUnT6oDeKwE6v1</id>
31    <link href="https://www.example.com/library/cancertest.html"/>
32    <sfdc:link>/apex/ExampleApp_view?id=UCAuUUnT6oDeKwE6v1&amp;q=test</sfdc:link>
33    <sfdc:recordType>Medical Record</sfdc:recordType>
34    <summary>A short overview about current cancer research ...</summary>
35    <updated>2012-08-15T15:20:54.000Z</updated>
36    <published>2012-08-15T15:20:54.000Z</published>
37    <sfdc:Main_author>Maker</sfdc:Main_author>
38    <sfdc:Reviewed>true</sfdc:Reviewed>
39  </entry>
40</feed>

RSS Search Results

1<?xml version="1.0" encoding="UTF-8"?>
2<rss version="2.0"
3xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"
4xmlns:sfdc="http://salesforce.com/2016/federatedsearch/1.0">
5  <channel>
6    <title>Example Search: test</title>
7    <link>https://example.com</link>
8    <description>Search results for "test" at Example.com</description>
9    <opensearch:totalResults>10</opensearch:totalResults>
10    <opensearch:startIndex>0</opensearch:startIndex>
11    <opensearch:itemsPerPage>2</opensearch:itemsPerPage>
12    <item>
13      <title>Unit testing framework</title>
14      <guid>https://example.com/id:GhITRcjf5go_JLero45</guid>
15      <link>https://www.example.com/library/unittest.html</link>
16      <description>The unit testing framework is ...</description>
17      <pubDate>Sat, 07 Sep 2002 0:00:01 GMT</pubDate>
18      <sfdc:link>/apex/ExampleApp_view?id=GhITRcjf5go_JLero45&amp;q=test</sfdc:link>
19      <sfdc:recordType>Blog Post</sfdc:recordType>
20      <sfdc:Author>Maker</sfdc:Author>
21      <sfdc:Expiration_date>2017-07-13T15:24:57.000Z</sfdc:Expiration_date>
22    </item>
23    <item>
24      <title>Cancer tests | Cancer Research</title>
25      <guid>https://example.com/id:UCAuUUnT6oDeKwE6v1</guid>
26      <link>https://www.example.com/library/cancertest.html</link>
27      <description>A short overview about current cancer research ...</description>
28      <pubDate>Sat, 07 Sep 2002 0:00:01 GMT</pubDate>
29      <sfdc:link>/apex/ExampleApp_view?id=UCAuUUnT6oDeKwE6v1&amp;q=test</sfdc:link>
30      <sfdc:recordType>Medical Record</sfdc:recordType>
31      <sfdc:Main_author>Maker</sfdc:Main_author>
32      <sfdc:Reviewed>true</sfdc:Reviewed>
33    </item>
34  </channel>
35</rss>