View | Details | Raw Unified | Return to bug 11096
Collapse All | Expand All

(-)a/C4/AuthoritiesMarc.pm (-4 / +16 lines)
Lines 267-276 sub SearchAuthorities { Link Here
267
        ##Here we have to extract MARC record and $authid from ZEBRA AUTHORITIES
267
        ##Here we have to extract MARC record and $authid from ZEBRA AUTHORITIES
268
        my $rec=$oAResult->record($counter);
268
        my $rec=$oAResult->record($counter);
269
        my $separator=C4::Context->preference('authoritysep');
269
        my $separator=C4::Context->preference('authoritysep');
270
        my $authrecord = MARC::Record->new_from_xml(
270
        my $authrecord = eval {
271
            $rec->raw(),
271
            if (C4::Context->config('zebra_auth_index_mode') eq 'dom') {
272
            'UTF-8'
272
                MARC::Record->new_from_xml(
273
        );
273
                  $rec->raw(),
274
                  'UTF-8'
275
                );
276
            } else {
277
                MARC::Record->new_from_usmarc($rec->raw());
278
            }
279
        };
280
281
        if ( !defined $authrecord or !defined $authrecord->field('001') ) {
282
            $counter++;
283
            next;
284
        }
285
274
        my $authid=$authrecord->field('001')->data();
286
        my $authid=$authrecord->field('001')->data();
275
        my %newline;
287
        my %newline;
276
        $newline{authid} = $authid;
288
        $newline{authid} = $authid;
(-)a/C4/Context.pm (-19 / +17 lines)
Lines 729-742 sub _new_Zconn { Link Here
729
729
730
    my $tried=0; # first attempt
730
    my $tried=0; # first attempt
731
    my $Zconn; # connection object
731
    my $Zconn; # connection object
732
    my $elementSetName;
733
732
    $server //= "biblioserver";
734
    $server //= "biblioserver";
733
    $syntax //= "XML";
735
    $syntax //= "XML";
734
736
737
    if ( ($server eq 'biblioserver' and $context->{'config'}->{'zebra_bib_index_mode'} eq 'grs1')
738
        or ($server eq 'authorityserver' and $context->{'config'}->{'zebra_auth_index_mode'} eq 'grs1')) {
739
740
        $elementSetName = 'F';
741
        $syntax = 'usmarc';
742
743
    } else {
744
745
        $elementSetName = 'marcxml';
746
        $syntax = 'XML';
747
    }
748
735
    my $host = $context->{'listen'}->{$server}->{'content'};
749
    my $host = $context->{'listen'}->{$server}->{'content'};
736
    my $servername = $context->{"config"}->{$server};
750
    my $servername = $context->{"config"}->{$server};
737
    my $user = $context->{"serverinfo"}->{$server}->{"user"};
751
    my $user = $context->{"serverinfo"}->{$server}->{"user"};
738
    my $password = $context->{"serverinfo"}->{$server}->{"password"};
752
    my $password = $context->{"serverinfo"}->{$server}->{"password"};
739
 $auth = 1 if($user && $password);   
753
    $auth = 1 if($user && $password);
740
    retry:
754
    retry:
741
    eval {
755
    eval {
742
        # set options
756
        # set options
Lines 748-754 sub _new_Zconn { Link Here
748
        $o->option(cqlfile=> $context->{"server"}->{$server}->{"cql2rpn"});
762
        $o->option(cqlfile=> $context->{"server"}->{$server}->{"cql2rpn"});
749
        $o->option(cclfile=> $context->{"serverinfo"}->{$server}->{"ccl2rpn"});
763
        $o->option(cclfile=> $context->{"serverinfo"}->{$server}->{"ccl2rpn"});
750
        $o->option(preferredRecordSyntax => $syntax);
764
        $o->option(preferredRecordSyntax => $syntax);
751
        $o->option(elementSetName => "marcxml");
765
        $o->option(elementSetName => $elementSetName);
752
        $o->option(databaseName => ($servername?$servername:"biblios"));
766
        $o->option(databaseName => ($servername?$servername:"biblios"));
753
767
754
        # create a new connection object
768
        # create a new connection object
Lines 763-785 sub _new_Zconn { Link Here
763
        }
777
        }
764
778
765
    };
779
    };
766
#     if ($@) {
780
767
#         # Koha manages the Zebra server -- this doesn't work currently for me because of permissions issues
768
#         # Also, I'm skeptical about whether it's the best approach
769
#         warn "problem with Zebra";
770
#         if ( C4::Context->preference("ManageZebra") ) {
771
#             if ($@->code==10000 && $tried==0) { ##No connection try restarting Zebra
772
#                 $tried=1;
773
#                 warn "trying to restart Zebra";
774
#                 my $res=system("zebrasrv -f $ENV{'KOHA_CONF'} >/koha/log/zebra-error.log");
775
#                 goto "retry";
776
#             } else {
777
#                 warn "Error ", $@->code(), ": ", $@->message(), "\n";
778
#                 $Zconn="error";
779
#                 return $Zconn;
780
#             }
781
#         }
782
#     }
783
    return $Zconn;
781
    return $Zconn;
784
}
782
}
785
783
(-)a/C4/Search.pm (-14 / +35 lines)
Lines 144-153 sub FindDuplicate { Link Here
144
    my @results;
144
    my @results;
145
    if (!defined $error) {
145
    if (!defined $error) {
146
        foreach my $possible_duplicate_record (@{$searchresults}) {
146
        foreach my $possible_duplicate_record (@{$searchresults}) {
147
            my $marcrecord = MARC::Record->new_from_xml(
147
            my $marcrecord = eval {
148
                $possible_duplicate_record,
148
                if ( C4::Context->config('zebra_bib_index_mode') eq 'dom') {
149
                'UTF-8'
149
                    MARC::Record->new_from_xml(
150
            );
150
                        $possible_duplicate_record,
151
                        'UTF-8'
152
                    );
153
                } else {
154
                    MARC::Record->new_from_usmarc(
155
                        $possible_duplicate_record
156
                    );
157
                }
158
            };
159
151
            my $result = TransformMarcToKoha( $dbh, $marcrecord, '' );
160
            my $result = TransformMarcToKoha( $dbh, $marcrecord, '' );
152
161
153
            # FIXME :: why 2 $biblionumber ?
162
            # FIXME :: why 2 $biblionumber ?
Lines 291-300 sub SimpleSearch { Link Here
291
            }
300
            }
292
301
293
            for my $j ( $first_record .. $last_record ) {
302
            for my $j ( $first_record .. $last_record ) {
294
                my $record =
303
                my $record = eval {
295
                  $tmpresults[ $i - 1 ]->record( $j - 1 )->raw()
304
                  $tmpresults[ $i - 1 ]->record( $j - 1 )->raw()
296
                  ;    # 0 indexed
305
                  ;    # 0 indexed
297
                push @{$results}, $record;
306
                };
307
                push @{$results}, $record if defined $record;
298
            }
308
            }
299
        }
309
        }
300
    );
310
    );
Lines 506-515 sub getRecords { Link Here
506
                    for my $facet (@$facets) {
516
                    for my $facet (@$facets) {
507
                        for ( my $j = 0 ; $j < $jmax ; $j++ ) {
517
                        for ( my $j = 0 ; $j < $jmax ; $j++ ) {
508
518
509
                            my $marc_record =  eval { MARC::Record->new_from_xml(
519
                            my $marc_record =  eval {
510
                                $results[ $i - 1 ]->record($j)->raw(),
520
                                if ( C4::Context->config('zebra_bib_index_mode') eq 'dom' ) {
511
                                'UTF-8'
521
                                    MARC::Record->new_from_xml(
512
                            ); };
522
                                        $results[ $i - 1 ]->record($j)->raw(),
523
                                        'UTF-8'
524
                                    );
525
                                } else {
526
                                   MARC::Record->new_from_usmarc(
527
                                        $results[ $i - 1 ]->record($j)->raw()
528
                                    );
529
                                }
530
                            };
513
531
514
                            if ( $@ ) {
532
                            if ( $@ ) {
515
                                warn "ERROR DECODING RECORD - $@: " .
533
                                warn "ERROR DECODING RECORD - $@: " .
Lines 1708-1717 sub searchResults { Link Here
1708
1726
1709
    # loop through all of the records we've retrieved
1727
    # loop through all of the records we've retrieved
1710
    for ( my $i = $offset ; $i <= $times - 1 ; $i++ ) {
1728
    for ( my $i = $offset ; $i <= $times - 1 ; $i++ ) {
1711
        my $marcrecord = eval {  MARC::Record->new_from_xml(
1729
        my $marcrecord = eval {
1712
            $marcresults->[$i],
1730
            if ( C4::Context->config('zebra_bib_index_mode') eq 'dom') {
1713
            'UTF-8'
1731
                MARC::Record->new_from_xml( $marcresults->[$i], 'UTF-8' );
1714
        ); };
1732
            } else {
1733
                MARC::Record->new_from_usmarc( $marcresults->[$i] );
1734
            }
1735
        };
1715
1736
1716
        if ( $@ ) {
1737
        if ( $@ ) {
1717
            warn "ERROR DECODING RECORD - $@: " . $marcresults->[$i];
1738
            warn "ERROR DECODING RECORD - $@: " . $marcresults->[$i];
(-)a/t/db_dependent/Search.t (-2 / +41 lines)
Lines 359-364 sub run_marc21_search_tests { Link Here
359
        getRecords('au:Lessig', 'au:Lessig', [], [ 'biblioserver' ], '20', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
359
        getRecords('au:Lessig', 'au:Lessig', [], [ 'biblioserver' ], '20', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
360
    is($results_hashref->{biblioserver}->{hits}, 4, "getRecords title search for 'Australia' matched right number of records");
360
    is($results_hashref->{biblioserver}->{hits}, 4, "getRecords title search for 'Australia' matched right number of records");
361
361
362
if ( $indexing_mode eq 'dom' ) {
362
    ( undef, $results_hashref, $facets_loop ) =
363
    ( undef, $results_hashref, $facets_loop ) =
363
        getRecords('salud', 'salud', [], [ 'biblioserver' ], '19', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
364
        getRecords('salud', 'salud', [], [ 'biblioserver' ], '19', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
364
    ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() =~ m/^Efectos del ambiente/ &&
365
    ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() =~ m/^Efectos del ambiente/ &&
Lines 393-398 sub run_marc21_search_tests { Link Here
393
        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[7],'UTF-8')->title_proper() eq 'World health statistics 2009^ien' &&
394
        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[7],'UTF-8')->title_proper() eq 'World health statistics 2009^ien' &&
394
        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() eq 'Manual de higiene industrial^ies'
395
        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() eq 'Manual de higiene industrial^ies'
395
        , "Simple descending publication date sorting in getRecords matches old behavior");
396
        , "Simple descending publication date sorting in getRecords matches old behavior");
397
398
} elsif ( $indexing_mode eq 'grs1' ){
399
    ( undef, $results_hashref, $facets_loop ) =
400
        getRecords('salud', 'salud', [], [ 'biblioserver' ], '19', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
401
    ok(MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0])->title_proper() =~ m/^Efectos del ambiente/ &&
402
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[7])->title_proper() eq 'Salud y seguridad de los trabajadores del sector salud: manual para gerentes y administradores^ies' &&
403
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[18])->title_proper() =~ m/^Indicadores de resultados identificados/
404
        , "Simple relevance sorting in getRecords matches old behavior");
405
406
    ( undef, $results_hashref, $facets_loop ) =
407
        getRecords('salud', 'salud', [ 'author_az' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
408
    ok(MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0])->title_proper() =~ m/la enfermedad laboral\^ies$/ &&
409
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[6])->title_proper() =~ m/^Indicadores de resultados identificados/ &&
410
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[18])->title_proper() eq 'World health statistics 2009^ien'
411
        , "Simple ascending author sorting in getRecords matches old behavior");
412
413
    ( undef, $results_hashref, $facets_loop ) =
414
        getRecords('salud', 'salud', [ 'author_za' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
415
    ok(MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0])->title_proper() eq 'World health statistics 2009^ien' &&
416
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[12])->title_proper() =~ m/^Indicadores de resultados identificados/ &&
417
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[18])->title_proper() =~ m/la enfermedad laboral\^ies$/
418
        , "Simple descending author sorting in getRecords matches old behavior");
419
420
    ( undef, $results_hashref, $facets_loop ) =
421
        getRecords('salud', 'salud', [ 'pubdate_asc' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
422
    ok(MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0])->title_proper() eq 'Manual de higiene industrial^ies' &&
423
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[7])->title_proper() =~ m/seguridad e higiene del trabajo\^ies$/ &&
424
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[18])->title_proper() =~ m/^Indicadores de resultados identificados/
425
        , "Simple ascending publication date sorting in getRecords matches old behavior");
426
427
    ( undef, $results_hashref, $facets_loop ) =
428
        getRecords('salud', 'salud', [ 'pubdate_dsc' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
429
    ok(MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0])->title_proper() =~ m/^Estado de salud/ &&
430
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[7])->title_proper() eq 'World health statistics 2009^ien' &&
431
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[18])->title_proper() eq 'Manual de higiene industrial^ies'
432
        , "Simple descending publication date sorting in getRecords matches old behavior");
433
}
434
396
TODO: {
435
TODO: {
397
    local $TODO = "Switch relevance search to MARCXML too";
436
    local $TODO = "Switch relevance search to MARCXML too";
398
    ( undef, $results_hashref, $facets_loop ) =
437
    ( undef, $results_hashref, $facets_loop ) =
Lines 402-407 TODO: { Link Here
402
    is($record->subfield('100', 'a'), 2, "Scan returned correct number of records matching term");
441
    is($record->subfield('100', 'a'), 2, "Scan returned correct number of records matching term");
403
    # Time to test buildQuery and searchResults too.
442
    # Time to test buildQuery and searchResults too.
404
}
443
}
444
405
    my ( $query, $simple_query, $query_cgi,
445
    my ( $query, $simple_query, $query_cgi,
406
    $query_desc, $limit, $limit_cgi, $limit_desc,
446
    $query_desc, $limit, $limit_cgi, $limit_desc,
407
    $stopwords_removed, $query_type );
447
    $stopwords_removed, $query_type );
Lines 541-547 TODO: { Link Here
541
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
581
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
542
    is($results_hashref->{biblioserver}->{hits}, 19, "Weighted query returned correct number of results");
582
    is($results_hashref->{biblioserver}->{hits}, 19, "Weighted query returned correct number of results");
543
    if ($indexing_mode eq 'grs1') {
583
    if ($indexing_mode eq 'grs1') {
544
        is(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper(), 'Salud y seguridad de los trabajadores del sector salud: manual para gerentes y administradores^ies', "Weighted query returns best match first");
584
        is(MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0])->title_proper(), 'Salud y seguridad de los trabajadores del sector salud: manual para gerentes y administradores^ies', "Weighted query returns best match first");
545
    } else {
585
    } else {
546
        local $TODO = "Query weighting does not behave exactly the same in DOM vs. GRS";
586
        local $TODO = "Query weighting does not behave exactly the same in DOM vs. GRS";
547
        is(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper(), 'Salud y seguridad de los trabajadores del sector salud: manual para gerentes y administradores^ies', "Weighted query returns best match first");
587
        is(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper(), 'Salud y seguridad de los trabajadores del sector salud: manual para gerentes y administradores^ies', "Weighted query returns best match first");
548
- 

Return to bug 11096