[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Koha-cvs] koha/opac opensearch opensearchdescription [dev_week]
From: |
Joshua Ferraro |
Subject: |
[Koha-cvs] koha/opac opensearch opensearchdescription [dev_week] |
Date: |
Tue, 19 Dec 2006 14:33:23 +0000 |
CVSROOT: /sources/koha
Module name: koha
Branch: dev_week
Changes by: Joshua Ferraro <kados> 06/12/19 14:33:23
Added files:
opac : opensearch opensearchdescription
Log message:
Working opensearch scripts -- need to create some sysprefs for the
values
in here rather than hardcode them in the script. Also, they were written
against an older version of the opensearch standard and could use some
updating ...
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/opac/opensearch?cvsroot=koha&only_with_tag=dev_week&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/opac/opensearchdescription?cvsroot=koha&only_with_tag=dev_week&rev=1.1.2.1
Patches:
Index: opensearch
===================================================================
RCS file: opensearch
diff -N opensearch
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ opensearch 19 Dec 2006 14:33:22 -0000 1.1.2.1
@@ -0,0 +1,210 @@
+#!/usr/bin/perl -w
+#Configurable variables:
+my $libraryname = "Nelsonville Public Library System";
+my $librarylogo = "http://athenscounty.lib.oh.us/img/Hills_shadowed.gif";
+my $libraryhomepage = "http://athenscounty.lib.oh.us";
+my $libraryOPACurl = "http://search.athenscounty.lib.oh.us";
+my $zebraaddress = "66.213.78.76";
+my $zebraport = "9999";
+my $zebradb = "NPLKoha";
+my $amazonimages = "1";
+
+my $searchurl = $libraryOPACurl."/search?q=";
+my $itemdetaillink = $libraryOPACurl."/bib/";
+my $reservelink = $libraryOPACurl."/opac-reserve.pl?bib=";
+my $authorlink = "http://search.athenscounty.lib.oh.us/search?q=au:";
+
+#use C4::Context;
+use Encode;
+use URI::Escape;
+use CGI;
+#use CGI::Carp qw(fatalsToBrowser);
+use ZOOM;
+use MARC::Record;
+use strict;
+my ($searchTerms, $searchindex, $startPage);
+my ($count, $startfrom);
+my ($totalResults);
+my $conn = new ZOOM::Connection($zebraaddress,$zebraport,
+ databaseName => "$zebradb") or die "can't get a
connection";
+
+my $cgi = new CGI;
+binmode(STDOUT, "utf8"); #output as utf8
+
+print $cgi->header( -type =>'text/xml' );
+
+$searchTerms = $cgi->param('q');
+$searchurl.=$searchTerms;
+$searchTerms =~ s/ / and /g;
+#warn "search terms:".$searchTerms;
+$startPage = $cgi->param('startPage');
+$startfrom = '1';
+$count = '10';
+if ($cgi->param('count')) {
+ $count = $cgi->param('count');
+}
+if ($startPage) {
+if ($startPage > 1) {
+ my $newstartfrom = ($startPage * $count);
+# warn "new start from=".$newstartfrom;
+ $newstartfrom-=($count - 1);
+ $startfrom = $newstartfrom;
+# warn "new start from 2:".$startfrom;
+ }
+}
+my $rs = $conn->search_pqf("address@hidden 4=106 address@hidden 2=102
address@hidden 4=106 \"$searchTerms\"") or die "can't do the search";
+$rs->option(preferredRecordSyntax => "USMARC");
+$rs->option(elementSetName => "f");
+if ($searchTerms) {
+ $rs->records($startfrom, $count, 1) or die ".....$!";
+
+ $totalResults = $rs->size() or warn "can't count";
+
+ print "<?xml version='1.0' encoding='utf-8' ?>\n";
+ print "<rss version='2.0'
xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'
xmlns:openIll=\"http://open-ils.org/xml/openIll/1.0\">";
+ print "<channel>\n";
+ print "<title>Search for: $searchTerms at the $libraryname</title>\n";
+ print "<link>$searchurl</link>\n";
+ print "<description>Search results for $searchTerms at the
$libraryname</description>\n";
+ print "<language>en-us</language>\n";
+ print "<copyright>\&copy; 2005, The $libraryname.</copyright>\n";
+ print "<lastBuildDate>Wed, 08 Jun 2005</lastBuildDate>\n";
+ print "<docs></docs>\n";
+ print "<generator>Koha-RSS</generator>\n";
+ print
"<openSearch:totalResults>$totalResults</openSearch:totalResults>\n";
+ print "<openSearch:startIndex>$startfrom</openSearch:startIndex>\n";
+ print "<openSearch:itemsPerPage>$count</openSearch:itemsPerPage>\n";
+ print "<ttl></ttl>\n";
+ print "<image>\n";
+ print "<title>The $libraryname logo</title>";
+ print "<url>$librarylogo</url>\n";
+ print "<link> $libraryhomepage</link>";
+ print "</image>\n";
+ my $starting = "0";
+ $starting = $startfrom if $startfrom; #$count * $startfrom - ($count -
1);
+ my $ending = $starting + $count - 1;
+ if ($ending > $totalResults) {
+ $ending = $totalResults;
+ }
+ warn "start and end:"."$starting"."$ending";
+ for (my $i=$starting; $i<=$ending; $i++) {
+ #warn "start:".$i;
+ if ($rs->record($i)){
+ #warn "got this far";
+ my $rec = $rs->record($i);
+ my $raw = $rec->raw();
+ #warn "raw data:".$raw;
+ #if ($rec->isa('Net::Z3950::Record::USMARC')) {
+ my $marc = MARC::Record->new_from_usmarc($raw) or die "marc not
working";
+ my $bib;
+ $bib = $marc->subfield('090',"c"); # this is where bibids are
stored
+ $bib = encode("utf8", $bib);
+ #warn "here's the bib:".$bib;
+
+ my $title = $marc->title_proper();
+ $title = encode("utf8", $title);
+ $title =~ s/&/&/;
+
+ my $author = $marc->author();
+ $author = encode("utf8", $author);
+ $author =~ s/&/&/;
+ my $authorlinker = $author;
+ $authorlinker =~ s/ /%2C%20/;
+
+ my $edition = $marc->edition();
+ $edition = encode("utf8", $edition);
+ $edition =~ s/&/&/;
+
+ my $pub_date = $marc->publication_date();
+ $pub_date = encode("utf8", $pub_date);
+ $pub_date =~ s/&/&/;
+ #warn "publication date:".$pub_date;
+
+ my $isbn = $marc->subfield('020',"a");
+ if ($isbn) {
+ $isbn = encode("utf8", $isbn);
+ $isbn =~ s/&/&/;
+ }
+ #grab holdings
+ my $holdings;
+ my $copies;
+ my $description = '';
+ #my $description = "<![CDATA[";
+ my @fields = $marc->field('952');
+ if (@fields) {
+ foreach my $field(@fields) {
+ my $branch = $field->subfield('b');
+ $holdings.=" ".$field->subfield('b').", "
unless $holdings =~ m/$branch/;
+ $copies++;
+ }
+ $holdings = "<br /><b>($copies) Copies at:</b>
".$holdings;
+ $holdings.="<a href=\"$reservelink$bib\">Place
Reserve</a>";
+ }
+ my $subjects;
+ my @subjectfields = $marc->field('6..');
+ if (@subjectfields) {
+ foreach my $field(@subjectfields) {
+ my $subjectentry = $field->subfield('a');
+ my $subjectentrylinker = $subjectentry;
+ $subjectentrylinker =~
s/(\(|\)|\.|\?|\:|\!|\'|,|\-|\"|\(|\)|\[|\]|\{|\})/%20/;
+ $subjects.=" <a
href=\"http://search.athenscounty.lib.oh.us/cgi-bin/koha/opac-search.pl?op=do_search&marclist=bibliosubject.subject&and_or=and&operator=contains&value=$subjectentrylinker\">$subjectentry</a>,
";
+ }
+ }
+
+ if ($author) {
+ $description.="<b>Author:</b> <a
href=\"http://search.athenscounty.lib.oh.us/cgi-bin/koha/opac-search.pl?marclist=biblio.author&and_or=and&excluding=&operator=contains&value=$authorlinker&resultsperpage=20&orderby=biblio.title&op=do_search\">$author</a><br
/>";
+ }
+ if ($subjects) {
+ $description.="<b>Subjects:</b>$subjects<br />";
+ }
+ if ($pub_date) {
+ $description.="<b>Details:</b>";
+ $description.="$edition " unless (!$edition);
+ $description.="$pub_date" unless (!$pub_date);
+ }
+ #grab descriptions
+ my $notes;
+ my @notesfields = $marc->field('5..');
+ if (@notesfields) {
+ #$notes.= @notesfields->as_formatted();
+ #warn "herea re notes:".$notes;
+ #foreach my $field(@notesfields) {
+ # $notes.=" ".$field->subfield('a').", " unless
(!$field->subfield('a'));
+ #}
+ }
+ $description.=$notes unless (!$notes);
+ #$marc->subfield('500',"a") unless
(!$marc->subfield('500',"a"));
+ #$description.=$marc->subfield('520',"a") unless
(!$marc->subfield('520',"a"));
+
+ if ($isbn) {
+ if ($amazonimages) {
+ $description.="<br /><img style=\"border-color: #FFFFFF;
border:none;\"border=\"0\"
src=\"http://images.amazon.com/images/P/$isbn.01.THUMBZZZ.jpg\" alt=\"read
inside\" />";
+ }}
+ $description.=$holdings unless (!$holdings);
+ #$description.="<hr />\n]]>";
+ $description =~ s/&/&/g;
+ $description =~ s/>/>/g;
+ $description =~ s/</</g;
+ $description = encode("utf8",$description);
+
+ my $link = "$libraryOPACurl/opac-detail.pl?bib=$bib";
+
+ #rank
+ #my $rank;
+ #my $ranker = $marc->field('999'); #$marc->subfield('999',"a");
# = $marc->field('999')->data(); #$marc->field('999');
+ # $bib = $marc->subfield('090',"c");
+ #$rank = $ranker;
+ #warn "ranking".$ranker;
+ print "<item>\n";
+ #print "<openIll:relevance>$rank</openIll:relevance>\n";
+ print "<title>$title</title>\n";
+ print "<link>$link</link>\n";
+ print "<description>$description</description>\n";
+ print "</item>\n";
+ # } else {warn "not usmarc"; }
+ } else {warn "no record"; }
+ }
+ print "</channel>\n";
+ print "</rss>";
+
+}
Index: opensearchdescription
===================================================================
RCS file: opensearchdescription
diff -N opensearchdescription
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ opensearchdescription 19 Dec 2006 14:33:23 -0000 1.1.2.1
@@ -0,0 +1,23 @@
+#!/usr/bin/perl -w
+use CGI;
+use strict;
+my $cgi = new CGI;
+binmode(STDOUT, "utf8"); #output as utf8
+
+print $cgi->header( -type =>'text/xml' );
+print "<?xml version='1.0' encoding='utf-8' ?>";
+print "<OpenSearchDescription
\n\txmlns=\"http://a9.com/-/spec/opensearchdescription/1.0/\"\n\txmlns:openIll=\"http://open-ils.org/xml/openIll/1.0\">";
+print
"\n<Url>http://search.athenscounty.lib.oh.us/opensearch?q={searchTerms}&searchindex=NPLKoha&startPage={startPage}&count={count}</Url>";
+print "\n<Format>http://a9.com/-/spec/opensearchrss/1.0/</Format>";
+print "\n<ShortName>NPLKoha</ShortName>";
+print "\n<LongName>Nelsonville Public Library System (NPLS) Ohio</LongName>";
+print "\n<Description>Search for items the in Nelsonville Public Library
System's Catalog.</Description>";
+print "\n<Tags>Koha ILS Catalog Public Library OPAC NPLS-RSS</Tags>";
+print "\n<Image>http://athenscounty.lib.oh.us/img/Hills_shadowed.gif</Image>";
+print "\n<SampleSearch>cryptonomicon</SampleSearch>";
+print "\n<Developer>Joshua Ferraro</Developer>";
+print "\n<Contact>address@hidden</Contact>";
+print "\n<Attribution>Koha from LibLime:
http://liblime.com/koha</Attribution>";
+print "\n<SyndicationRight>open</SyndicationRight>";
+print "\n<AdultContent>false</AdultContent>";
+print "\n</OpenSearchDescription>";
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Koha-cvs] koha/opac opensearch opensearchdescription [dev_week],
Joshua Ferraro <=