From 84233f4b6d11f3f2136d1fa30071da0c34e5fc9f Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Mon, 11 Feb 2008 16:21:48 -0600 Subject: [PATCH] FRBR: added OPAC search result grouping option Because this feature is experimental, the syspref will not be added to the list just yet. Signed-off-by: Joshua Ferraro --- C4/Search.pm | 32 ++++++++++++++++++-------------- C4/Search/PazPar2.pm | 2 ++ opac/opac-search.pl | 24 +++++++++++++++++++----- 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index e586ebf5b3..a7d8ecf3d8 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -623,7 +623,6 @@ sub pazGetRecords { my $paz = C4::Search::PazPar2->new('http://localhost:10006/search.pz2'); $paz->init(); - #die $simple_query; $paz->search($simple_query); sleep 1; @@ -631,31 +630,36 @@ sub pazGetRecords { my $results_hashref = {}; my $stats = XMLin($paz->stat); $results_hashref->{'biblioserver'}->{'hits'} = $stats->{'hits'}; - my $results = XMLin($paz->show($offset, $results_per_page), forcearray => 1); - #die Dumper($results); + my $results = XMLin($paz->show($offset, $results_per_page, 'work-title:1'), forcearray => 1); + HIT: foreach my $hit (@{ $results->{'hit'} }) { - warn "hit"; my $recid = $hit->{recid}->[0]; + my $work_title = $hit->{'md-work-title'}->[0]; - #if ($recid =~ /[\200-\377]/) { - if ($recid =~ /sodot/) { - #die "bad $recid\n"; - #probably do not want non-ASCII in record ID - last HIT; + my $work_author; + if (exists $hit->{'md-work-author'}) { + $work_author = $hit->{'md-work-author'}->[0]; } + my $group_label = (defined $work_author) ? "$work_title / $work_author" : $work_title; + + my $result_group = {}; + $result_group->{'group_label'} = $group_label; + $result_group->{'group_merge_key'} = $recid; + my $count = 1; if (exists $hit->{count}) { $count = $hit->{count}->[0]; } - #die $count; + $result_group->{'group_count'} = $count; + for (my $i = 0; $i < $count; $i++) { - warn "look for $recid offset = $i"; + # FIXME -- may need to worry about diacritics here my $rec = $paz->record($recid, $i); - warn "got record $i"; - push @{ $results_hashref->{'biblioserver'}->{$work_title}->{'RECORDS'} }, $paz->record($recid, $i); + push @{ $result_group->{'RECORDS'} }, $paz->record($recid, $i); } + + push @{ $results_hashref->{'biblioserver'}->{'GROUPS'} }, $result_group; } - warn "past hits"; # pass through facets my $termlist_xml = $paz->termlist('author,subject'); diff --git a/C4/Search/PazPar2.pm b/C4/Search/PazPar2.pm index f543c96d10..52191f04f6 100644 --- a/C4/Search/PazPar2.pm +++ b/C4/Search/PazPar2.pm @@ -102,6 +102,7 @@ sub show { my $self = shift; my $start = shift; my $count = shift; + my $sort = shift; my $uri = URI->new($self->{'endpoint'}); $uri->query_param(command => 'show'); @@ -109,6 +110,7 @@ sub show { $uri->query_param(num => $count); $uri->query_param(block => 1); $uri->query_param(session => $self->{'session'}); + $uri->query_param(sort => $sort); my $response = $self->{'ua'}->get($uri); if ($response->is_success) { return $response->content; diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 30dc8a1542..a3d326f70d 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -26,7 +26,12 @@ my ($template,$borrowernumber,$cookie); my $template_name; my $template_type; my @params = $cgi->param("limit"); -if ((@params>=1) || ($cgi->param("q")) || ($cgi->param('multibranchlimit')) || ($cgi->param('limit-yr')) ) { + +my $build_grouped_results = C4::Context->preference('OPACGroupResults'); +if ($build_grouped_results) { + $template_name = 'opac-results-grouped.tmpl'; +} +elsif ((@params>=1) || ($cgi->param("q")) || ($cgi->param('multibranchlimit')) || ($cgi->param('limit-yr')) ) { $template_name = 'opac-results.tmpl'; } else { @@ -304,10 +309,14 @@ if (C4::Context->preference('NoZebra')) { eval { ($error, $results_hashref, $facets) = NZgetRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan); }; -} else { +} elsif ($build_grouped_results) { eval { ($error, $results_hashref, $facets) = C4::Search::pazGetRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan); }; +} else { + eval { + ($error, $results_hashref, $facets) = getRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan); + }; } if ($@ || $error) { $template->param(query_error => $error.$@); @@ -324,9 +333,14 @@ for (my $i=0;$i<=@servers;$i++) { $hits = $results_hashref->{$server}->{"hits"}; my $page = $cgi->param('page') || 0; my @newresults; - for my $work_title (keys %{ $results_hashref->{$server} }) { - next if $work_title eq "hits"; - push @newresults, searchResults( $query_desc,$hits,$results_per_page,$offset,@{$results_hashref->{$server}->{$work_title}->{"RECORDS"}}); + if ($build_grouped_results) { + foreach my $group (@{ $results_hashref->{$server}->{"GROUPS"} }) { + my @group_results = searchResults( $query_desc, $group->{'group_count'},$results_per_page,$offset, + @{ $group->{"RECORDS"} }); + push @newresults, { group_label => $group->{'group_label'}, GROUP_RESULTS => \@group_results }; + } + } else { + @newresults = searchResults( $query_desc,$hits,$results_per_page,$offset,@{$results_hashref->{$server}->{"RECORDS"}}); } $total = $total + $results_hashref->{$server}->{"hits"}; if ($hits) { -- 2.39.5