From e6683d5474e6729c1f627f442c2f461c0a47b5af Mon Sep 17 00:00:00 2001 From: miker Date: Tue, 13 Jun 2006 01:46:26 +0000 Subject: [PATCH] adding multiclass search to opensearch interface git-svn-id: svn://svn.open-ils.org/ILS/trunk@4596 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm | 52 ++++++++++++++++--- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm index c041989bd1..f376b0bf43 100644 --- a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm +++ b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm @@ -621,12 +621,43 @@ sub opensearch_feed { } - $class = 'keyword' if ($class eq '-'); $terms = decode_utf8($terms); $terms =~ s/\+/ /go; $terms =~ s/'//go; + my $term_copy = $terms; + + if ($terms eq 'help') { + print $cgi->header(-type => 'text/html'); + print < + + just type something! + + +

You are in a maze of dark, twisty stacks, all alike.

+ + +HTML + return Apache2::Const::OK; + } - #warn "searching for $class -> [$terms] via OS $version, response type $type"; + my $cache_key = ''; + my $searches = {}; + while ($term_copy =~ /(keyword|title|author|subject|series):(.+)/ogc) { + my $c = $1; + my $t = $2; + ($term_copy = $t) =~ s/(keyword|title|author|subject|series):(.+)//o; + $$searches{$c} = { term => $term_copy }; + $cache_key .= $c . $term_copy; + warn "searching for $c -> [$term_copy] via OS $version, response type $type"; + $term_copy = $t; + } + + if (!keys(%$searches)) { + $class = 'keyword' if ($class eq '-'); + $$searches{$class} = { term => $terms }; + $cache_key .= $class . $terms; + } my $org_unit; if ($org eq '-') { @@ -639,23 +670,25 @@ sub opensearch_feed { )->gather(1); } + $cache_key .= $org; + my $rs_name = $cgi->cookie('os_session'); my $cached_res = OpenSRF::Utils::Cache->new->get_cache( "os_session:$rs_name" ) if ($rs_name); my $recs; - if (!($recs = $$cached_res{os_results}{$class}{$terms}{$org})) { + if (!($recs = $$cached_res{os_results}{$cache_key})) { warn "NOT pulling results from cache"; $rs_name = $cgi->remote_host . '::' . rand(time); $recs = $search->request( 'open-ils.search.biblio.multiclass' => { - searches => { $class => { term => $terms, }, }, + searches => $searches, org_unit => $org_unit->[0]->id, offset => 0, limit => 5000, } )->gather(1); try { - $$cached_res{os_results}{$class}{$terms}{$org} = $recs; + $$cached_res{os_results}{$cache_key} = $recs; OpenSRF::Utils::Cache->new->put_cache( "os_session:$rs_name", $cached_res, 1800 ); } catch Error with { warn shift(); @@ -673,7 +706,12 @@ sub opensearch_feed { $feed->search($terms); $feed->class($class); - $feed->title("Search results for [$class => $terms] at ".$org_unit->[0]->name); + if (keys(%$searches) > 1) { + $feed->title("Search results for [$terms] at ".$org_unit->[0]->name); + } else { + $feed->title("Search results for [$class => $terms] at ".$org_unit->[0]->name); + } + $feed->creator($host); $feed->update_ts(gmtime_ISO8601()); @@ -728,7 +766,7 @@ sub opensearch_feed { $feed->link( opac => $root . "../$lang/skin/default/xml/rresult.xml?rt=list&" . - join('&', map { 'rl=' . $_->[0] } grep { defined $_ } @{$recs->{ids}} ), + join('&', map { 'rl=' . $_->[0] } grep { ref $_ && defined $_->[0] } @{$recs->{ids}} ), 'text/html' ); -- 2.43.2