6 use C4::AuthoritiesMarc;
10 # script that fills the nozebra table
14 $|=1; # flushes output
16 # limit for database dumping
17 my $limit;# = "LIMIT 1000";
33 $directory = "export" unless $directory;
34 my $dbh=C4::Context->dbh;
35 $dbh->do("update systempreferences set value=1 where variable='NoZebra'");
36 $dbh->do("CREATE TABLE `nozebra` (
37 `indexname` varchar(40) character set latin1 NOT NULL,
38 `value` varchar(250) character set latin1 NOT NULL,
39 `biblionumbers` longtext character set latin1 NOT NULL,
40 KEY `indexname` (`indexname`),
41 KEY `value` (`value`))
42 ENGINE=InnoDB DEFAULT CHARSET=utf8");
43 $dbh->do("truncate nozebra");
45 $sth=$dbh->prepare("select biblionumber from biblioitems order by biblionumber $limit");
51 'title' => '200a,200c,200d,200e,225a,225d,225e,225f,225h,225i,225v,500*,501*,503*,510*,512*,513*,514*,515*,516*,517*,518*,519*,520*,530*,531*,532*,540*,541*,545*,604t,610t,605a',
52 'author' =>'200f,600a,601a,604a,700a,700b,700c,700d,700a,701b,701c,701d,702a,702b,702c,702d,710a,710b,710c,710d,711a,711b,711c,711d,712a,712b,712c,712d',
55 'biblionumber' =>'0909',
58 'publisher' => '210x',
60 'note' => '300a,301a,302a,303a,304a,305a,306az,307a,308a,309a,310a,311a,312a,313a,314a,315a,316a,317a,318a,319a,320a,321a,322a,323a,324a,325a,326a,327a,328a,330a,332a,333a,336a,337a,345a',
61 'Koha-Auth-Number' => '6009,6019,6029,6039,6049,6059,6069,6109',
62 'subject' => '600*,601*,606*,610*',
64 'host-item' => '995a,995c',
68 while (my ($biblionumber) = $sth->fetchrow) {
71 my $record = GetMarcBiblio($biblionumber);
73 # get title of the record (to store the 10 first letters with the index)
75 if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
76 $title = lc($record->subfield('200','a'));
78 $title = lc($record->subfield('245','a'));
80 # remove blancks comma (that could cause problem when decoding the string for CQL retrieval) and regexp specific values
81 $title =~ s/ |,|;|\[|\]|\(|\)|\*//g;
82 # limit to 10 char, should be enough, and limit the DB size
83 $title = substr($title,0,10);
85 foreach my $field ($record->fields()) {
87 next if $field->tag <10;
88 foreach my $subfield ($field->subfields()) {
89 my $tag = $field->tag();
90 my $subfieldcode = $subfield->[0];
92 # check each index to see if the subfield is stored somewhere
93 # otherwise, store it in __RAW__ index
94 foreach my $key (keys %index) {
95 if ($index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfield/) {
97 my $line= lc $subfield->[1];
98 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\// /g;
99 foreach (split / /,$line) {
100 # see if the entry is already here
101 if ($result{$key}->{$_} =~ /$biblionumber,$title\-(\d);/) {
103 $result{$key}->{$_} =~ s/$biblionumber,$title\-(\d);//;
104 $result{$key}->{$_} .= "$biblionumber,$title-$weight;";
106 $result{$key}->{$_}.="$biblionumber,$title-1;";
111 # the subfield is not indexed, store it in __RAW__ index anyway
113 my $line= lc $subfield->[1];
114 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\// /g;
115 foreach (split / /,$line) {
116 # warn $record->as_formatted."$_ =>".$title;
117 if ($result{__RAW__}->{$_} =~ /$biblionumber,$title\-(\d);/) {
120 $result{__RAW__}->{$_} =~ s/$biblionumber,$title\-(\d);//;
121 $result{__RAW__}->{$_} .= "$biblionumber,$title-$weight;";
123 $result{__RAW__}->{$_}.="$biblionumber,$title-1;";
130 my $sth = $dbh->prepare("INSERT INTO nozebra (indexname,value,biblionumbers) VALUES (?,?,?)");
131 foreach my $key (keys %result) {
132 foreach my $index (keys %{$result{$key}}) {
133 $sth->execute($key,$index,$result{$key}->{$index});
134 if (length($result{$key}->{$index}) >40000) {
135 print length($result{$key}->{$index})." for $key / $index";