Skip to content

Instantly share code, notes, and snippets.

@trygvis
Created May 3, 2012 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trygvis/2590139 to your computer and use it in GitHub Desktop.
Save trygvis/2590139 to your computer and use it in GitHub Desktop.
OpenSearch 'sort' extension brain dump.
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:os="http://a9.com/-/spec/opensearch/1.1/"
xmlns:sort="http://purl.org/opensearch-sort/1.0">
<!--
A sort form lists the fields that can be sorted with the available
sorting functions used to sort the field. If a field doesn't list
a sorting function the server has a default sort function available.
This would normally be numerical order for numbers and lexicographical
for text.
The agent will pick the fields it want to sort on and put them
in a list called 'sortFields'. For each of these fields it will
find a sort function to use. It the server didn't list any available
fields or it just want the default ordering an empty string is
used. The resulting list is put in a variable called 'sortFunctions'.
Similar to the sort functions list it will build a list of sort
directions describing the wanted sort order for each field. The
list is put in a variable called 'sortDirections'.
NOTE: ideally this would all be put into a key+value list and
expanded to a set of &field=function values, but as we need both
function and order per field stuff get a bit more complicated.
NOTE: The OpenSearch specification hard code a set of variable
names so I assume it's fine to do this here as well.
-->
<sort:form>
<!-- No sort functions are listed, 'natural' is assumed as the only one available -->
<sort:field id="updated"/>
<sort:field id="published"/>
<sort:field id="thread-count"/>
<sort:field id="title"/>
<!-- Available sort functions for this field. The first function is the default function. -->
<sort:function name="natural"/>
<sort:function name="case-insensitive"/>
</sort:field>
</form>
<!--
With searchTerms = 'foo' and the sort fields are 'published',
sorted ascending and 'title' with a case-insensitive sort. The
values available for expansion are then:
searchTerms=foo
sortFields = (published,title)
sortFunctions = (,case-insensitive)
sortDirections = (asc,desc)
With the given template the full result is then:
http://example.com/?q=foo&sortFields=published,title&sortFunctions=,case-insensitive&sortDirections=asc,desc
-->
<Url template="http://example.com/?q={searchTerms}&sortFields={sortFields}&sortFunctions={sortFunctions}&sortDirections={sortDirections}"/>
</feed>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment