6 use C4::AuthoritiesMarc;
10 # script that fills the nozebra table
14 $|=1; # flushes output
16 # limit for database dumping
17 my $limit;# = "LIMIT 100";
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");
50 my %index = GetNoZebraIndexes();
53 if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
54 $dbh->do("UPDATE systempreferences SET value=\"'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',
55 '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',
58 'biblionumber' =>'0909',
61 'publisher' => '210x',
63 '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',
64 'Koha-Auth-Number' => '6009,6019,6029,6039,6049,6059,6069,6109',
65 'subject' => '600*,601*,606*,610*',
67 'host-item' => '995a,995c',\" where variable='NoZebraIndexes'");
68 %index = GetNoZebraIndexes();
70 # build a MARC21 default index file
74 while (my ($biblionumber) = $sth->fetchrow) {
77 my $record = GetMarcBiblio($biblionumber);
79 # get title of the record (to store the 10 first letters with the index)
80 my ($titletag,$titlesubfield) = GetMarcFromKohaField('biblio.title');
81 my $title = lc($record->subfield($titletag,$titlesubfield));
83 # remove blancks comma (that could cause problem when decoding the string for CQL retrieval) and regexp specific values
84 $title =~ s/ |,|;|\[|\]|\(|\)|\*|-|'|=//g;
85 # limit to 10 char, should be enough, and limit the DB size
86 $title = substr($title,0,10);
88 foreach my $field ($record->fields()) {
90 next if $field->tag <10;
91 foreach my $subfield ($field->subfields()) {
92 my $tag = $field->tag();
93 my $subfieldcode = $subfield->[0];
95 # check each index to see if the subfield is stored somewhere
96 # otherwise, store it in __RAW__ index
97 foreach my $key (keys %index) {
98 if ($index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfieldcode/) {
100 my $line= lc $subfield->[1];
101 # remove meaningless value in the field...
102 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=/ /g;
103 # ... and split in words
104 foreach (split / /,$line) {
105 next unless $_; # skip empty values (multiple spaces)
106 # if the entry is already here, improve weight
107 if ($result{$key}->{$_} =~ /$biblionumber,$title\-(\d);/) {
109 $result{$key}->{$_} =~ s/$biblionumber,$title\-(\d);//;
110 $result{$key}->{$_} .= "$biblionumber,$title-$weight;";
111 # otherwise, create it, with weight=1
113 $result{$key}->{$_}.="$biblionumber,$title-1;";
118 # the subfield is not indexed, store it in __RAW__ index anyway
120 my $line= lc $subfield->[1];
121 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=/ /g;
122 foreach (split / /,$line) {
124 # warn $record->as_formatted."$_ =>".$title;
125 if ($result{__RAW__}->{$_} =~ /$biblionumber,$title\-(\d);/) {
128 $result{__RAW__}->{$_} =~ s/$biblionumber,$title\-(\d);//;
129 $result{__RAW__}->{$_} .= "$biblionumber,$title-$weight;";
131 $result{__RAW__}->{$_}.="$biblionumber,$title-1;";
138 my $sth = $dbh->prepare("INSERT INTO nozebra (indexname,value,biblionumbers) VALUES (?,?,?)");
139 foreach my $key (keys %result) {
140 foreach my $index (keys %{$result{$key}}) {
141 if (length($result{$key}->{$index}) > 1000000) {
142 print "very long index (".length($result{$key}->{$index}).")for $key / $index. update mySQL config file if you have an error just after this warning (max_paquet_size parameter)\n";
144 $sth->execute($key,$index,$result{$key}->{$index});