0

Here is an example OpenSearch description file:

http://webcat.hud.ac.uk/OpenSearch.xml

When I send a query as like that:

http://webcat.hud.ac.uk/perl/opensearch.pl?keyword=new&startpage=1&itemsperpage=20

I get a response which is compatible to OpenSearch. How can I implement OpenSearch specification at Java or is there any library for it or is there any xsd that I can generate a Java code from it?

kamaci
  • 72,915
  • 69
  • 228
  • 366

2 Answers2

2

According to the OpenSearch website's section on "Reading OpenSearch", there is a Java library which can do this, called Apache Abdera. I have not used it myself, so I cannot comment on its quality, but it should be worth looking into - apparently it can both interpret AND create OpenSearch responses, so this may be exactly what you're looking for.

Alternatively, there are quite a few very good XML parsers for Java (see this question for some suggestions), so writing your own parser for a simple OpenSearch XML file shouldn't be too difficult, since the full specification is available online.

As for an XSD, I can't find an "official" one, however there are XSD's for OpenSearch in various open source projects which have been tested and you can use, such as this one, which is part of a project called "OpenSearch Validator."

Another potential choice for writing OpenSearch results is the very mature and widely-used Apache Lucene library, which is in the list of software "writing OpenSearch results" in the previously linked OpenSearch website.

Community
  • 1
  • 1
CmdrMoozy
  • 3,870
  • 3
  • 19
  • 31
  • I want to generate OpenSearch standard responses. – kamaci Oct 26 '13 at 17:30
  • Did you even look at the link to Abdera? It has the capability to generate OpenSearch results as well (requires an extra add-on module to do so). – dcsohl Oct 31 '13 at 20:21
  • Is there anything I can do to improve this answer? You ask for "a detailed working answer," and I think I've provided numerous solutions to software which will work for you. I'd love to add more detail, if you let me know what you're looking for! – CmdrMoozy Nov 01 '13 at 15:53
  • Just some things: I think that I can use XSL to generate such responses? What should I include at a response (HTML, Atom, RSS) to say that "I support Opensearch type responses"? – kamaci Nov 01 '13 at 23:21
  • XSL(T) is pretty general; you could use it to write responses in one format and then transform them into OpenSearch XML, or you could use them to render OpenSearch XML as a human-readable HTML page, or etc. As for letting clients know that you can speak in OpenSearch, that is probably really dependent on what clients are talking to you. From what I have read, OpenSearch is generally used to implement search APIs, so your clients should already know before trying to talk to you. – CmdrMoozy Nov 04 '13 at 18:39
0

ROME also supports OpenSearch with its ROME Module A9 OpenSearch.

Sample usage:

SyndFeed feed = new SyndFeedImpl();
feed.setFeedType(feedType);

// Add the opensearch module, you would get information like totalResults from the
// return results of your search
List mods = feed.getModules();
OpenSearchModule osm = new OpenSearchModuleImpl();
osm.setItemsPerPage(1);
osm.setStartIndex(1);
osm.setTotalResults(1024);
osm.setItemsPerPage(50);

OSQuery query = new OSQuery();
query.setRole("superset");
query.setSearchTerms("Java Syndication");
query.setStartPage(1);
osm.addQuery(query);

Link link = new Link();
link.setHref("http://www.bargainstriker.com/opensearch-description.xml");
link.setType("application/opensearchdescription+xml");
osm.setLink(link);

mods.add(osm);

feed.setModules(mods);
// end add module
Hendy Irawan
  • 20,498
  • 11
  • 103
  • 114