From f3a2fbdae3a78744307133ea3bf483688c7e9b04 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Fri, 23 Oct 2015 16:09:03 +0200 Subject: [PATCH] Bug 15054 - Get items from database instead of search engine in search results Since OPAC uses the XSLT, the items displayed in search results does not come from search engine results anymore (see C4::XSLT::buildKohaItemsNamespace), they come from database table items. At intranet, the search results page, even when XSLT is used, displays items in left column and they come from search engine result. This enh proposes to get items from database. The big advantage is that item status display does not relay on indexing anymore. When checking in or out, the effect in search results is instantaneous, same for item defined as lost, damaged, ... Test plan : - Disable zebraqueue indexing (rebuild_zebra -z) - Perform a search - Choose a result with an item available for loan - Perform a checkout on this item - Re-perform a search => Without patch you see the item still available => With patch you see the item on loan - Test also with checkin --- C4/Search.pm | 53 ++++++++++++----------------------------------------- 1 file changed, 12 insertions(+), 41 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index e0f34bf..e62887b 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -20,6 +20,7 @@ use strict; require Exporter; use C4::Context; use C4::Biblio; # GetMarcFromKohaField, GetBiblioData +use C4::Items; use C4::Koha; # getFacets use Lingua::Stem; use C4::Search::PazPar2; @@ -1933,11 +1934,11 @@ sub searchResults { } } - my $fw = $scan - ? undef - : $bibliotag < 10 - ? GetFrameworkCode($marcrecord->field($bibliotag)->data) - : GetFrameworkCode($marcrecord->subfield($bibliotag,$bibliosubf)); + my $biblionumber = + ( $bibliotag < 10 ) + ? $marcrecord->field($bibliotag)->data + : $marcrecord->subfield( $bibliotag, $bibliosubf ); + my $fw = $scan ? undef : GetFrameworkCode($biblionumber); SetUTF8Flag($marcrecord); my $oldbiblio = TransformMarcToKoha( $dbh, $marcrecord, $fw ); @@ -1961,7 +1962,6 @@ sub searchResults { # FIXME: is this used anywhere, I think it can be commented out? -- JF if ( $itemtypes{ $oldbiblio->{itemtype} }->{summary} ) { my $summary = $itemtypes{ $oldbiblio->{itemtype} }->{summary}; - my @fields = $marcrecord->fields(); my $newsummary; foreach my $line ( "$summary\n" =~ /(.*)\n/g ){ @@ -2003,34 +2003,10 @@ sub searchResults { } # Pull out the items fields - my @fields = $marcrecord->field($itemtag); - my $marcflavor = C4::Context->preference("marcflavour"); - # adding linked items that belong to host records - my $analyticsfield = '773'; - if ($marcflavor eq 'MARC21' || $marcflavor eq 'NORMARC') { - $analyticsfield = '773'; - } elsif ($marcflavor eq 'UNIMARC') { - $analyticsfield = '461'; - } - foreach my $hostfield ( $marcrecord->field($analyticsfield)) { - my $hostbiblionumber = $hostfield->subfield("0"); - my $linkeditemnumber = $hostfield->subfield("9"); - if(!$hostbiblionumber eq undef){ - my $hostbiblio = GetMarcBiblio($hostbiblionumber, 1); - my ($itemfield, undef) = GetMarcFromKohaField( 'items.itemnumber', GetFrameworkCode($hostbiblionumber) ); - if(!$hostbiblio eq undef){ - my @hostitems = $hostbiblio->field($itemfield); - foreach my $hostitem (@hostitems){ - if ($hostitem->subfield("9") eq $linkeditemnumber){ - my $linkeditem =$hostitem; - # append linked items if they exist - if (!$linkeditem eq undef){ - push (@fields, $linkeditem);} - } - } - } - } - } + my @items = GetItemsInfo($biblionumber); + # adding items linked via host biblios + my @hostitems = GetHostItemsInfo($marcrecord); + push ( @items, @hostitems ); # Setting item statuses for display my @available_items_loop; @@ -2055,19 +2031,14 @@ sub searchResults { my $can_place_holds = 0; my $item_onhold_count = 0; my $notforloan_count = 0; - my $items_count = scalar(@fields); + my $items_count = scalar(@items); my $maxitems_pref = C4::Context->preference('maxItemsinSearchResults'); my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1; my @hiddenitems; # hidden itemnumbers based on OpacHiddenItems syspref # loop through every item - foreach my $field (@fields) { - my $item; + foreach my $item (@items) { - # populate the items hash - foreach my $code ( keys %subfieldstosearch ) { - $item->{$code} = $field->subfield( $subfieldstosearch{$code} ); - } $item->{description} = $itemtypes{ $item->{itype} }{description}; # OPAC hidden items -- 2.1.0