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

(-)a/misc/migration_tools/dedup_authorities.pl (-44 / +29 lines)
Lines 6-12 use C4::Biblio; Link Here
6
use C4::Search;
6
use C4::Search;
7
use C4::Charset;
7
use C4::Charset;
8
use C4::Debug;
8
use C4::Debug;
9
use C4::ZebraIndex;
10
9
11
use Getopt::Long;
10
use Getopt::Long;
12
use YAML;
11
use YAML;
Lines 24-43 Use this script to remove duplicate authorities. Link Here
24
23
25
my @matchstrings;
24
my @matchstrings;
26
my $choosemethod = "u";   # by default, choose to keep the most used authority
25
my $choosemethod = "u";   # by default, choose to keep the most used authority
27
my ($verbose, $all, $help, $wherestring, $test);
26
my ($all, $help, $wherestring, $test);
27
my $verbose = 0;
28
28
29
# default is to check all these subfields for 'auth_tag_to_report'
29
# default is to check all these subfields for 'auth_tag_to_report'
30
my $check = 'TAGabcdefghitxyz';
30
my $check = 'TAGabcdefghitxyz';
31
31
32
my $result = GetOptions (
32
my $result = GetOptions (
33
    "match=s"   => \@matchstrings
33
    "match=s"   => \@matchstrings,
34
    , "verbose+"  => \$verbose
34
    "verbose+"  => \$verbose,
35
    , "all|a"  => \$all
35
    "all|a"  => \$all,
36
    , "test|t"  => \$test
36
    "test|t"  => \$test,
37
    , "help|h"   => \$help
37
    "help|h"   => \$help,
38
    , "where=s"   => \$wherestring
38
    "where=s"   => \$wherestring,
39
    , "choose-method=s" => \$choosemethod
39
    "choose-method=s" => \$choosemethod,
40
    , "check=s" => \$check
40
    "check=s" => \$check
41
);
41
);
42
42
43
if ( $help || ! (@ARGV || $all)) {
43
if ( $help || ! (@ARGV || $all)) {
Lines 47-65 if ( $help || ! (@ARGV || $all)) { Link Here
47
47
48
my @choose_subs;
48
my @choose_subs;
49
foreach (split //, $choosemethod) {
49
foreach (split //, $choosemethod) {
50
    given($_) {
50
    if ($_  eq 'd') {
51
        when ('d') {
51
        push @choose_subs, \&_get_date;
52
            push @choose_subs, \&_get_date;
52
    }
53
        }
53
    elsif( $_ eq 'p') {
54
        when ('p') {
54
        push @choose_subs, \&_has_ppn;
55
            push @choose_subs, \&_has_ppn;
55
    }
56
        }
56
    elsif( $_ eq 'u') {
57
        when ('u') {
57
        push @choose_subs, \&_get_usage;
58
            push @choose_subs, \&_get_usage;
58
    }
59
        }
59
    else {
60
        default {
60
        warn "Choose method '$_' is not supported";
61
            warn "Choose method '$_' is not supported";
62
        }
63
    }
61
    }
64
}
62
}
65
63
Lines 153-162 for my $authtypecode (@authtypecodes) { Link Here
153
            ($verbose >= 2) and logger("Building query...");
151
            ($verbose >= 2) and logger("Building query...");
154
            my $query = _build_query( $authrecord, $attempt );
152
            my $query = _build_query( $authrecord, $attempt );
155
            ($verbose >= 2) and logger("Building query done.");
153
            ($verbose >= 2) and logger("Building query done.");
156
            ($verbose >= 2) and logger ($query);
154
            ($verbose >= 2) and logger ("$query");
157
            # This prevent too general queries to be executed
155
            # This prevent too general queries to be executed
158
            # TODO: This should allow more than these 3 indexes
156
            # TODO: This should allow more than these 3 indexes
159
            next unless $query =~ /(ppn|he|he-main|ident)(,\S*)*(=|:)/;
157
#            next unless $query =~ /(ppn|he|heading-main|ident)(,\S*)*(=|:)/;
160
158
161
            ($verbose >= 2) and logger("Searching...");
159
            ($verbose >= 2) and logger("Searching...");
162
            my ($error, $results) = SimpleSearch($query, undef, undef, ["authorityserver"]);
160
            my ($error, $results) = SimpleSearch($query, undef, undef, ["authorityserver"]);
Lines 191-196 for my $authtypecode (@authtypecodes) { Link Here
191
                            $biblios{$biblio} = 1;
189
                            $biblios{$biblio} = 1;
192
                        }
190
                        }
193
                        $authorities{$localauthid} = 2;
191
                        $authorities{$localauthid} = 2;
192
                        logger("Deleting $localauthid");
193
                        DelAuthority({ authid => $localauthid, skip_merge => 1 });
194
                    }
194
                    }
195
                }
195
                }
196
                ($verbose >= 2) and logger("Merge done.");
196
                ($verbose >= 2) and logger("Merge done.");
Lines 214-244 for my $authtypecode (@authtypecodes) { Link Here
214
my @biblios_to_update = grep {defined $biblios{$_} and $biblios{$_} == 1}
214
my @biblios_to_update = grep {defined $biblios{$_} and $biblios{$_} == 1}
215
                            keys %biblios;
215
                            keys %biblios;
216
if( @biblios_to_update > 0 ) {
216
if( @biblios_to_update > 0 ) {
217
    logger("Updating biblios index (" . scalar(@biblios_to_update) . " biblios to update)");
217
    logger("Updated " . scalar(@biblios_to_update) . " biblios");
218
    C4::ZebraIndex::IndexRecord("biblio", \@biblios_to_update,
219
        { as_xml => 1, record_format => "marcxml" });
220
} else {
218
} else {
221
    logger("No biblios to update");
219
    logger("No biblios to update");
222
}
220
}
223
221
224
# Update authorities
225
my @authorities_to_update = grep{defined $authorities{$_} and $authorities{$_} == 1}
226
                                keys %authorities;
227
if( @authorities_to_update > 0 ) {
228
    logger("Updating authorities index (" . scalar(@authorities_to_update) . " authorities to update)");
229
    C4::ZebraIndex::IndexRecord("authority", \@authorities_to_update,
230
        { as_xml => 1, record_format => "marcxml" });
231
} else {
232
    logger("No autorities to update");
233
}
234
222
235
# Delete authorities
223
# Delete authorities
236
my @authorities_to_delete = grep{defined $authorities{$_} and $authorities{$_} == 2}
224
my @authorities_to_delete = grep{defined $authorities{$_} and $authorities{$_} == 2}
237
                                keys %authorities;
225
                                keys %authorities;
238
if( @authorities_to_delete > 0 ) {
226
if( @authorities_to_delete > 0 ) {
239
    logger("Deleting authorities from index (" . scalar(@authorities_to_delete) . " authorities to delete)");
227
    logger("Deleted " . scalar(@authorities_to_delete) . " authorities");
240
    C4::ZebraIndex::DeleteRecordIndex("authority", \@authorities_to_delete,
241
        { as_xml => 1, record_format => "marcxml" });
242
} else {
228
} else {
243
    logger("No authorities to delete");
229
    logger("No authorities to delete");
244
}
230
}
Lines 296-308 sub prepare_strings{ Link Here
296
            }
282
            }
297
        }
283
        }
298
        else {
284
        else {
299
            if ($attempt->{subfields}){
285
            if (scalar @{$attempt->{subfields}} ){
300
                for my $subfield (@{$attempt->{subfields}}){
286
                for my $subfield (@{$attempt->{subfields}}){
301
                    push @stringstosearch, trim(map { NormalizeString($_, undef, 1) } $field->subfield($subfield));
287
                    push @stringstosearch, trim(map { NormalizeString($_, undef, 1) } $field->subfield($subfield));
302
                }
288
                }
303
            }
289
            }
304
            else {
290
            else {
305
                push @stringstosearch,  trim(map { NormalizeString($_, undef, 1) } $field->as_string());
291
                push @stringstosearch,  trim(map { NormalizeString($_, undef, 1) } ($field->as_string()) );
306
            }
292
            }
307
293
308
        }
294
        }
309
- 

Return to bug 13706