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>.
22 use C4::Biblio qw( GetMarcBiblio );
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 = GetMarcBiblio( { biblionumber => $biblionumber } );
42 if ( C4::Context->preference('UseControlNumber') ) {
43 my $pf001 = $marc->field('001') || undef;
45 if ( defined($pf001) ) {
46 my $pf003 = $marc->field('003') || undef;
48 if ( !defined($pf003) ) {
49 # search for 773$w='Host001'
50 $searchstr = "rcn:" . $pf001->data();
54 # search for (773$w='Host001' and 003='Host003') or 773$w='Host003 Host001')
55 $searchstr .= "(rcn:" . $pf001->data() . " AND cni:" . $pf003->data() . ")";
56 $searchstr .= " OR rcn:" . $pf003->data() . " " . $pf001->data();
60 # limit to monograph and serial component part records
61 $searchstr .= " AND (bib-level:a OR bib-level:b)";
65 my $cleaned_title = $marc->title;
66 $cleaned_title =~ tr|/||;
67 $searchstr = "Host-item:($cleaned_title)";