From c5cb4e2a1b2b663a71b0e04205715e0ba5d53cf5 Mon Sep 17 00:00:00 2001 From: miker Date: Fri, 23 Jun 2006 07:24:00 +0000 Subject: [PATCH] feed improvements git-svn-id: svn://svn.open-ils.org/ILS/trunk@4732 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../Application/Storage/Publisher/metabib.pm | 12 +-- .../perlmods/OpenILS/Application/SuperCat.pm | 37 +++++++- Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm | 91 ++++++++++++------- .../src/perlmods/OpenILS/WWW/SuperCat/Feed.pm | 25 +++-- Open-ILS/xsl/ATOM2XHTML.xsl | 5 +- 5 files changed, 122 insertions(+), 48 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm index c6e561934a..bfedb17bf7 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm @@ -55,7 +55,7 @@ sub ordered_records_from_metarecord { item_type, item_form, quality, - FIRST(COALESCE(LTRIM(SUBSTR( value, COALESCE(SUBSTRING(ind2 FROM '\\\\d+'),'0')::INT )),'zzzzzzzz')) AS title + FIRST(COALESCE(LTRIM(SUBSTR( value, COALESCE(SUBSTRING(ind2 FROM '\\\\d+'),'0')::INT + 1 )),'zzzzzzzz')) AS title FROM ( SELECT rd.record, rd.item_type, @@ -538,7 +538,7 @@ sub biblio_multi_search_full_rec { } elsif (lc($sort) eq 'title') { $rank = <<" RANK"; ( FIRST (( - SELECT COALESCE(LTRIM(SUBSTR( frt.value, COALESCE(SUBSTRING(frt.ind2 FROM '\\\\d+'),'0')::INT )),'zzzzzzzz') + SELECT COALESCE(LTRIM(SUBSTR( frt.value, COALESCE(SUBSTRING(frt.ind2 FROM '\\\\d+'),'0')::INT + 1 )),'zzzzzzzz') FROM $metabib_full_rec frt WHERE frt.record = f.record AND frt.tag = '245' @@ -1158,7 +1158,7 @@ sub postfilter_search_class_fts { } elsif (lc($sort) eq 'title') { $rank = <<" RANK"; ( FIRST (( - SELECT COALESCE(LTRIM(SUBSTR( frt.value, COALESCE(SUBSTRING(frt.ind2 FROM '\\\\d+'),'0')::INT )),'zzzzzzzz') + SELECT COALESCE(LTRIM(SUBSTR( frt.value, COALESCE(SUBSTRING(frt.ind2 FROM '\\\\d+'),'0')::INT + 1 )),'zzzzzzzz') FROM $metabib_full_rec frt WHERE frt.record = mr.master_record AND frt.tag = '245' @@ -1559,7 +1559,7 @@ sub postfilter_search_multi_class_fts { my $secondary_sort = <<" SORT"; ( FIRST (( - SELECT COALESCE(LTRIM(SUBSTR( sfrt.value, COALESCE(SUBSTRING(sfrt.ind2 FROM '\\\\d+'),'0')::INT )),'zzzzzzzz') + SELECT COALESCE(LTRIM(SUBSTR( sfrt.value, COALESCE(SUBSTRING(sfrt.ind2 FROM '\\\\d+'),'0')::INT + 1 )),'zzzzzzzz') FROM $metabib_full_rec sfrt, $metabib_metarecord mr WHERE sfrt.record = mr.master_record @@ -1592,7 +1592,7 @@ sub postfilter_search_multi_class_fts { } elsif (lc($sort) eq 'title') { $rank = <<" RANK"; ( FIRST (( - SELECT COALESCE(LTRIM(SUBSTR( frt.value, COALESCE(SUBSTRING(frt.ind2 FROM '\\\\d+'),'0')::INT )),'zzzzzzzz') + SELECT COALESCE(LTRIM(SUBSTR( frt.value, COALESCE(SUBSTRING(frt.ind2 FROM '\\\\d+'),'0')::INT + 1 )),'zzzzzzzz') FROM $metabib_full_rec frt WHERE frt.record = mr.master_record AND frt.tag = '245' @@ -2018,7 +2018,7 @@ sub biblio_search_multi_class_fts { } elsif (lc($sort) eq 'title') { $rank = <<" RANK"; ( FIRST (( - SELECT COALESCE(LTRIM(SUBSTR( frt.value, COALESCE(SUBSTRING(frt.ind2 FROM '\\\\d+'),'0')::INT )),'zzzzzzzz') + SELECT COALESCE(LTRIM(SUBSTR( frt.value, COALESCE(SUBSTRING(frt.ind2 FROM '\\\\d+'),'0')::INT + 1 )),'zzzzzzzz') FROM $metabib_full_rec frt WHERE frt.record = b.id AND frt.tag = '245' diff --git a/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm b/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm index 130c2734bf..29e60d46dc 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm @@ -307,7 +307,7 @@ sub new_record_holdings { } )->gather(1); - my $o_search = { shortname => $ou }; + my $o_search = { shortname => uc($ou) }; if (!$ou || $ou eq '-') { $o_search = { parent_ou => undef }; } @@ -620,6 +620,41 @@ sub retrieve_record_transform { return entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $marc ) )->toString); } +sub retrieve_record_objects { + my $self = shift; + my $client = shift; + my $ids = shift; + + $ids = [$ids] unless (ref $ids); + $ids = [grep {$_} @$ids]; + + return [] unless (@$ids); + + my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' ); + return $_storage->request('open-ils.cstore.direct.biblio.record_entry.search.atomic' => { id => [grep {$_} @$ids] })->gather(1); +} +__PACKAGE__->register_method( + method => 'retrieve_record_objects', + api_name => 'open-ils.supercat.record.object.retrieve', + api_level => 1, + argc => 1, + signature => + { desc => <<" DESC", +Returns the Fieldmapper object representation of the requested bibliographic records + DESC + params => + [ + { name => 'bibIds', + desc => 'OpenILS biblio::record_entry ids', + type => 'array' }, + ], + 'return' => + { desc => 'The bib records', + type => 'array' } + } +); + + sub retrieve_metarecord_mods { my $self = shift; diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm index 993783a25c..494019b117 100644 --- a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm +++ b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm @@ -25,7 +25,7 @@ use OpenILS::WWW::SuperCat::Feed; # set the bootstrap config when this module is loaded -my ($bootstrap, $supercat, $actor, $parser, $search); +my ($bootstrap, $cstore, $supercat, $actor, $parser, $search); sub import { my $self = shift; @@ -36,6 +36,7 @@ sub import { sub child_init { OpenSRF::System->bootstrap_client( config_file => $bootstrap ); $supercat = OpenSRF::AppSession->create('open-ils.supercat'); + $cstore = OpenSRF::AppSession->create('open-ils.cstore'); $actor = OpenSRF::AppSession->create('open-ils.actor'); $search = OpenSRF::AppSession->create('open-ils.search'); $parser = new XML::LibXML; @@ -405,8 +406,8 @@ sub bookbag_feed { $feed->creator($host); $feed->update_ts(gmtime_ISO8601()); - $feed->link(atom => $base . "/atom/$id" => 'application/atom+xml'); - $feed->link(rss2 => $base . "/rss2/$id"); + $feed->link(rss => $base . "/rss2/$id" => 'application/rss+xml'); + $feed->link(alternate => $base . "/atom/$id" => 'application/atom+xml'); $feed->link(html => $base . "/html/$id" => 'text/html'); $feed->link(unapi => $unapi); @@ -473,9 +474,9 @@ sub changes_feed { $feed->creator($host); $feed->update_ts(gmtime_ISO8601()); - $feed->link(atom => $base . "/atom/$rtype/$axis/$date/$limit" => 'application/atom+xml'); - $feed->link(rss2 => $base . "/rss2/$rtype/$axis/$date/$limit"); - $feed->link(html => $base . "/html/$rtype/$axis/$date/$limit" => 'text/html'); + $feed->link(rss => $base . "/rss2/$rtype/$axis/$limit/$date" => 'application/rss+xml'); + $feed->link(alternate => $base . "/atom/$rtype/$axis/$limit/$date" => 'application/atom+xml'); + $feed->link(html => $base . "/html/$rtype/$axis/$limit/$date" => 'text/html'); $feed->link(unapi => $unapi); $feed->link( @@ -526,10 +527,10 @@ Content-type: application/opensearchdescription+xml; charset=utf-8 $lib Search the $lib OPAC by $class. $lib book library + - param('searchLang'); $sort ||= $cgi->param('searchSort'); + $sortdir ||= $cgi->param('searchSortDir'); $terms ||= $cgi->param('searchTerms'); $class ||= $cgi->param('searchClass') || '-'; $type ||= $cgi->param('responseType') || '-'; @@ -652,20 +654,28 @@ sub opensearch_feed { my $cache_key = ''; my $searches = {}; - while ($term_copy =~ /(keyword|title|author|subject|series|site|sort|lang):([^:]+?)$/o) { - my $c = $1; - my $t = $2; - $term_copy =~ s/(keyword|title|author|subject|series|site|sort|lang):([^:]+?)$//o; + while ($term_copy =~ s/((?:keyword|title|author|subject|series|site|dir|sort|lang):[^:]+)$//so) { + warn $1 . " <<< "; + my ($c,$t) = split ':' => $1; if ($c eq 'site') { - ($org = uc($t)) =~ s/\s+//go; + $org = $t; + $org =~ s/^\s*//o; + $org =~ s/\s*$//o; + warn $org . " >>> "; } elsif ($c eq 'sort') { - ($sort = lc($t)) =~ s/^\s*(\w+)/$1/go; + ($sort = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go; + warn $sort . " >>> "; + } elsif ($c eq 'dir') { + ($sortdir = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go; + warn $sortdir . " >>> "; } elsif ($c eq 'lang') { - ($lang = lc($t)) =~ s/^\s*(\w+)/$1/go; + ($lang = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go; + warn $lang . " >>> "; } else { - $$searches{$c} = { term => $t }; + $$searches{$c}{term} .= ' '.$t; $cache_key .= $c . $t; $complex_terms = 1; + warn $t . " >>> "; } } @@ -683,11 +693,11 @@ sub opensearch_feed { )->gather(1); } else { $org_unit = $actor->request( - 'open-ils.actor.org_unit_list.search' => shortname => $org + 'open-ils.actor.org_unit_list.search' => shortname => uc($org) )->gather(1); } - $cache_key .= $org.$sort.$lang; + $cache_key .= $org.$sort.$sortdir.$lang; my $rs_name = $cgi->cookie('os_session'); my $cached_res = OpenSRF::Utils::Cache->new->get_cache( "os_session:$rs_name" ) if ($rs_name); @@ -699,10 +709,11 @@ sub opensearch_feed { 'open-ils.search.biblio.multiclass' => { searches => $searches, org_unit => $org_unit->[0]->id, - ($sort ? ( 'sort' => $sort, sort_dir => 'asc' ) : ()), - ($lang ? ( 'language' => $lang) : ()), offset => 0, limit => 5000, + ($sort ? ( 'sort' => $sort ) : ()), + ($sortdir ? ( 'sort_dir' => $sortdir ) : ( sort_dir => 'asc' )), + ($lang ? ( 'language' => $lang ) : ()), } )->gather(1); try { @@ -772,14 +783,25 @@ sub opensearch_feed { 'application/opensearch+xml' ); - $feed->link( unapi => $unapi); + $feed->link( + rss => + $base . "/$version/$org/rss2/$class?searchTerms=$terms" => + 'application/rss+xml' + ); + + $feed->link( + alternate => + $base . "/$version/$org/atom/$class?searchTerms=$terms" => + 'application/atom+xml' + ); -# $feed->link( -# alternate => -# $root . "../$lang/skin/default/xml/rresult.xml?rt=list&" . -# join('&', map { 'rl=' . $_->[0] } @{$recs->{ids}} ), -# 'text/html' -# ); + $feed->link( + html => + $base . "/$version/$org/html/$class?searchTerms=$terms" => + 'text/html' + ); + + $feed->link( unapi => $unapi); $feed->link( opac => @@ -804,7 +826,7 @@ sub create_record_feed { my $records = shift; my $unapi = shift; - my $lib = shift || ''; + my $lib = shift || '-'; my $cgi = new CGI; my $base = $cgi->url; @@ -819,8 +841,12 @@ sub create_record_feed { $type = 'atom' if ($type eq 'html'); $type = 'marcxml' if ($type eq 'htmlcard' or $type eq 'htmlholdings'); - for my $rec (@$records) { - next unless($rec); + $records = $supercat->request( "open-ils.supercat.record.object.retrieve", $records )->gather(1); + + for my $record (@$records) { + #next unless($record); + my $rec = $record->id; + #my $record = $supercat->request( "open-ils.supercat.record.object.retrieve", $rec )->gather(1)->[0]; my $item_tag = "tag:$host,$year:biblio-record_entry/$rec/$lib"; @@ -839,6 +865,7 @@ sub create_record_feed { } $node->id($item_tag); + $node->update_ts(clense_ISO8601($record->edit_date)); $node->link(alternate => $feed->unapi . "?id=$item_tag&format=htmlholdings" => 'text/html'); $node->link(opac => $feed->unapi . "?id=$item_tag&format=opac"); $node->link(unapi => $feed->unapi . "?id=$item_tag"); diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm index 1aa1f88d8a..58370a1a4d 100644 --- a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm +++ b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm @@ -119,6 +119,7 @@ sub _create_node { if (ref($attrs)) { for my $key (keys %$attrs) { + next unless $$attrs{$key}; $new->setAttribute( $key => $$attrs{$key} ); } } @@ -188,7 +189,8 @@ use base 'OpenILS::WWW::SuperCat::Feed'; sub new { my $class = shift; - my $self = $class->SUPER::build(''); + my $self = $class->SUPER::build(''); + $self->{doc}->documentElement->setNamespace('http://www.w3.org/2005/Atom', undef); $self->{type} = 'application/xml'; $self->{item_xpath} = '/atom:feed'; return $self; @@ -197,20 +199,20 @@ sub new { sub title { my $self = shift; my $text = shift; - $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','atom:title', $text); + $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','title', $text); } sub update_ts { my $self = shift; my $text = shift; - $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','atom:updated', $text); + $self->_create_node($self->{item_xpath},'http://www.w3.org/2005/Atom','updated', $text); } sub creator { my $self = shift; my $text = shift; - $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','atom:author'); - $self->_create_node('/atom:feed/atom:author', 'http://www.w3.org/2005/Atom','atom:name', $text); + $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','author'); + $self->_create_node('/atom:feed/atom:author', 'http://www.w3.org/2005/Atom','name', $text); } sub link { @@ -225,7 +227,7 @@ sub link { $self->_create_node( $self->{item_xpath}, 'http://www.w3.org/2005/Atom', - 'atom:link', + 'link', undef, { rel => $type, href => $id, @@ -239,7 +241,7 @@ sub id { my $self = shift; my $id = shift; - $self->_create_node( '/atom:feed', 'http://www.w3.org/2005/Atom', 'atom:id', $id ); + $self->_create_node( '/atom:feed', 'http://www.w3.org/2005/Atom', 'id', $id ); } package OpenILS::WWW::SuperCat::Feed::atom::item; @@ -279,7 +281,7 @@ sub title { sub update_ts { my $self = shift; my $text = shift; - $self->_create_node('/rss/channel',undef,'lastBuildDate', $text); + $self->_create_node($self->{item_xpath},undef,'lastBuildDate', $text); } sub creator { @@ -320,6 +322,13 @@ sub new { return $self; } +sub update_ts { + my $self = shift; + my $text = shift; + $self->_create_node($self->{item_xpath},undef,'pubDate', $text); +} + + #---------------------------------------------------------- diff --git a/Open-ILS/xsl/ATOM2XHTML.xsl b/Open-ILS/xsl/ATOM2XHTML.xsl index db8da61a13..693a842c31 100644 --- a/Open-ILS/xsl/ATOM2XHTML.xsl +++ b/Open-ILS/xsl/ATOM2XHTML.xsl @@ -149,7 +149,7 @@ To-do list: - + @@ -160,6 +160,7 @@ To-do list:

+ +

-- 2.43.2