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

(-)a/C4/Context.pm (-5 / +3 lines)
Lines 705-712 sub Zconn { Link Here
705
        $context->{"Zconn"}->{$server}->destroy() if defined($context->{"Zconn"}->{$server});
705
        $context->{"Zconn"}->{$server}->destroy() if defined($context->{"Zconn"}->{$server});
706
706
707
        $context->{"Zconn"}->{$server} = &_new_Zconn($server,$async,$auth,$piggyback,$syntax);
707
        $context->{"Zconn"}->{$server} = &_new_Zconn($server,$async,$auth,$piggyback,$syntax);
708
        $context->{ Zconn }->{ $server }->option(
709
            preferredRecordSyntax => C4::Context->preference("marcflavour") );
710
        return $context->{"Zconn"}->{$server};
708
        return $context->{"Zconn"}->{$server};
711
    }
709
    }
712
}
710
}
Lines 730-737 sub _new_Zconn { Link Here
730
728
731
    my $tried=0; # first attempt
729
    my $tried=0; # first attempt
732
    my $Zconn; # connection object
730
    my $Zconn; # connection object
733
    $server = "biblioserver" unless $server;
731
    $server //= "biblioserver";
734
    $syntax = "usmarc" unless $syntax;
732
    $syntax //= "XML";
735
733
736
    my $host = $context->{'listen'}->{$server}->{'content'};
734
    my $host = $context->{'listen'}->{$server}->{'content'};
737
    my $servername = $context->{"config"}->{$server};
735
    my $servername = $context->{"config"}->{$server};
Lines 749-755 sub _new_Zconn { Link Here
749
        $o->option(cqlfile=> $context->{"server"}->{$server}->{"cql2rpn"});
747
        $o->option(cqlfile=> $context->{"server"}->{$server}->{"cql2rpn"});
750
        $o->option(cclfile=> $context->{"serverinfo"}->{$server}->{"ccl2rpn"});
748
        $o->option(cclfile=> $context->{"serverinfo"}->{$server}->{"ccl2rpn"});
751
        $o->option(preferredRecordSyntax => $syntax);
749
        $o->option(preferredRecordSyntax => $syntax);
752
        $o->option(elementSetName => "F"); # F for 'full' as opposed to B for 'brief'
750
        $o->option(elementSetName => "marcxml");
753
        $o->option(databaseName => ($servername?$servername:"biblios"));
751
        $o->option(databaseName => ($servername?$servername:"biblios"));
754
752
755
        # create a new connection object
753
        # create a new connection object
(-)a/C4/Search.pm (-29 / +37 lines)
Lines 144-151 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 =
147
            my $marcrecord = MARC::Record->new_from_xml(
148
            MARC::Record->new_from_usmarc($possible_duplicate_record);
148
                $possible_duplicate_record,
149
                'UTF-8'
150
            );
149
            my $result = TransformMarcToKoha( $dbh, $marcrecord, '' );
151
            my $result = TransformMarcToKoha( $dbh, $marcrecord, '' );
150
152
151
            # FIXME :: why 2 $biblionumber ?
153
            # FIXME :: why 2 $biblionumber ?
Lines 446-451 sub getRecords { Link Here
446
                else {
448
                else {
447
                    $times = $size;
449
                    $times = $size;
448
                }
450
                }
451
449
                for ( my $j = $offset ; $j < $times ; $j++ ) {
452
                for ( my $j = $offset ; $j < $times ; $j++ ) {
450
                    my $records_hash;
453
                    my $records_hash;
451
                    my $record;
454
                    my $record;
Lines 455-461 sub getRecords { Link Here
455
                        my ( $term, $occ ) = $results[ $i - 1 ]->term($j);
458
                        my ( $term, $occ ) = $results[ $i - 1 ]->term($j);
456
459
457
                 # here we create a minimal MARC record and hand it off to the
460
                 # here we create a minimal MARC record and hand it off to the
458
                 # template just like a normal result ... perhaps not ideal, but
461
                 # template just like a normal result ... serhaps not ideal, but
459
                 # it works for now
462
                 # it works for now
460
                        my $tmprecord = MARC::Record->new();
463
                        my $tmprecord = MARC::Record->new();
461
                        $tmprecord->encoding('UTF-8');
464
                        $tmprecord->encoding('UTF-8');
Lines 488-494 sub getRecords { Link Here
488
                    # not an index scan
491
                    # not an index scan
489
                    else {
492
                    else {
490
                        $record = $results[ $i - 1 ]->record($j)->raw();
493
                        $record = $results[ $i - 1 ]->record($j)->raw();
491
492
                        # warn "RECORD $j:".$record;
494
                        # warn "RECORD $j:".$record;
493
                        $results_hash->{'RECORDS'}[$j] = $record;
495
                        $results_hash->{'RECORDS'}[$j] = $record;
494
                    }
496
                    }
Lines 503-541 sub getRecords { Link Here
503
                      $size > $facets_maxrecs ? $facets_maxrecs : $size;
505
                      $size > $facets_maxrecs ? $facets_maxrecs : $size;
504
                    for my $facet (@$facets) {
506
                    for my $facet (@$facets) {
505
                        for ( my $j = 0 ; $j < $jmax ; $j++ ) {
507
                        for ( my $j = 0 ; $j < $jmax ; $j++ ) {
506
                            my $render_record =
508
507
                              $results[ $i - 1 ]->record($j)->render();
509
                            my $marc_record = MARC::Record->new_from_xml(
510
                                $results[ $i - 1 ]->record($j)->raw(),
511
                                'UTF-8'
512
                            );
508
                            my @used_datas = ();
513
                            my @used_datas = ();
514
509
                            foreach my $tag ( @{ $facet->{tags} } ) {
515
                            foreach my $tag ( @{ $facet->{tags} } ) {
510
516
511
                                # avoid first line
517
                                # avoid first line
512
                                my $tag_num = substr( $tag, 0, 3 );
518
                                my $tag_num = substr( $tag, 0, 3 );
513
                                my $letters = substr( $tag, 3 );
519
                                my $subfield_letters = substr( $tag, 3 );
514
                                my $field_pattern =
520
                                # Removed when as_string fixed
515
                                  '\n' . $tag_num . ' ([^z][^\n]+)';
521
                                my @subfields = $subfield_letters =~ /./sg;
516
                                $field_pattern = '\n' . $tag_num . ' ([^\n]+)'
522
517
                                  if ( int($tag_num) < 10 );
523
                                my @fields = $marc_record->field($tag_num);
518
                                my @field_tokens =
524
                                foreach my $field (@fields) {
519
                                  ( $render_record =~ /$field_pattern/g );
525
                                    # TODO: Once as_string is capable of using a separator, use this
520
                                foreach my $field_token (@field_tokens) {
526
                                    # my $data = $field->as_string( $subfield_letters, $facet->{sep} );
521
                                    my @subf = ( $field_token =~
527
522
                                          /\$([a-zA-Z0-9]) ([^\$]+)/g );
528
                                    my @values = ();
523
                                    my @values;
529
                                    foreach my $subfield (@subfields) {
524
                                    for ( my $i = 0 ; $i < @subf ; $i += 2 ) {
530
                                        push @values, $field->subfield( $subfield )
525
                                        if ( $letters =~ $subf[$i] ) {
531
                                            if defined $field->subfield( $subfield );
526
                                            my $value = $subf[ $i + 1 ];
527
                                            $value =~ s/^ *//;
528
                                            $value =~ s/ *$//;
529
                                            push @values, $value;
530
                                        }
531
                                    }
532
                                    }
533
532
                                    my $data = join( $facet->{sep}, @values );
534
                                    my $data = join( $facet->{sep}, @values );
535
533
                                    unless ( $data ~~ @used_datas ) {
536
                                    unless ( $data ~~ @used_datas ) {
534
                                        $facets_counter->{ $facet->{idx} }
535
                                          ->{$data}++;
536
                                        push @used_datas, $data;
537
                                        push @used_datas, $data;
537
                                    }
538
                                    }
538
                                }    # fields
539
540
                                    $facets_counter->{ $facet->{idx} }->{$data}++;
541
542
                                } # fields
539
                            }    # field codes
543
                            }    # field codes
540
                        }    # records
544
                        }    # records
541
                        $facets_info->{ $facet->{idx} }->{label_value} =
545
                        $facets_info->{ $facet->{idx} }->{label_value} =
Lines 1693-1705 sub searchResults { Link Here
1693
        $times = $hits;	 # FIXME: if $hits is undefined, why do we want to equal it?
1697
        $times = $hits;	 # FIXME: if $hits is undefined, why do we want to equal it?
1694
    }
1698
    }
1695
1699
1696
	my $marcflavour = C4::Context->preference("marcflavour");
1700
    my $marcflavour = C4::Context->preference("marcflavour");
1697
    # We get the biblionumber position in MARC
1701
    # We get the biblionumber position in MARC
1698
    my ($bibliotag,$bibliosubf)=GetMarcFromKohaField('biblio.biblionumber','');
1702
    my ($bibliotag,$bibliosubf)=GetMarcFromKohaField('biblio.biblionumber','');
1699
1703
1700
    # loop through all of the records we've retrieved
1704
    # loop through all of the records we've retrieved
1701
    for ( my $i = $offset ; $i <= $times - 1 ; $i++ ) {
1705
    for ( my $i = $offset ; $i <= $times - 1 ; $i++ ) {
1702
        my $marcrecord = eval { MARC::File::USMARC::decode( $marcresults->[$i] ); };
1706
        my $marcrecord = eval {  MARC::Record->new_from_xml(
1707
            $marcresults->[$i],
1708
            'UTF-8'
1709
        ); };
1710
1703
        if ( $@ ) {
1711
        if ( $@ ) {
1704
            warn "ERROR DECODING RECORD - $@: " . $marcresults->[$i];
1712
            warn "ERROR DECODING RECORD - $@: " . $marcresults->[$i];
1705
            next;
1713
            next;
(-)a/catalogue/search.pl (-1 / +1 lines)
Lines 660-666 for (my $i=0;$i<@servers;$i++) { Link Here
660
    elsif ($server =~/authorityserver/) { # this is the local authority server
660
    elsif ($server =~/authorityserver/) { # this is the local authority server
661
        my @inner_sup_results_array;
661
        my @inner_sup_results_array;
662
        for my $sup_record ( @{$results_hashref->{$server}->{"RECORDS"}} ) {
662
        for my $sup_record ( @{$results_hashref->{$server}->{"RECORDS"}} ) {
663
            my $marc_record_object = MARC::Record->new_from_usmarc($sup_record);
663
            my $marc_record_object = MARC::Record->new_from_xml($sup_record,'UTF-8');
664
            # warn "Authority Found: ".$marc_record_object->as_formatted();
664
            # warn "Authority Found: ".$marc_record_object->as_formatted();
665
            push @inner_sup_results_array, {
665
            push @inner_sup_results_array, {
666
                'title' => $marc_record_object->field(100)->subfield('a'),
666
                'title' => $marc_record_object->field(100)->subfield('a'),
(-)a/circ/circulation.pl (-1 / +1 lines)
Lines 309-315 if ($barcode) { Link Here
309
            foreach my $hit ( @{$results} ) {
309
            foreach my $hit ( @{$results} ) {
310
                my $chosen =
310
                my $chosen =
311
                  TransformMarcToKoha( C4::Context->dbh,
311
                  TransformMarcToKoha( C4::Context->dbh,
312
                    MARC::Record->new_from_usmarc($hit) );
312
                    MARC::Record->new_from_xml($hit,'UTF-8') );
313
313
314
                # offer all barcodes individually
314
                # offer all barcodes individually
315
                foreach my $barcode ( sort split(/\s*\|\s*/, $chosen->{barcode}) ) {
315
                foreach my $barcode ( sort split(/\s*\|\s*/, $chosen->{barcode}) ) {
(-)a/t/db_dependent/Search.t (-21 / +20 lines)
Lines 346-392 sub run_marc21_search_tests { Link Here
346
346
347
    ( undef, $results_hashref, $facets_loop ) =
347
    ( undef, $results_hashref, $facets_loop ) =
348
        getRecords('salud', 'salud', [], [ 'biblioserver' ], '19', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
348
        getRecords('salud', 'salud', [], [ 'biblioserver' ], '19', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
349
    ok(MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0])->title_proper() =~ m/^Efectos del ambiente/ &&
349
    ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() =~ m/^Efectos del ambiente/ &&
350
        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' &&
350
        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[7],'UTF-8')->title_proper() eq 'Salud y seguridad de los trabajadores del sector salud: manual para gerentes y administradores^ies' &&
351
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[18])->title_proper() =~ m/^Indicadores de resultados identificados/
351
        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/
352
        , "Simple relevance sorting in getRecords matches old behavior");
352
        , "Simple relevance sorting in getRecords matches old behavior");
353
353
354
    ( undef, $results_hashref, $facets_loop ) =
354
    ( undef, $results_hashref, $facets_loop ) =
355
        getRecords('salud', 'salud', [ 'author_az' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
355
        getRecords('salud', 'salud', [ 'author_az' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
356
    ok(MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0])->title_proper() =~ m/la enfermedad laboral\^ies$/ &&
356
    ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() =~ m/la enfermedad laboral\^ies$/ &&
357
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[6])->title_proper() =~ m/^Indicadores de resultados identificados/ &&
357
        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[6],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/ &&
358
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[18])->title_proper() eq 'World health statistics 2009^ien'
358
        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() eq 'World health statistics 2009^ien'
359
        , "Simple ascending author sorting in getRecords matches old behavior");
359
        , "Simple ascending author sorting in getRecords matches old behavior");
360
360
361
    ( undef, $results_hashref, $facets_loop ) =
361
    ( undef, $results_hashref, $facets_loop ) =
362
        getRecords('salud', 'salud', [ 'author_za' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
362
        getRecords('salud', 'salud', [ 'author_za' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
363
    ok(MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0])->title_proper() eq 'World health statistics 2009^ien' &&
363
    ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() eq 'World health statistics 2009^ien' &&
364
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[12])->title_proper() =~ m/^Indicadores de resultados identificados/ &&
364
        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[12],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/ &&
365
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[18])->title_proper() =~ m/la enfermedad laboral\^ies$/
365
        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() =~ m/la enfermedad laboral\^ies$/
366
        , "Simple descending author sorting in getRecords matches old behavior");
366
        , "Simple descending author sorting in getRecords matches old behavior");
367
367
368
    ( undef, $results_hashref, $facets_loop ) =
368
    ( undef, $results_hashref, $facets_loop ) =
369
        getRecords('salud', 'salud', [ 'pubdate_asc' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
369
        getRecords('salud', 'salud', [ 'pubdate_asc' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
370
    ok(MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0])->title_proper() eq 'Manual de higiene industrial^ies' &&
370
    ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() eq 'Manual de higiene industrial^ies' &&
371
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[7])->title_proper() =~ m/seguridad e higiene del trabajo\^ies$/ &&
371
        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[7],'UTF-8')->title_proper() =~ m/seguridad e higiene del trabajo\^ies$/ &&
372
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[18])->title_proper() =~ m/^Indicadores de resultados identificados/
372
        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() =~ m/^Indicadores de resultados identificados/
373
        , "Simple ascending publication date sorting in getRecords matches old behavior");
373
        , "Simple ascending publication date sorting in getRecords matches old behavior");
374
374
375
    ( undef, $results_hashref, $facets_loop ) =
375
    ( undef, $results_hashref, $facets_loop ) =
376
        getRecords('salud', 'salud', [ 'pubdate_dsc' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
376
        getRecords('salud', 'salud', [ 'pubdate_dsc' ], [ 'biblioserver' ], '38', 0, undef, \%branches, \%itemtypes, 'ccl', undef);
377
    ok(MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0])->title_proper() =~ m/^Estado de salud/ &&
377
    ok(MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[0],'UTF-8')->title_proper() =~ m/^Estado de salud/ &&
378
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[7])->title_proper() eq 'World health statistics 2009^ien' &&
378
        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[7],'UTF-8')->title_proper() eq 'World health statistics 2009^ien' &&
379
        MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[18])->title_proper() eq 'Manual de higiene industrial^ies'
379
        MARC::Record::new_from_xml($results_hashref->{biblioserver}->{RECORDS}->[18],'UTF-8')->title_proper() eq 'Manual de higiene industrial^ies'
380
        , "Simple descending publication date sorting in getRecords matches old behavior");
380
        , "Simple descending publication date sorting in getRecords matches old behavior");
381
381
TODO: {
382
    local $TODO = "Switch relevance search to MARCXML too";
382
    ( undef, $results_hashref, $facets_loop ) =
383
    ( undef, $results_hashref, $facets_loop ) =
383
        getRecords('books', 'books', [ 'relevance' ], [ 'biblioserver' ], '20', 0, undef, \%branches, \%itemtypes, undef, 1);
384
        getRecords('books', 'books', [ 'relevance' ], [ 'biblioserver' ], '20', 0, undef, \%branches, \%itemtypes, undef, 1);
384
    $record = MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0]);
385
    $record = MARC::Record::new_from_usmarc($results_hashref->{biblioserver}->{RECORDS}->[0]);
385
    is($record->title_proper(), 'books', "Scan returned requested item");
386
    is($record->title_proper(), 'books', "Scan returned requested item");
386
    is($record->subfield('100', 'a'), 2, "Scan returned correct number of records matching term");
387
    is($record->subfield('100', 'a'), 2, "Scan returned correct number of records matching term");
387
388
    # Time to test buildQuery and searchResults too.
388
    # Time to test buildQuery and searchResults too.
389
389
}
390
    my ( $query, $simple_query, $query_cgi,
390
    my ( $query, $simple_query, $query_cgi,
391
    $query_desc, $limit, $limit_cgi, $limit_desc,
391
    $query_desc, $limit, $limit_cgi, $limit_desc,
392
    $stopwords_removed, $query_type );
392
    $stopwords_removed, $query_type );
Lines 526-535 sub run_marc21_search_tests { Link Here
526
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
526
    ($error, $results_hashref, $facets_loop) = getRecords($query,$simple_query,[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
527
    is($results_hashref->{biblioserver}->{hits}, 19, "Weighted query returned correct number of results");
527
    is($results_hashref->{biblioserver}->{hits}, 19, "Weighted query returned correct number of results");
528
    if ($indexing_mode eq 'grs1') {
528
    if ($indexing_mode eq 'grs1') {
529
        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");
529
        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");
530
    } else {
530
    } else {
531
        local $TODO = "Query weighting does not behave exactly the same in DOM vs. GRS";
531
        local $TODO = "Query weighting does not behave exactly the same in DOM vs. GRS";
532
        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");
532
        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");
533
    }
533
    }
534
534
535
    $QueryStemming = $QueryWeightFields = $QueryFuzzy = $QueryRemoveStopwords = 0;
535
    $QueryStemming = $QueryWeightFields = $QueryFuzzy = $QueryRemoveStopwords = 0;
536
- 

Return to bug 11096