X hits on this document

365 views

0 shares

1 downloads

0 comments

134 / 142

An Introduction to the Search/Retrieve URL Service (SRU)

  • 5.

    index all the XHTML files

  • 6.

    provide an SRU interface to search the index

Here at the Notre Dame we use scripts written against a Perl module called MARC::Record [3] to con- vert MARC data into XHTML. We use xsltproc [4] to transform XML output from SFX into more XHTML. We use swish-e [5] to index the XHTML, and finally, we use a locally written Perl script to implement an SRU interface to the index. The interface is pretty much the basic vanilla flavour, i.e. sup- porting only explain and searchResponse operations. It returns raw XML with an associated XSLT (Extensible Stylesheet Language Transformations) stylesheet, and consequently the interface assumes the patron is using a relatively modern browser with a built-in XSLT processor. Journal Locator is not a production service.

A rudimentary SRU explain operation returns an explain response. The response is expected to be trans- formed by the XSLT stylesheet specified in the output into an XHTML form. Queries submitted through the form are sent to the server as SRU searchRetrieve operations. Once the query string of the URL is parsed by the server, the search statement is passed on to a subroutine. This routine searches the index, formats the results, and returns them accordingly. An example SRU searchRetrieve request may include:

http://dewey.library.nd.edu/morgan/sru/search.cgi?operation=searchRetrieve&query=dog&version=1.1

Here is an abbreviated version of the search subroutine in the Perl script. Notice how it searches the in- dex, initialises the XML output, loops through each search result, closes all the necessary elements, and returns the result:

sub search {

  • #

    get the input

my ($query, $style) = @ ;

_

  • #

    open the index

my $swish = SWISH::API->new($INDEX);

  • #

    create a search object

my $search = $swish->New Search Object;

_

_

  • #

    do the work

my $results = $search->Execute($query);

  • #

    get the number of hits

my $hits = $results->Hits;

  • #

    begin formatting the response

my $response = "<?xml version='1.0' ?>\n";

$response $response $response $response

. . . .

= "<?xml-stylesheet type='text/xsl' href='$style' ?>\n"; = "<searchRetrieveResponse>\n"; = "<version>1.1</version>\n"; = "<numberOfRecords>$hits</numberOfRecords>\n";

# check for hits if ($hits) {

  • #

    process each found record

$response .= "<records>\n"; my $p = 0; while (my $record = $results->NextResult)

{

$response .= "<record>\n"; $response .= "<recordSchema>"

.

126

Document info
Document views365
Page views371
Page last viewedFri Dec 02 19:01:34 UTC 2016
Pages142
Paragraphs3126
Words34660

Comments