);
}
+sub _auth_build_query {
+ my ( $pars ) = @_;
+
+ my $nameany= $pars->{nameany};
+ my $authorany= $pars->{authorany};
+ my $authorpersonal= $pars->{authorpersonal};
+ my $authorcorp= $pars->{authorcorp};
+ my $authormeetingcon= $pars->{authormeetingcon};
+ my $title= $pars->{title};
+ my $uniformtitle= $pars->{uniformtitle};
+ my $subject= $pars->{subject};
+ my $subjectsubdiv= $pars->{subjectsubdiv};
+ my $srchany= $pars->{srchany};
+ my $authid= $pars->{authid};
+
+ my $qry_build = {
+ nameany => '@attr 1=1002 "#term" ',
+ authorany => '@attr 1=1003 "#term" ',
+ authorcorp => '@attr 1=2 "#term" ',
+ authorpersonal => '@attr 1=1 "#term" ',
+ authormeetingcon => '@attr 1=3 "#term" ',
+ subject => '@attr 1=21 "#term" ',
+ subjectsubdiv => '@attr 1=47 "#term" ',
+ title => '@attr 1=4 "#term" ',
+ uniformtitle => '@attr 1=6 "#term" ',
+ srchany => '@attr 1=1016 "#term" ',
+ };
+
+ my $zquery='';
+ my $squery='';
+ my $nterms=0;
+ foreach my $k ( sort keys %$pars ) {
+ #note that the sort keys forces an identical result under Perl 5.18
+ #one of the unit tests is based on that assumption
+ if( ( my $val=$pars->{$k} ) && $qry_build->{$k} ) {
+ $qry_build->{$k} =~ s/#term/$val/g;
+ $zquery .= $qry_build->{$k};
+ $squery .= "[$k]=\"$val\" and ";
+ $nterms++;
+ }
+ }
+ $zquery = "\@and " . $zquery for 2..$nterms;
+ $squery =~ s/ and $//;
+ return ( $zquery, $squery );
+
+}
+
sub _build_query {
my ( $pars ) = @_;
my $raw= $zoomrec->raw();
my $marcrecord;
if( $servhref->{servertype} eq 'sru' ) {
- $marcrecord= MARC::Record->new_from_xml( $raw, 'UTF-8',
- $servhref->{syntax} );
- } else {
- ($marcrecord) = MarcToUTF8Record($raw, C4::Context->preference('marcflavour'), $servhref->{encoding} // "iso-5426" ); #ignores charset return values
+ $raw= MARC::Record->new_from_xml( $raw, $servhref->{encoding}, $servhref->{syntax} );
}
+ ($marcrecord) = MarcToUTF8Record($raw, C4::Context->preference('marcflavour'), $servhref->{encoding} // "iso-5426" ); #ignores charset return values
SetUTF8Flag($marcrecord);
my $error;
( $marcrecord, $error ) = _do_xslt_proc($marcrecord, $servhref, $xslh);
$option1->option( 'user', $server->{userid} ) if $server->{userid};
$option1->option( 'password', $server->{password} ) if $server->{password};
}
-
my $obj= ZOOM::Connection->create($option1);
if( $server->{servertype} eq 'sru' ) {
my $host= $server->{host};
=head2 ImportBreedingAuth
-ImportBreedingAuth($marcrecords,$overwrite_auth,$filename,$encoding,$z3950random,$batch_type);
+ImportBreedingAuth($marcrecords,$overwrite_auth,$filename,$encoding,$z3950random);
ImportBreedingAuth imports MARC records in the reservoir (import_records table).
ImportBreedingAuth is based on the ImportBreeding subroutine.
=cut
sub ImportBreedingAuth {
- my ($marcrecords,$overwrite_auth,$filename,$encoding,$z3950random,$batch_type) = @_;
- my @marcarray = split /\x1D/, $marcrecords;
-
+ my ($marcrecord,$overwrite_auth,$filename,$encoding,$z3950random) = @_;
my $dbh = C4::Context->dbh;
my $batch_id = GetZ3950BatchId($filename);
my $alreadyinfarm = 0;
my $notmarcrecord = 0;
my $breedingid;
- for (my $i=0;$i<=$#marcarray;$i++) {
- my ($marcrecord, $charset_result, $charset_errors);
- ($marcrecord, $charset_result, $charset_errors) =
- MarcToUTF8Record($marcarray[$i]."\x1D", $marc_type, $encoding);
# Normalize the record so it doesn't have separated diacritics
SetUTF8Flag($marcrecord);
}
}
}
- }
return ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported,$breedingid);
}
my $random= $pars->{random};
my $page= $pars->{page};
- my $nameany= $pars->{nameany};
- my $authorany= $pars->{authorany};
- my $authorpersonal= $pars->{authorpersonal};
- my $authorcorp= $pars->{authorcorp};
- my $authormeetingcon= $pars->{authormeetingcon};
- my $title= $pars->{title};
- my $uniformtitle= $pars->{uniformtitle};
- my $subject= $pars->{subject};
- my $subjectsubdiv= $pars->{subjectsubdiv};
- my $srchany= $pars->{srchany};
- my $authid= $pars->{authid};
my $show_next = 0;
my $total_pages = 0;
my $count;
my $record;
my @serverhost;
- my @servername;
my @breeding_loop = ();
my @oConnection;
my @oResult;
my @errconn;
+ my @servers;
my $s = 0;
my $query;
my $nterms=0;
my $marcflavour = C4::Context->preference('marcflavour');
my $marc_type = $marcflavour eq 'UNIMARC' ? 'UNIMARCAUTH' : $marcflavour;
-
- if ($nameany) {
- $query .= " \@attr 1=1002 \"$nameany\" "; #Any name (this includes personal, corporate, meeting/conference authors, and author names in subject headings)
- #This attribute is supported by both the Library of Congress and Libraries Australia 08/05/2013
- $nterms++;
- }
-
- if ($authorany) {
- $query .= " \@attr 1=1003 \"$authorany\" "; #Author-name (this includes personal, corporate, meeting/conference authors, but not author names in subject headings)
- #This attribute is not supported by the Library of Congress, but is supported by Libraries Australia 08/05/2013
- $nterms++;
- }
-
- if ($authorcorp) {
- $query .= " \@attr 1=2 \"$authorcorp\" "; #1005 is another valid corporate author attribute...
- $nterms++;
- }
-
- if ($authorpersonal) {
- $query .= " \@attr 1=1 \"$authorpersonal\" "; #1004 is another valid personal name attribute...
- $nterms++;
- }
-
- if ($authormeetingcon) {
- $query .= " \@attr 1=3 \"$authormeetingcon\" "; #1006 is another valid meeting/conference name attribute...
- $nterms++;
- }
-
- if ($subject) {
- $query .= " \@attr 1=21 \"$subject\" ";
- $nterms++;
- }
-
- if ($subjectsubdiv) {
- $query .= " \@attr 1=47 \"$subjectsubdiv\" ";
- $nterms++;
- }
-
- if ($title) {
- $query .= " \@attr 1=4 \"$title\" "; #This is a regular title search. 1=6 will give just uniform titles
- $nterms++;
- }
-
- if ($uniformtitle) {
- $query .= " \@attr 1=6 \"$uniformtitle\" "; #This is the uniform title search
- $nterms++;
- }
-
- if($srchany) {
- $query .= " \@attr 1=1016 \"$srchany\" ";
- $nterms++;
- }
-
- for my $i (1..$nterms-1) {
- $query = "\@and " . $query;
- }
-
+ my $authid= $pars->{authid};
+ my ( $zquery, $squery ) = _auth_build_query( $pars );
foreach my $servid (@id) {
my $sth = $dbh->prepare("select * from z3950servers where id=?");
$sth->execute($servid);
while ( $server = $sth->fetchrow_hashref ) {
- my $option1 = new ZOOM::Options();
- $option1->option( 'async' => 1 );
- $option1->option( 'elementSetName', 'F' );
- $option1->option( 'databaseName', $server->{db} );
- $option1->option( 'user', $server->{userid} ) if $server->{userid};
- $option1->option( 'password', $server->{password} ) if $server->{password};
- $option1->option( 'preferredRecordSyntax', $server->{syntax} );
- $option1->option( 'timeout', $server->{timeout} ) if $server->{timeout};
- $oConnection[$s] = create ZOOM::Connection($option1);
- $oConnection[$s]->connect( $server->{host}, $server->{port} );
- $serverhost[$s] = $server->{host};
- $servername[$s] = $server->{servername};
+ $oConnection[$s] = _create_connection( $server );
+
+ $oResult[$s] =
+ $server->{servertype} eq 'zed'?
+ $oConnection[$s]->search_pqf( $zquery ):
+ $oConnection[$s]->search(new ZOOM::Query::CQL(
+ _translate_query( $server, $squery )));
$encoding[$s] = ($server->{encoding}?$server->{encoding}:"iso-5426");
+ $servers[$s] = $server;
$s++;
- } ## while fetch
+ } ## while fetch
} # foreach
my $nremaining = $s;
- for ( my $z = 0 ; $z < $s ; $z++ ) {
- $oResult[$z] = $oConnection[$z]->search_pqf($query);
- }
-
while ( $nremaining-- ) {
my $k;
my $event;
$marcdata = $rec->raw();
my ($charset_result, $charset_errors);
+ if( $servers[$k]->{servertype} eq 'sru' ) {
+ $marcdata = MARC::Record->new_from_xml( $marcdata, $encoding[$k], $servers[$k]->{syntax} );
+ }
($marcrecord, $charset_result, $charset_errors)= MarcToUTF8Record($marcdata, $marc_type, $encoding[$k]);
-
my $heading;
my $heading_authtype_code;
$heading_authtype_code = GuessAuthTypeCode($marcrecord);
$heading = C4::AuthoritiesMarc::GetAuthorizedHeading({ record => $marcrecord });
- my ($notmarcrecord, $alreadyindb, $alreadyinfarm, $imported, $breedingid)= ImportBreedingAuth( $marcdata, 2, $serverhost[$k], $encoding[$k], $random, 'z3950' );
+ my ($notmarcrecord, $alreadyindb, $alreadyinfarm, $imported, $breedingid)= ImportBreedingAuth( $marcrecord, 2, $serverhost[$k], $encoding[$k], $random);
my %row_data;
- $row_data{server} = $servername[$k];
+ $row_data{server} = $servers[$k]->{'servername'};
$row_data{breedingid} = $breedingid;
$row_data{heading} = $heading;
$row_data{authid} = $authid;
push( @breeding_loop, \%row_data );
}
else {
- push(@breeding_loop,{'server'=>$servername[$k],'title'=>join(': ',$oConnection[$k]->error_x()),'breedingid'=>-1,'authid'=>-1});
+ push(@breeding_loop,{'server'=>$servers[$k]->{'servername'},'title'=>join(': ',$oConnection[$k]->error_x()),'breedingid'=>-1,'authid'=>-1});
}
}
} #if $numresults
$oConnection[$_]->destroy();
}
- my @servers = ();
+ @servers = ();
foreach my $id (@id) {
push @servers, {id => $id};
}
--- /dev/null
+[% INCLUDE 'doc-head-open.inc' %]
+<title>Koha › SRU search fields mapping for authorities</title>
+[% INCLUDE 'doc-head-close.inc' %]
+
+<script type="text/javascript">
+//<![CDATA[
+ $(document).ready(function() {
+ $("#form01").submit(function(event) {
+ if(window.opener) {
+ var newmap=allInputs();
+ window.opener.$('#show_sru_fields').val(newmap);
+ window.close();
+ } else {
+ // In this case not called as a popup. Just do nothing.
+ event.preventDefault();
+ }
+ });
+ });
+ function allInputs () {
+ var aInput= new Array();
+ $("form :input").each(function() {
+ if( this.id && $(this).val() ) {
+ aInput.push(this.id+'='+$(this).val());
+ }
+ });
+ return aInput.join(',');
+ }
+//]]>
+</script>
+</head>
+
+<body id="admin_sru_modmapping" class="admin">
+
+<div id="custom-doc" class="yui-t7">
+
+ <div id="bd">
+ <h1>Modify SRU search fields mapping for authorities</h1>
+ <form id="form01" method="post">
+ <fieldset class="rows">
+ <div class="yui-g">
+ <div class="yui-u first">
+ <ol>
+ <li>
+ <label for="srchany">Keyword (any): </label>
+ <input id="srchany" type="text" value="[% FILTER html %][% mapping.srchany %][% END %]" />
+ </li>
+ <li>
+ <label for="nameany">Name (any): </label>
+ <input id="nameany" type="text" value="[% FILTER html %][% mapping.nameany %][% END %]" />
+ </li>
+ <li>
+ <label for="authorany">Author (any): </label>
+ <input id="authorany" type="text" value="[% FILTER html %][% mapping.authorany %][% END %]" />
+ </li>
+ <li>
+ <label for="authorpersonal">Author (personal): </label>
+ <input id="authorpersonal" type="text" value="[% FILTER html %][% mapping.authorpersonal %][% END %]" />
+ </li>
+ <li>
+ <label for="authorcorp">Author (corporate): </label>
+ <input id="authorcorp" type="text" value="[% FILTER html %][% mapping.authorcorp %][% END %]" />
+ </li>
+ <li>
+ <label for="authormeetingcon">Author (meeting/conference): </label>
+ <input id="authormeetingcon" type="text" value="[% FILTER html %][% mapping.authormeetingcon %][% END %]" />
+ </li>
+ </ol>
+ </div>
+ <div class="yui-u">
+ <ol>
+ <li>
+ <label for="subject">Subject heading: </label>
+ <input id="subject" type="text" value="[% FILTER html %][% mapping.subject %][% END %]" />
+ </li>
+ <li>
+ <label for="subjectsubdiv">Subject sub-division: </label>
+ <input id="subjectsubdiv" type="text" value="[% FILTER html %][% mapping.subjectsubdiv %][% END %]" />
+ </li>
+ <li>
+ <label for="title">Title (any): </label>
+ <input id="title" type="text" value="[% FILTER html %][% mapping.title %][% END %]" />
+ </li>
+ <li>
+ <label for="uniformtitle">Title (uniform): </label>
+ <input id="uniformtitle" type="text" value="[% FILTER html %][% mapping.uniformtitle %][% END %]" />
+ </li>
+ </ol>
+ </div>
+ </div>
+ </fieldset>
+ <fieldset class="action">
+ <input type="submit" value="Save" class="submit" />
+ <a class="close cancel" href="#">Cancel</a>
+ </fieldset>
+ </form>
+ </div>
+
+[% INCLUDE 'intranet-bottom.inc' %]