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("truncate nozebra");
37 $sth=$dbh->prepare("select biblionumber from biblioitems order by biblionumber $limit");
43 'title' => '200a,200c,200d',
44 'author' =>'200f,700*,701*,702*'
48 while (my ($biblionumber) = $sth->fetchrow) {
51 my $record = GetMarcBiblio($biblionumber);
53 # get title of the record (to store the 10 first letters with the index)
55 if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
56 $title = lc($record->subfield('200','a'));
58 $title = lc($record->subfield('245','a'));
60 # remove blancks and comma (that could cause problem when decoding the string for CQL retrieval
62 # limit to 10 char, should be enough, and limit the DB size
63 $title = substr($title,0,10);
65 foreach my $field ($record->fields()) {
67 next if $field->tag <10;
68 foreach my $subfield ($field->subfields()) {
69 my $tag = $field->tag();
70 my $subfieldcode = $subfield->[0];
72 # check each index to see if the subfield is stored somewhere
73 # otherwise, store it in __RAW__ index
74 foreach my $key (keys %index) {
75 if ($index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfield/) {
77 my $line= lc $subfield->[1];
78 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\// /g;
79 foreach (split / /,$line) {
80 $result{$key}->{$_}.="$biblionumber;$title," unless $subfield->[0] eq '9';
84 # the subfield is not indexed, store it in __RAW__ index anyway
86 my $line= lc $subfield->[1];
87 $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\// /g;
88 foreach (split / /,$line) {
89 $result{'__RAW__'}->{$_}.="$biblionumber;$title," unless $subfield->[0] eq '9';
95 my $sth = $dbh->prepare("INSERT INTO nozebra (indexname,value,biblionumbers) VALUES (?,?,?)");
96 foreach my $key (keys %result) {
97 foreach my $index (keys %{$result{$key}}) {
98 $sth->execute($key,$index,$result{$key}->{$index});