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

(-)a/Koha/SearchEngine/Elasticsearch.pm (-3 / +3 lines)
Lines 610-617 An optional range as a string in the format "<START>-<END>" or "<START>", Link Here
610
where "<START>" and "<END>" are integers specifying a range that will be used
610
where "<START>" and "<END>" are integers specifying a range that will be used
611
for extracting a substring from MARC data as Elasticsearch field target value.
611
for extracting a substring from MARC data as Elasticsearch field target value.
612
612
613
The first character position is "1", and the range is inclusive,
613
The first character position is "0", and the range is inclusive,
614
so "1-3" means the first three characters of MARC data.
614
so "0-2" means the first three characters of MARC data.
615
615
616
If only "<START>" is provided only one character at position "<START>" will
616
If only "<START>" is provided only one character at position "<START>" will
617
be extracted.
617
be extracted.
Lines 626-632 sub _field_mappings { Link Here
626
    my @mappings;
626
    my @mappings;
627
627
628
    my $substr_args = undef;
628
    my $substr_args = undef;
629
    if ($range) {
629
    if (defined $range) {
630
        # TODO: use value_callback instead?
630
        # TODO: use value_callback instead?
631
        my ($start, $end) = map(int, split /-/, $range, 2);
631
        my ($start, $end) = map(int, split /-/, $range, 2);
632
        $substr_args = [$start];
632
        $substr_args = [$start];
(-)a/admin/searchengine/elasticsearch/mappings.yaml (-12 / +12 lines)
Lines 1758-1769 biblios: Link Here
1758
    label: date-entered-on-file
1758
    label: date-entered-on-file
1759
    mappings:
1759
    mappings:
1760
      - facet: ''
1760
      - facet: ''
1761
        marc_field: '008_/1-5'
1761
        marc_field: '008_/0-5'
1762
        marc_type: marc21
1762
        marc_type: marc21
1763
        sort: ~
1763
        sort: ~
1764
        suggestible: ''
1764
        suggestible: ''
1765
      - facet: ''
1765
      - facet: ''
1766
        marc_field: '008_/1-5'
1766
        marc_field: '008_/0-5'
1767
        marc_type: normarc
1767
        marc_type: normarc
1768
        sort: ~
1768
        sort: ~
1769
        suggestible: ''
1769
        suggestible: ''
Lines 1869-1880 biblios: Link Here
1869
    label: ff7-00
1869
    label: ff7-00
1870
    mappings:
1870
    mappings:
1871
      - facet: ''
1871
      - facet: ''
1872
        marc_field: 007_/1
1872
        marc_field: 007_/0
1873
        marc_type: marc21
1873
        marc_type: marc21
1874
        sort: ~
1874
        sort: ~
1875
        suggestible: ''
1875
        suggestible: ''
1876
      - facet: ''
1876
      - facet: ''
1877
        marc_field: 007_/1
1877
        marc_field: 007_/0
1878
        marc_type: normarc
1878
        marc_type: normarc
1879
        sort: ~
1879
        sort: ~
1880
        suggestible: ''
1880
        suggestible: ''
Lines 1883-1894 biblios: Link Here
1883
    label: ff7-01
1883
    label: ff7-01
1884
    mappings:
1884
    mappings:
1885
      - facet: ''
1885
      - facet: ''
1886
        marc_field: 007_/2
1886
        marc_field: 007_/1
1887
        marc_type: marc21
1887
        marc_type: marc21
1888
        sort: ~
1888
        sort: ~
1889
        suggestible: ''
1889
        suggestible: ''
1890
      - facet: ''
1890
      - facet: ''
1891
        marc_field: 007_/2
1891
        marc_field: 007_/1
1892
        marc_type: normarc
1892
        marc_type: normarc
1893
        sort: ~
1893
        sort: ~
1894
        suggestible: ''
1894
        suggestible: ''
Lines 1897-1908 biblios: Link Here
1897
    label: ff7-01-02
1897
    label: ff7-01-02
1898
    mappings:
1898
    mappings:
1899
      - facet: ''
1899
      - facet: ''
1900
        marc_field: 007_/1-2
1900
        marc_field: 007_/0-1
1901
        marc_type: marc21
1901
        marc_type: marc21
1902
        sort: ~
1902
        sort: ~
1903
        suggestible: ''
1903
        suggestible: ''
1904
      - facet: ''
1904
      - facet: ''
1905
        marc_field: 007_/1-2
1905
        marc_field: 007_/0-1
1906
        marc_type: normarc
1906
        marc_type: normarc
1907
        sort: ~
1907
        sort: ~
1908
        suggestible: ''
1908
        suggestible: ''
Lines 1911-1922 biblios: Link Here
1911
    label: ff7-02
1911
    label: ff7-02
1912
    mappings:
1912
    mappings:
1913
      - facet: ''
1913
      - facet: ''
1914
        marc_field: 007_/3
1914
        marc_field: 007_/2
1915
        marc_type: marc21
1915
        marc_type: marc21
1916
        sort: ~
1916
        sort: ~
1917
        suggestible: ''
1917
        suggestible: ''
1918
      - facet: ''
1918
      - facet: ''
1919
        marc_field: 007_/3
1919
        marc_field: 007_/2
1920
        marc_type: normarc
1920
        marc_type: normarc
1921
        sort: ~
1921
        sort: ~
1922
        suggestible: ''
1922
        suggestible: ''
Lines 2586-2597 biblios: Link Here
2586
    label: llength
2586
    label: llength
2587
    mappings:
2587
    mappings:
2588
      - facet: ''
2588
      - facet: ''
2589
        marc_field: leader_/1-5
2589
        marc_field: leader_/0-4
2590
        marc_type: marc21
2590
        marc_type: marc21
2591
        sort: ~
2591
        sort: ~
2592
        suggestible: ''
2592
        suggestible: ''
2593
      - facet: ''
2593
      - facet: ''
2594
        marc_field: leader_/1-5
2594
        marc_field: leader_/0-4
2595
        marc_type: normarc
2595
        marc_type: normarc
2596
        sort: ~
2596
        sort: ~
2597
        suggestible: ''
2597
        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