/[webpac]/trunk2/all2all.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk2/all2all.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 178 by dpavlin, Mon Nov 24 21:54:19 2003 UTC revision 199 by dpavlin, Wed Jan 7 12:29:11 2004 UTC
# Line 72  my %lhash; Line 72  my %lhash;
72  # if you are tight on memory, turn this off  # if you are tight on memory, turn this off
73  my $use_lhash_cache = 1;  my $use_lhash_cache = 1;
74    
75    my $last_field_name;    # cache to prevent repeated fields
76    
77  sub data2xml {  sub data2xml {
78    
79          use xmlify;          use xmlify;
# Line 102  sub data2xml { Line 104  sub data2xml {
104          }          }
105    
106          my @sorted_tags;          my @sorted_tags;
107          if ($cache->{tags_by_order}->{$type}) {          if ($cache->{tags_by_order}) {
108                  @sorted_tags = @{$cache->{tags_by_order}->{$type}};                  @sorted_tags = @{$cache->{tags_by_order}};
109          } else {          } else {
110                  @sorted_tags = sort by_order keys %{$config->{indexer}};                  @sorted_tags = sort by_order keys %{$config->{indexer}};
111                  $cache->{tags_by_order}->{$type} = \@sorted_tags;                  $cache->{tags_by_order} = \@sorted_tags;
112          }          }
113    
114          # lookup key          # lookup key
115          my $lookup_key;          my $lookup_key;
116    
117          # cache for field in pages          # cache for field in pages
118          $cache->{display_data} = ();          delete $cache->{display_data};
119          $cache->{swish_data} = ();          delete $cache->{swish_data};
120          $cache->{swish_exact_data} = ();          delete $cache->{swish_exact_data};
121            delete $cache->{index_data};
122            delete $cache->{index_delimiter};
123          my @page_fields;        # names of fields          my @page_fields;        # names of fields
124    
125    
# Line 136  sub data2xml { Line 140  sub data2xml {
140                          print STDERR "WARNING: field '$field' doesn't have 'name' attribute!";                          print STDERR "WARNING: field '$field' doesn't have 'name' attribute!";
141                  }                  }
142                  if ($field_name) {                  if ($field_name) {
143                          return x($field_name);                          if (! $last_field_name) {
144                                    $last_field_name = x($field_name);
145                                    return $last_field_name;
146                            } elsif ($field_name ne $last_field_name) {
147                                    $last_field_name = x($field_name);
148                                    return $last_field_name;
149                            }
150                  }                  }
151          }          }
152    
# Line 150  sub data2xml { Line 160  sub data2xml {
160                  my $swish_data = "";                  my $swish_data = "";
161                  my $swish_exact_data = "";                  my $swish_exact_data = "";
162                  my $display_data = "";                  my $display_data = "";
163                    my @index_data;
164                  my $line_delimiter;                  my $line_delimiter;
165    
166                  my ($swish,$display);                  my ($swish,$display);
# Line 162  sub data2xml { Line 173  sub data2xml {
173                  my %page_max = ();                  my %page_max = ();
174                  # default line_delimiter if using                  # default line_delimiter if using
175                  my $page_line_delimiter = $config->{indexer}->{$field}->{page_line_delimiter} || '<br/>';                  my $page_line_delimiter = $config->{indexer}->{$field}->{page_line_delimiter} || '<br/>';
176                    $cache->{index_delimiter}->{$field} = $config->{indexer}->{$field}->{index_delimiter};
177    
178                    my $format_name = $config->{indexer}->{$field}->{format_name};
179                    my $format_delimiter = $config->{indexer}->{$field}->{format_delimiter};
180                    if ($format_name && $format_delimiter) {
181                            $cache->{format}->{$field}->{format_name} = $format_name;
182                            $cache->{format}->{$field}->{format_delimiter} = $format_delimiter;
183                    }
184    
185                  foreach my $x (@{$config->{indexer}->{$field}->{$tag}}) {                  foreach my $x (@{$config->{indexer}->{$field}->{$tag}}) {
186    
# Line 175  sub data2xml { Line 194  sub data2xml {
194                          my ($s,$se,$d,$i,$il) = (1,0,1,0,0);                          my ($s,$se,$d,$i,$il) = (1,0,1,0,0);
195                          $s = 0 if (lc($x->{type}) eq "display");                          $s = 0 if (lc($x->{type}) eq "display");
196                          $d = 0 if (lc($x->{type}) eq "swish");                          $d = 0 if (lc($x->{type}) eq "swish");
197                          $se = 1 if (lc($x->{type}) eq "swish_exact");                          ($s,$se,$d,$i) = (0,1,0,1) if (lc($x->{type}) eq "index");
198                          ($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index");                          ($s,$se,$d,$i) = (0,1,0,0) if (lc($x->{type}) eq "swish_exact");
199                          $il = 1 if (lc($x->{type}) =~ /^lookup/);                          ($s,$se,$d,$i,$il) = (0,1,0,0,1) if (lc($x->{type}) =~ /^lookup/);
   
200    
201                          # what will separate last line from this one?                          # what will separate last line from this one?
202                          if ($display_data && $x->{append} && $x->{append} eq "1") {                          if ($display_data && $x->{append}) {
203                                  $line_delimiter = ' ';                                  $line_delimiter = ' ';
204                          } elsif ($display_data) {                          } elsif ($display_data) {
205                                  $line_delimiter = '<br/>';                                  $line_delimiter = '<br/>';
# Line 191  sub data2xml { Line 209  sub data2xml {
209                          ($swish,$display) = (1,1);                          ($swish,$display) = (1,1);
210    
211                          # placeholder for all repeatable entries for index                          # placeholder for all repeatable entries for index
                         my @index_data;  
212    
213                          sub mkformat {                          sub mkformat($$) {
214                                  my $x = shift || die "mkformat needs tag reference";                                  my $x = shift || die "mkformat needs tag reference";
215                                  my $data = shift || return;                                  my $data = shift || return;
216                                  my $format_name = x($x->{format_name}) || return $data;                                  my $format_name = x($x->{format_name}) || return $data;
# Line 265  sub data2xml { Line 282  sub data2xml {
282                                                  no strict 'refs';                                                  no strict 'refs';
283                                                  my $tmp = join(" ",&$filter($swish)) if ($s || $se);                                                  my $tmp = join(" ",&$filter($swish)) if ($s || $se);
284                                                  $swish_data .= $tmp if ($s);                                                  $swish_data .= $tmp if ($s);
285                                                  $swish_exact_data .= $tmp if ($se);                                                  $swish_exact_data .= "xxbxx $tmp xxexx " if ($se && $tmp ne "");
286    
287                                          } else {                                          } else {
288                                                  $swish_data .= $swish if ($s);                                                  $swish_data .= $swish if ($s);
289                                                  $swish_exact_data .= $swish if ($se);                                                  $swish_exact_data .= "xxbxx $swish xxexx " if ($se && $swish ne "");
290                                          }                                          }
291                                  }                                  }
292    
# Line 281  sub data2xml { Line 298  sub data2xml {
298                                          if ($filter) {                                          if ($filter) {
299                                                  no strict 'refs';                                                  no strict 'refs';
300                                                  if ($display_data) {                                                  if ($display_data) {
301                                                          $display_data .= $delimiter.join($delimiter,mkformat($x,&$filter($display)));                                                          $display_data .= $delimiter.mkformat($x,join($delimiter,&$filter($display)));
302                                                  } else {                                                  } else {
303                                                          $display_data = join($delimiter,mkformat($x,&$filter($display)));                                                          $display_data = mkformat($x,join($delimiter,&$filter($display)));
304                                                  }                                                  }
305                                          } else {                                          } else {
306                                                  if ($display_data) {                                                  if ($display_data) {
# Line 295  sub data2xml { Line 312  sub data2xml {
312                                  }                                  }
313                                                                                                    
314                                  # type="index" ; insert into index                                  # type="index" ; insert into index
315                                    my $idisplay;
316                                  if ($i && $display) {                                  if ($i && $display) {
317                                            $idisplay = $display;
318                                          if ($filter) {                                          if ($filter) {
319                                                  no strict 'refs';                                                  no strict 'refs';
320                                                  $display = &$filter($display);                                                  $idisplay = &$filter($idisplay);
                                         }  
                                         if ($x->{append} && @index_data) {  
                                                 $index_data[$#index_data].=$display;  
                                         } else {  
                                                 push @index_data, $display;  
321                                          }                                          }
322                                            push @index_data, $idisplay if (! $iterate_by_page);
323                                  }                                  }
324    
325                                  # store fields in lookup                                  # store fields in lookup
# Line 330  sub data2xml { Line 345  sub data2xml {
345                                          sub iterate_fld($$$$$$) {                                          sub iterate_fld($$$$$$) {
346                                                  my ($cache,$what,$field,$page,$data,$append) = @_;                                                  my ($cache,$what,$field,$page,$data,$append) = @_;
347                                                  return if (!$data);                                                  return if (!$data);
348                                                  my $line_delimiter = $page_line_delimiter;  
349                                                  $line_delimiter = " " if ($append);                                                  my $ldel = $page_line_delimiter;
350                                                    $ldel = " " if ($append);
351    #print STDERR "line delimiter: ",Dumper($ldel) if ($ldel);
352                                                  if (! $cache->{$what}->{$field}->[$page]) {                                                  if (! $cache->{$what}->{$field}->[$page]) {
353                                                          $cache->{$what}->{$field}->[$page] = $data;                                                          $cache->{$what}->{$field}->[$page] = $data;
354                                                  } else {                                                  } else {
355                                                          $cache->{$what}->{$field}->[$page] .= $line_delimiter.$data;                                                          $cache->{$what}->{$field}->[$page] .= $ldel.$data;
356                                                  }                                                  }
357                                          }                                          }
358    
359                                          if ($display_data) {                                          if ($display_data) {
 print STDERR "line delimiter: ",Dumper($line_delimiter) if ($line_delimiter);  
360                                                  iterate_fld($cache,'display_data',$field,$page,$display_data,$x->{append});                                                  iterate_fld($cache,'display_data',$field,$page,$display_data,$x->{append});
361                                          }                                          }
362                                                  $display_data = "";                                                  $display_data = "";
# Line 352  print STDERR "line delimiter: ",Dumper($ Line 368  print STDERR "line delimiter: ",Dumper($
368                                                  iterate_fld($cache,'swish_exact_data',$field,$page,$swish_exact_data,$x->{append});                                                  iterate_fld($cache,'swish_exact_data',$field,$page,$swish_exact_data,$x->{append});
369                                                  $swish_exact_data = "";                                                  $swish_exact_data = "";
370                                          }                                          }
371    
372                                            if ($idisplay) {
373                                                    my $ldel=$page_line_delimiter;
374                                                    my @index_data;
375                                                    if ($cache->{index_data}->{$field}->[$page]) {
376    
377                                                            @index_data = @{$cache->{index_data}->{$field}->[$page]};
378                                                    }
379                                                    if ($x->{append}) {
380                                                            if (@index_data) {
381                                                                    $index_data[$#index_data] .= $idisplay;
382                                                            } else {
383                                                                    push @index_data, $idisplay;
384                                                            }
385                                                    } else {
386                                                            push @index_data, $idisplay;
387                                                    }
388                                                    $idisplay = "";
389                                                    @{$cache->{index_data}->{$field}->[$page]} = @index_data;
390                                            }
391                                  }                                  }
392                          }                          }
393    
394                          # fill data in index                          if (! $iterate_by_page) {
395                          foreach my $d (@index_data) {                                  my $idel = $x->{index_delimiter};
396                                  $index->insert($field, $d, $path);                                  # fill data in index
397                                    foreach my $tmp (@index_data) {
398                                            my $i = $d = $tmp;
399                                            if ($idel && $tmp =~ m/$idel/) {
400                                                    ($i,$d) = split(/$idel/,$tmp);
401                                            }
402                                            $index->insert($field, $i, $d, $path);
403                                    }
404                                    @index_data = ();
405                          }                          }
406                  }                  }
407    
# Line 405  print STDERR "line delimiter: ",Dumper($ Line 449  print STDERR "line delimiter: ",Dumper($
449  #print STDERR "field '$field' iterate over ",($nr_pages || 0)," pages...\n";  #print STDERR "field '$field' iterate over ",($nr_pages || 0)," pages...\n";
450  #print STDERR Dumper($cache->{display_data});  #print STDERR Dumper($cache->{display_data});
451                          for (my $page=0; $page <= $nr_pages; $page++) {                          for (my $page=0; $page <= $nr_pages; $page++) {
452                                    my $display_data;
453                                  my $display_data = $cache->{display_data}->{$field}->[$page];                                  if ($cache->{format}->{$field}) {
454                                            $display_data=mkformat($cache->{format}->{$field},$cache->{display_data}->{$field}->[$page]);
455                                    } else {
456                                            $display_data = $cache->{display_data}->{$field}->[$page];
457                                    }
458                                  if ($display_data) { # default                                  if ($display_data) { # default
459                                          if ($field eq "headline") {                                          if ($field eq "headline") {
460                                                  $xml .= xmlify("headline", $display_data);                                                  $xml .= xmlify("headline", $display_data);
# Line 434  print STDERR "line delimiter: ",Dumper($ Line 482  print STDERR "line delimiter: ",Dumper($
482    
483                                          # add delimiters before and after word.                                          # add delimiters before and after word.
484                                          # That is required to produce exact match                                          # That is required to produce exact match
485                                          $xml .= xmlify($field."_swish_exact", unac_string($codepage,'xxbxx '.$swish_exact_data.' xxexx'));                                          $xml .= xmlify($field."_swish_exact", unac_string($codepage,$swish_exact_data));
486                                    }
487                                    
488                                    my $idel = $cache->{index_delimiter}->{$field};
489                                    foreach my $tmp (@{$cache->{index_data}->{$field}->[$page]}) {
490                                            my $i = $tmp;
491                                            my $d = $tmp;
492                                            if ($idel && $tmp =~ m/$idel/) {
493                                                    ($i,$d) = split(/$idel/,$tmp);
494                                            }
495                                            $index->insert($field, $i, $d, $path);
496    #print STDERR "index [$idel] $field: $i --> $d [$path]\n";
497                                  }                                  }
498                          }                          }
499                    
# Line 465  print STDERR "line delimiter: ",Dumper($ Line 524  print STDERR "line delimiter: ",Dumper($
524    
525                                  # add delimiters before and after word.                                  # add delimiters before and after word.
526                                  # That is required to produce exact match                                  # That is required to produce exact match
527                                  $xml .= xmlify($field."_swish_exact", unac_string($codepage,'xxbxx '.$swish_exact_data.' xxexx'));                                  $xml .= xmlify($field."_swish_exact", unac_string($codepage,$swish_exact_data));
528                          }                          }
529                  }                  }
530          }          }
# Line 566  print STDERR "reading ./import_xml/$type Line 625  print STDERR "reading ./import_xml/$type
625          # now read database          # now read database
626  print STDERR "using: $type...\n";  print STDERR "using: $type...\n";
627    
628            # erase cache for tags by order in this database
629            delete $cache->{tags_by_order};
630    
631          if ($type_base eq "isis") {          if ($type_base eq "isis") {
632    
633                  my $isis_db = $cfg -> val($database, 'isis_db') || die "$database doesn't have 'isis_db' defined!";                  my $isis_db = $cfg -> val($database, 'isis_db') || die "$database doesn't have 'isis_db' defined!";

Legend:
Removed from v.178  
changed lines
  Added in v.199

  ViewVC Help
Powered by ViewVC 1.1.26