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

(-)a/Koha/SearchEngine/Elasticsearch.pm (-3 / +3 lines)
Lines 595-602 An optional range as a string in the format "<START>-<END>" or "<START>", Link Here
595
where "<START>" and "<END>" are integers specifying a range that will be used
595
where "<START>" and "<END>" are integers specifying a range that will be used
596
for extracting a substring from MARC data as Elasticsearch field target value.
596
for extracting a substring from MARC data as Elasticsearch field target value.
597
597
598
The first character position is "1", and the range is inclusive,
598
The first character position is "0", and the range is inclusive,
599
so "1-3" means the first three characters of MARC data.
599
so "0-2" means the first three characters of MARC data.
600
600
601
If only "<START>" is provided only one character at position "<START>" will
601
If only "<START>" is provided only one character at position "<START>" will
602
be extracted.
602
be extracted.
Lines 611-617 sub _field_mappings { Link Here
611
    my @mappings;
611
    my @mappings;
612
612
613
    my $substr_args = undef;
613
    my $substr_args = undef;
614
    if ($range) {
614
    if (defined $range) {
615
        # TODO: use value_callback instead?
615
        # TODO: use value_callback instead?
616
        my ($start, $end) = map(int, split /-/, $range, 2);
616
        my ($start, $end) = map(int, split /-/, $range, 2);
617
        $substr_args = [$start];
617
        $substr_args = [$start];
(-)a/admin/searchengine/elasticsearch/mappings.yaml (-12 / +12 lines)
Lines 1756-1767 biblios: Link Here
1756
    label: date-entered-on-file
1756
    label: date-entered-on-file
1757
    mappings:
1757
    mappings:
1758
      - facet: ''
1758
      - facet: ''
1759
        marc_field: '008_/1-5'
1759
        marc_field: '008_/0-5'
1760
        marc_type: marc21
1760
        marc_type: marc21
1761
        sort: ~
1761
        sort: ~
1762
        suggestible: ''
1762
        suggestible: ''
1763
      - facet: ''
1763
      - facet: ''
1764
        marc_field: '008_/1-5'
1764
        marc_field: '008_/0-5'
1765
        marc_type: normarc
1765
        marc_type: normarc
1766
        sort: ~
1766
        sort: ~
1767
        suggestible: ''
1767
        suggestible: ''
Lines 1867-1878 biblios: Link Here
1867
    label: ff7-00
1867
    label: ff7-00
1868
    mappings:
1868
    mappings:
1869
      - facet: ''
1869
      - facet: ''
1870
        marc_field: 007_/1
1870
        marc_field: 007_/0
1871
        marc_type: marc21
1871
        marc_type: marc21
1872
        sort: ~
1872
        sort: ~
1873
        suggestible: ''
1873
        suggestible: ''
1874
      - facet: ''
1874
      - facet: ''
1875
        marc_field: 007_/1
1875
        marc_field: 007_/0
1876
        marc_type: normarc
1876
        marc_type: normarc
1877
        sort: ~
1877
        sort: ~
1878
        suggestible: ''
1878
        suggestible: ''
Lines 1881-1892 biblios: Link Here
1881
    label: ff7-01
1881
    label: ff7-01
1882
    mappings:
1882
    mappings:
1883
      - facet: ''
1883
      - facet: ''
1884
        marc_field: 007_/2
1884
        marc_field: 007_/1
1885
        marc_type: marc21
1885
        marc_type: marc21
1886
        sort: ~
1886
        sort: ~
1887
        suggestible: ''
1887
        suggestible: ''
1888
      - facet: ''
1888
      - facet: ''
1889
        marc_field: 007_/2
1889
        marc_field: 007_/1
1890
        marc_type: normarc
1890
        marc_type: normarc
1891
        sort: ~
1891
        sort: ~
1892
        suggestible: ''
1892
        suggestible: ''
Lines 1895-1906 biblios: Link Here
1895
    label: ff7-01-02
1895
    label: ff7-01-02
1896
    mappings:
1896
    mappings:
1897
      - facet: ''
1897
      - facet: ''
1898
        marc_field: 007_/1-2
1898
        marc_field: 007_/0-1
1899
        marc_type: marc21
1899
        marc_type: marc21
1900
        sort: ~
1900
        sort: ~
1901
        suggestible: ''
1901
        suggestible: ''
1902
      - facet: ''
1902
      - facet: ''
1903
        marc_field: 007_/1-2
1903
        marc_field: 007_/0-1
1904
        marc_type: normarc
1904
        marc_type: normarc
1905
        sort: ~
1905
        sort: ~
1906
        suggestible: ''
1906
        suggestible: ''
Lines 1909-1920 biblios: Link Here
1909
    label: ff7-02
1909
    label: ff7-02
1910
    mappings:
1910
    mappings:
1911
      - facet: ''
1911
      - facet: ''
1912
        marc_field: 007_/3
1912
        marc_field: 007_/2
1913
        marc_type: marc21
1913
        marc_type: marc21
1914
        sort: ~
1914
        sort: ~
1915
        suggestible: ''
1915
        suggestible: ''
1916
      - facet: ''
1916
      - facet: ''
1917
        marc_field: 007_/3
1917
        marc_field: 007_/2
1918
        marc_type: normarc
1918
        marc_type: normarc
1919
        sort: ~
1919
        sort: ~
1920
        suggestible: ''
1920
        suggestible: ''
Lines 2581-2592 biblios: Link Here
2581
    label: llength
2581
    label: llength
2582
    mappings:
2582
    mappings:
2583
      - facet: ''
2583
      - facet: ''
2584
        marc_field: leader_/1-5
2584
        marc_field: leader_/0-4
2585
        marc_type: marc21
2585
        marc_type: marc21
2586
        sort: ~
2586
        sort: ~
2587
        suggestible: ''
2587
        suggestible: ''
2588
      - facet: ''
2588
      - facet: ''
2589
        marc_field: leader_/1-5
2589
        marc_field: leader_/0-4
2590
        marc_type: normarc
2590
        marc_type: normarc
2591
        sort: ~
2591
        sort: ~
2592
        suggestible: ''
2592
        suggestible: ''
(-)a/installer/data/mysql/atomicupdate/bug_22339.perl (+55 lines)
Line 0 Link Here
1
$DBversion = 'XXX'; # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do( q|
4
        UPDATE search_marc_map SET marc_field='007_/0' 
5
          WHERE marc_type IN ('marc21', 'normarc') AND marc_field='007_/1' AND id IN 
6
            (SELECT search_marc_map_id FROM search_marc_to_field WHERE search_field_id IN 
7
              (SELECT id FROM search_field WHERE label='ff7-00')
8
            )
9
    |);
10
11
    $dbh->do( q|
12
        UPDATE search_marc_map SET marc_field='007_/1' 
13
          WHERE marc_type IN ('marc21', 'normarc') AND marc_field='007_/2' AND id IN 
14
            (SELECT search_marc_map_id FROM search_marc_to_field WHERE search_field_id IN 
15
              (SELECT id FROM search_field WHERE label='ff7-01')
16
            )
17
    |);
18
19
    $dbh->do( q|
20
        UPDATE search_marc_map SET marc_field='007_/2' 
21
          WHERE marc_type IN ('marc21', 'normarc') AND marc_field='007_/3' AND id IN 
22
            (SELECT search_marc_map_id FROM search_marc_to_field WHERE search_field_id IN 
23
              (SELECT id FROM search_field WHERE label='ff7-02')
24
            )
25
    |);
26
27
    # N.B. ff7-01-02 really is 00-01!
28
    $dbh->do( q|
29
        UPDATE search_marc_map SET marc_field='007_/0-1' 
30
          WHERE marc_type IN ('marc21', 'normarc') AND marc_field='007_/1-2' AND id IN 
31
            (SELECT search_marc_map_id FROM search_marc_to_field WHERE search_field_id IN 
32
              (SELECT id FROM search_field WHERE label='ff7-01-02')
33
            )
34
    |);
35
36
    $dbh->do( q|
37
        UPDATE search_marc_map SET marc_field='008_/0-5' 
38
          WHERE marc_type IN ('marc21', 'normarc') AND marc_field='008_/1-5' AND id IN 
39
            (SELECT search_marc_map_id FROM search_marc_to_field WHERE search_field_id IN 
40
              (SELECT id FROM search_field WHERE label='date-entered-on-file')
41
            )
42
    |);
43
44
    $dbh->do( q|
45
        UPDATE search_marc_map SET marc_field='leader_/0-4' 
46
          WHERE marc_type IN ('marc21', 'normarc') AND marc_field='leader_/1-5' AND id IN 
47
            (SELECT search_marc_map_id FROM search_marc_to_field WHERE search_field_id IN 
48
              (SELECT id FROM search_field WHERE label='llength')
49
            )
50
    |);
51
52
    # Always end with this (adjust the bug info)
53
    SetVersion( $DBversion );
54
    print "Upgrade to $DBversion done (Bug 22339 - Fix search field mappings of MARC fixed fields)\n";
55
}
(-)a/t/Koha/SearchEngine/Elasticsearch.t (-2 / +13 lines)
Lines 117-123 subtest 'get_elasticsearch_mappings() tests' => sub { Link Here
117
117
118
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub {
118
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub {
119
119
120
    plan tests => 49;
120
    plan tests => 50;
121
121
122
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
122
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
123
123
Lines 239-244 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
239
            marc_type => 'marc21',
239
            marc_type => 'marc21',
240
            marc_field => 'leader_/6-7',
240
            marc_field => 'leader_/6-7',
241
        },
241
        },
242
        {
243
            name => 'ff7-00',
244
            type => 'string',
245
            facet => 0,
246
            suggestible => 0,
247
            sort => 0,
248
            marc_type => 'marc21',
249
            marc_field => '007_/0',
250
        },
242
    );
251
    );
243
252
244
    my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch');
253
    my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch');
Lines 268-273 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
268
    $marc_record_1->leader('     cam  22      a 4500');
277
    $marc_record_1->leader('     cam  22      a 4500');
269
    $marc_record_1->append_fields(
278
    $marc_record_1->append_fields(
270
        MARC::Field->new('001', '123'),
279
        MARC::Field->new('001', '123'),
280
        MARC::Field->new('007', 'ku'),
271
        MARC::Field->new('020', '', '', a => '1-56619-909-3'),
281
        MARC::Field->new('020', '', '', a => '1-56619-909-3'),
272
        MARC::Field->new('100', '', '', a => 'Author 1'),
282
        MARC::Field->new('100', '', '', a => 'Author 1'),
273
        MARC::Field->new('110', '', '', a => 'Corp Author'),
283
        MARC::Field->new('110', '', '', a => 'Corp Author'),
Lines 301-306 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
301
311
302
    is_deeply($docs->[0][1]->{control_number}, ['123'], 'First record control number should be set correctly');
312
    is_deeply($docs->[0][1]->{control_number}, ['123'], 'First record control number should be set correctly');
303
313
314
    is_deeply($docs->[0][1]->{'ff7-00'}, ['k'], 'First record ff7-00 should be set correctly');
315
304
    is(scalar @{$docs->[0][1]->{author}}, 2, 'First document author field should contain two values');
316
    is(scalar @{$docs->[0][1]->{author}}, 2, 'First document author field should contain two values');
305
    is_deeply($docs->[0][1]->{author}, ['Author 1', 'Corp Author'], 'First document author field should be set correctly');
317
    is_deeply($docs->[0][1]->{author}, ['Author 1', 'Corp Author'], 'First document author field should be set correctly');
306
318
307
- 

Return to bug 22339