use C4::AuthoritiesMarc::MARC21;
use C4::AuthoritiesMarc::UNIMARC;
use C4::Charset;
+use C4::Debug;
use vars qw($VERSION @ISA @EXPORT);
sub SearchAuthorities {
my ($tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode,$sortby) = @_;
- #use Data::Dumper; map {warn "CALL : ".Data::Dumper::Dumper($_);} @_;
+# warn "CALL : $tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode,$sortby";
my $dbh=C4::Context->dbh;
if (C4::Context->preference('NoZebra')) {
my $n=0;
my @authtypecode;
my @auths=split / /,$authtypecode ;
+ my @queries;
foreach my $auth (@auths){
- $query .=" \@attr 1=authtype \@attr 5=100 ".$auth; ##No truncation on authtype
+ push @queries, " \@attr 1=authtype \@attr 5=100 ".$auth; ##No truncation on authtype
push @authtypecode ,$auth;
$n++;
}
while ($n>1){$query= "\@or ".$query;$n--;}
}
+ my $dosearch;
my $and=" \@and " ;
- my $q2="";
for(my $i = 0 ; $i <= $#{$value} ; $i++)
{
if (@$value[$i]){
##If mainentry search $a tag
if (@$tags[$i] eq "mainmainentry") {
- $attr =" \@attr 1=Heading-Main ";
+
+ $attr =" \@attr 1=Heading-Main ";
+# $attr =" \@attr 1=Heading ";
+
}elsif (@$tags[$i] eq "mainentry") {
$attr =" \@attr 1=Heading ";
}else{
$attr .=" \@attr 5=1 \@attr 4=6 ";## Word list, right truncated, anywhere
}
$attr =$attr."\"".@$value[$i]."\"";
- $q2 =($q2 ne "" ?$and.$q2.$attr:$attr);
+ push @queries, "$attr";
+ $dosearch=1;
}#if value
}
##Add how many queries generated
- if ($query=~/\S+/ && $q2 ne ""){
- $query= $and.$query.$q2;
- }
- elsif ($q2 ne "") {
- $query=$q2;
- }
+ $query='';
+ foreach my $query_part (@queries){
+ $query=($query?$and.$query_part.$query:$query_part);
+ }
## Adding order
#$query=' @or @attr 7=2 @attr 1=Heading 0 @or @attr 7=1 @attr 1=Heading 1'.$query if ($sortby eq "HeadingDsc");
my $orderstring= ($sortby eq "HeadingAsc"?
'@attr 7=2 @attr 1=Heading 0'
:''
);
- my $allrecords=" \@attr 1=_ALLRECORDS \@attr 2=103 '' ";
- $query=($q2?"\@or $orderstring $query":"\@or $orderstring ".($query?"\@and $allrecords $query":$allrecords) );
+ $query=($dosearch?"\@or $orderstring $query":"\@or ".($query?"$and $query":"")." \@attr 1=_ALLRECORDS \@attr 2=103 '' $orderstring ");
+ $debug && warn $query;
$offset=0 unless $offset;
my $counter = $offset;
# pass the MARC::Record to this function, and it will create the records in the authority table
my ($record,$authid,$authtypecode) = @_;
my $dbh=C4::Context->dbh;
- my $leader=' nz a22 o 4500';#Leader for incomplete MARC21 record
+ my $leader=' nz a22 o 4500';#Leader for incomplete MARC21 record
# if authid empty => true add, find a new authid number
- my $format= 'UNIMARCAUTH' if (uc(C4::Context->preference('marcflavour')) eq 'UNIMARC');
- $format= 'MARC21' if (uc(C4::Context->preference('marcflavour')) ne 'UNIMARC');
+ my $format = uc(C4::Context->preference('marcflavour')) eq 'UNIMARC'
+ ? 'UNIMARCAUTH' : 'MARC21'
+ ;
if ($format eq "MARC21") {
if (!$record->leader) {
my $sth=$dbh->prepare("select max(authid) from auth_header");
$sth->execute;
($authid)=$sth->fetchrow;
- $authid=$authid+1;
- ##Insert the recordID in MARC record
- unless ($record->field('001') && $record->field('001')->data() eq $authid){
- $record->delete_field($record->field('001'));
- $record->insert_fields_ordered(MARC::Field->new('001',$authid));
- }
+ ( $authid ||= 0 )++; # $authid is undef for the first authority
+ ## Insert the recordID in MARC record
+ if ( my $field = $record->field('001') ) { $field->data($authid) }
+ else { $record->insert_fields_ordered(MARC::Field->new('001',$authid)) }
} else {
$auth_exists=$dbh->do(qq(select authid from auth_header where authid=?),undef,$authid);
# warn "auth_exists = $auth_exists";
sub GetAuthorityXML {
# Returns MARC::XML of the authority passed in parameter.
my ( $authid ) = @_;
- my $format= 'UNIMARCAUTH' if (uc(C4::Context->preference('marcflavour')) eq 'UNIMARC');
- $format= 'MARC21' if (uc(C4::Context->preference('marcflavour')) ne 'UNIMARC');
- if ($format eq "MARC21") {
- # for MARC21, call GetAuthority instead of
- # getting the XML directly since we may
- # need to fix up the location of the authority
- # code -- note that this is reasonably safe
- # because GetAuthorityXML is used only by the
- # indexing processes like zebraqueue_start.pl
- my $record = GetAuthority($authid);
- return $record->as_xml_record($format);
- } else {
- my $dbh=C4::Context->dbh;
- my $sth = $dbh->prepare("select marcxml from auth_header where authid=? " );
- $sth->execute($authid);
- my ($marcxml)=$sth->fetchrow;
- return $marcxml;
+ if (uc(C4::Context->preference('marcflavour')) eq 'UNIMARC') {
+ my $dbh=C4::Context->dbh;
+ my $sth = $dbh->prepare("select marcxml from auth_header where authid=? " );
+ $sth->execute($authid);
+ my ($marcxml)=$sth->fetchrow;
+ return $marcxml;
+ }
+ else {
+ # for MARC21, call GetAuthority instead of
+ # getting the XML directly since we may
+ # need to fix up the location of the authority
+ # code -- note that this is reasonably safe
+ # because GetAuthorityXML is used only by the
+ # indexing processes like zebraqueue_start.pl
+ my $record = GetAuthority($authid);
+ return $record->as_xml_record('MARC21');
}
}
$summary =~ s/\n/<br>/g;
} else {
my $heading;
- my $authid;
my $altheading;
my $seealso;
my $broaderterms;
# accepted form
foreach my $field ($record->field('2..')) {
$heading.= $field->subfield('a');
- $authid=$field->subfield('3');
}
# rejected form(s)
foreach my $field ($record->field('3..')) {
$notes.= '<span class="note">'.$field->subfield('a')."</span>\n";
}
foreach my $field ($record->field('4..')) {
- my $thesaurus = "thes. : ".$thesaurus{"$field->subfield('2')"}." : " if ($field->subfield('2'));
- $see.= '<span class="UF">'.$thesaurus.$field->subfield('a')."</span> -- \n";
+ if ($field->subfield('2')) {
+ my $thesaurus = "thes. : ".$thesaurus{"$field->subfield('2')"}." : ";
+ $see.= '<span class="UF">'.$thesaurus.$field->subfield('a')."</span> -- \n";
+ }
}
# see :
foreach my $field ($record->field('5..')) {
-
+ my $authid=_get_authid_subfield($field);
if (($field->subfield('5')) && ($field->subfield('a')) && ($field->subfield('5') eq 'g')) {
- $broaderterms.= '<span class="BT"> <a href="detail.pl?authid='.$field->subfield('3').'">'.$field->subfield('a')."</a></span> -- \n";
+ $broaderterms.= '<span class="BT"> <a href="detail.pl?authid='.$authid.'">'.$field->subfield('a')."</a></span> -- \n";
} elsif (($field->subfield('5')) && ($field->subfield('a')) && ($field->subfield('5') eq 'h')){
- $narrowerterms.= '<span class="NT"><a href="detail.pl?authid='.$field->subfield('3').'">'.$field->subfield('a')."</a></span> -- \n";
+ $narrowerterms.= '<span class="NT"><a href="detail.pl?authid='.$authid.'">'.$field->subfield('a')."</a></span> -- \n";
} elsif ($field->subfield('a')) {
- $seealso.= '<span class="RT"><a href="detail.pl?authid='.$field->subfield('3').'">'.$field->subfield('a')."</a></span> -- \n";
+ $seealso.= '<span class="RT"><a href="detail.pl?authid='.$authid.'">'.$field->subfield('a')."</a></span> -- \n";
}
}
# // form
return $summary;
}
+sub _get_authid_subfield{
+ my ($field)=@_;
+ return $field->subfield('9')||$field->subfield('3');
+}
=head2 BuildUnimarcHierarchies
=over 4
my $data = GetHeaderAuthority($authid);
if ($data->{'authtrees'} and not $force){
return $data->{'authtrees'};
- } elsif ($data->{'authtrees'}){
- $hierarchies=$data->{'authtrees'};
+# } elsif ($data->{'authtrees'}){
+# $hierarchies=$data->{'authtrees'};
} else {
my $record = GetAuthority($authid);
my $found;
- foreach my $field ($record->field('550')){
+ return unless $record;
+ foreach my $field ($record->field('5..')){
if ($field->subfield('5') && $field->subfield('5') eq 'g'){
- my $parentrecord = GetAuthority($field->subfield('3'));
+ my $subfauthid=_get_authid_subfield($field);
+ my $parentrecord = GetAuthority($subfauthid);
my $localresult=$hierarchies;
my $trees;
- $trees = BuildUnimarcHierarchies($field->subfield('3'));
+ $trees = BuildUnimarcHierarchies($subfauthid);
my @trees;
if ($trees=~/;/){
@trees = split(/;/,$trees);
}
#Unless there is no ancestor, I am alone.
$hierarchies="$authid" unless ($hierarchies);
- }
+ }
AddAuthorityTrees($authid,$hierarchies);
return $hierarchies;
}
my $record = shift @_;
my $class = shift @_;
my $authid_constructed = shift @_;
- my $authid=$record->subfield('250','3');
+ return unless $record;
+ my $authid=$record->field('001')->data();
my %cell;
my $parents=""; my $children="";
my (@loopparents,@loopchildren);
- foreach my $field ($record->field('550')){
+ foreach my $field ($record->field('5..')){
+ my $subfauthid=_get_authid_subfield($field);
if ($field->subfield('5') && $field->subfield('a')){
if ($field->subfield('5') eq 'h'){
- push @loopchildren, { "childauthid"=>$field->subfield('3'),"childvalue"=>$field->subfield('a')};
+ push @loopchildren, { "childauthid"=>$subfauthid,"childvalue"=>$field->subfield('a')};
}elsif ($field->subfield('5') eq 'g'){
- push @loopparents, { "parentauthid"=>$field->subfield('3'),"parentvalue"=>$field->subfield('a')};
+ push @loopparents, { "parentauthid"=>$subfauthid,"parentvalue"=>$field->subfield('a')};
}
# brothers could get in there with an else
}
$cell{"class"}=$class;
$cell{"loopauthid"}=$authid;
$cell{"current_value"} =1 if $authid eq $authid_constructed;
- $cell{"value"}=$record->subfield('250',"a");
+ $cell{"value"}=$record->subfield('2..',"a");
return \%cell;
}
while (my $biblionumbers=$rq->fetchrow){
my @biblionumbers=split /;/,$biblionumbers;
foreach (@biblionumbers) {
- my $biblionumber=$1 if ($_=~/(\d+),.*/);
- my $marc=GetMarcBiblio($biblionumber);
- push @reccache,$marc;
+ if ($_=~/(\d+),.*/) {
+ my $marc=GetMarcBiblio($1);
+ push @reccache,$marc;
+ }
}
}
} else {
my $query;
$query= "an=".$mergefrom;
my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection ));
- my $count=$oResult->size() if ($oResult);
+ my $count = 0;
+ if ($oResult) {
+ $count=$oResult->size();
+ }
my $z=0;
while ( $z<$count ) {
my $rec;
$rec=$oResult->record($z);
my $marcdata = $rec->raw();
push @reccache, $marcdata;
- $z++;
+ $z++;
}
$oConnection->destroy();
}