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

(-)a/Koha/SearchEngine/Elasticsearch/Search.pm (+16 lines)
Lines 45-50 use C4::Context; Link Here
45
use Koha::ItemTypes;
45
use Koha::ItemTypes;
46
use Koha::AuthorisedValues;
46
use Koha::AuthorisedValues;
47
use Koha::SearchEngine::QueryBuilder;
47
use Koha::SearchEngine::QueryBuilder;
48
use Koha::SearchEngine::Search;
48
use MARC::Record;
49
use MARC::Record;
49
use Catmandu::Store::ElasticSearch;
50
use Catmandu::Store::ElasticSearch;
50
51
Lines 344-349 sub simple_search_compat { Link Here
344
    return (undef, \@records, $results->total);
345
    return (undef, \@records, $results->total);
345
}
346
}
346
347
348
=head2 extract_biblionumber
349
350
    my $biblionumber = $searcher->extract_biblionumber( $searchresult );
351
352
$searchresult comes from simple_search_compat.
353
354
Returns the biblionumber from the search result record.
355
356
=cut
357
358
sub extract_biblionumber {
359
    my ( $self, $searchresultrecord ) = @_;
360
    return Koha::SearchEngine::Search::extract_biblionumber( $searchresultrecord );
361
}
362
347
=head2 json2marc
363
=head2 json2marc
348
364
349
    my $marc = $self->json2marc($marc_json);
365
    my $marc = $self->json2marc($marc_json);
(-)a/Koha/SearchEngine/Search.pm (-1 / +22 lines)
Lines 43-50 Creates a new C<Search> of whatever the relevant type is. Link Here
43
43
44
=cut
44
=cut
45
45
46
use C4::Context;
47
use Modern::Perl;
46
use Modern::Perl;
47
use C4::Context;
48
use C4::Biblio qw//;
48
49
49
sub new {
50
sub new {
50
    my $engine = C4::Context->preference("SearchEngine") // 'Zebra';
51
    my $engine = C4::Context->preference("SearchEngine") // 'Zebra';
Lines 55-58 sub new { Link Here
55
    return $class->new(@_);
56
    return $class->new(@_);
56
}
57
}
57
58
59
=head2 extract_biblionumber
60
61
    my $biblionumber = $searcher->extract_biblionumber( $marc );
62
63
Returns the biblionumber from $marc. The routine is called from the
64
extract_biblionumber method of the specific search engine.
65
66
=cut
67
68
sub extract_biblionumber {
69
    my ( $record ) = @_;
70
    return if ref($record) ne 'MARC::Record';
71
    my ( $biblionumbertagfield, $biblionumbertagsubfield ) = C4::Biblio::GetMarcFromKohaField( 'biblio.biblionumber', '' );
72
    if( $biblionumbertagfield < 10 ) {
73
        my $controlfield = $record->field( $biblionumbertagfield );
74
        return $controlfield ? $controlfield->data : undef;
75
    }
76
    return $record->subfield( $biblionumbertagfield, $biblionumbertagsubfield );
77
}
78
58
1;
79
1;
(-)a/Koha/SearchEngine/Zebra/Search.pm (+17 lines)
Lines 23-28 use base qw(Class::Accessor); Link Here
23
23
24
use C4::Search; # :(
24
use C4::Search; # :(
25
use C4::AuthoritiesMarc;
25
use C4::AuthoritiesMarc;
26
use Koha::SearchEngine::Search;
26
27
27
=head1 NAME
28
=head1 NAME
28
29
Lines 76-81 sub simple_search_compat { Link Here
76
    return C4::Search::SimpleSearch(@_);
77
    return C4::Search::SimpleSearch(@_);
77
}
78
}
78
79
80
=head2 extract_biblionumber
81
82
    my $biblionumber = $searcher->extract_biblionumber( $searchresult );
83
84
$searchresult comes from simple_search_compat.
85
86
Returns the biblionumber from the search result record.
87
88
=cut
89
90
sub extract_biblionumber {
91
    my ( $self, $searchresultrecord ) = @_;
92
    my $record = C4::Search::new_record_from_zebra( 'biblioserver', $searchresultrecord );
93
    return Koha::SearchEngine::Search::extract_biblionumber( $record );
94
}
95
79
=head2 search_auth_compat
96
=head2 search_auth_compat
80
97
81
This passes the search query on to C4::AuthoritiesMarc::SearchAuthorities
98
This passes the search query on to C4::AuthoritiesMarc::SearchAuthorities
(-)a/t/db_dependent/Koha/SearchEngine/Search.t (-1 / +63 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Tests for Koha/SearchEngine/Search
4
5
use Modern::Perl;
6
7
use Test::More tests => 1;
8
9
use MARC::Field;
10
use MARC::Record;
11
use Test::MockModule;
12
use Test::MockObject;
13
14
use t::lib::Mocks;
15
16
#use C4::Biblio qw//;
17
use Koha::Database;
18
use Koha::SearchEngine::Search;
19
20
BEGIN {
21
    my $mock = Test::MockObject->new();
22
    $mock->fake_module( 'Catmandu::Store::ElasticSearch' );
23
}
24
25
my $schema  = Koha::Database->new->schema;
26
$schema->storage->txn_begin;
27
28
subtest 'Test extract_biblionumber' => sub {
29
    plan tests => 2;
30
31
    t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' );
32
    my $biblio_mod = Test::MockModule->new( 'C4::Biblio' );
33
    my $search_mod = Test::MockModule->new( 'C4::Search' );
34
    my $koha_fields = [ '001', '' ];
35
    $biblio_mod->mock( 'GetMarcFromKohaField', sub { return @$koha_fields; });
36
    $search_mod->mock( 'new_record_from_zebra', \&test_record );
37
38
    # Extract using 001
39
    my $searcher = Koha::SearchEngine::Search->new;
40
    my $bibno = $searcher->extract_biblionumber( 'fake_result' );
41
    is( $bibno, 3456, 'Extracted biblio number for Zebra' );
42
43
    # Now use 999c with Elasticsearch
44
    t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' );
45
    $search_mod->unmock( 'new_record_from_zebra' );
46
    $koha_fields = [ '999', 'c' ];
47
    $searcher = Koha::SearchEngine::Search->new({ index => 'biblios' });
48
    $bibno = $searcher->extract_biblionumber( test_record() );
49
    is( $bibno, 4567, 'Extracted biblio number for Zebra' );
50
};
51
52
# -- Helper routine
53
sub test_record {
54
    my $marc = MARC::Record->new;
55
    $marc->append_fields(
56
        MARC::Field->new( '001', '3456' ),
57
        MARC::Field->new( '245', '', '', a => 'Some title' ),
58
        MARC::Field->new( '999', '', '', c => '4567' ),
59
    );
60
    return $marc;
61
}
62
63
$schema->storage->txn_rollback;

Return to bug 9988