X hits on this document

434 views

0 shares

1 downloads

0 comments

113 / 142

Apache

name/value pairs of the query string, branches accordingly, and transforms parts of the XML data into HTML, which is returned to the Web browser.

CGI interfaces to XML indexes

In a previous section of the workbook you learned how to create and search simple indexes of XML files. In this section various techniques for making these indexes searchable on the Web will be demon- strated.

Simple XHTML files

Swish-e comes with a Perl module called SWISH::API providing a means to search swish-e indexes through Perl scripts and without the need of the swish-e binary. By combining the standard Perl CGI module with SWISH::API it you can make your swish-e indexes available on the Web. The program cgi-bin/xhtml.cgi implements this idea. The heart of the program is a subroutine called search:

  • #

    the heart of the matter

sub search {

  • #

    get the result page

$html .

= &results;

  • #

    open the index

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

  • #

    create a search object

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

_

_

  • #

    set the sort order

$search->SetSort('title');

  • #

    search

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

  • #

    get the number of titles found

$number of hits = $results->Hits;

_

_

  • #

    initialize the hit list

$hit list .

= '<ol>';

_

  • #

    process each hit

while (my $result = $results->NextResult)

{

  • #

    get the results

my $detail my $brief

= $result->Property ('swishdocpath'); = $result->Property ('brief');

$hit list

.

= "<li>$brief (<a href='$detail'>detailed view</a>)</li>";

_

}

  • #

    finish the hit list

_ $hit list . }

= '</ol>';

It works by:

105

Document info
Document views434
Page views440
Page last viewedThu Dec 08 04:55:00 UTC 2016
Pages142
Paragraphs3126
Words34660

Comments