1 package Koha::Util::Search;
3 # Copyright 2020 University of Helsinki
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
26 Koha::Util::Search - functions to build complex search queries
30 =head2 get_component_part_query
32 Returns a query which can be used to search for all component parts of MARC21 biblios
36 sub get_component_part_query {
37 my ($biblionumber) = @_;
39 my $marc = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber });
40 my $pf001 = $marc->field('001') || undef;
42 if (defined($pf001)) {
43 my $pf003 = $marc->field('003') || undef;
46 if (!defined($pf003)) {
47 # search for 773$w='Host001'
48 $searchstr = "rcn='".$pf001->data()."'";
50 # search for (773$w='Host001' and 003='Host003') or 773$w='Host003 Host001')
51 $searchstr = "(rcn='".$pf001->data()."' AND cni='".$pf003->data()."')";
52 $searchstr .= " OR rcn='".$pf003->data()." ".$pf001->data()."'";