/[webpac]/trunk/all2xml.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 /trunk/all2xml.pl

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

revision 182 by dpavlin, Sat Nov 29 15:59:19 2003 UTC revision 196 by dpavlin, Mon Dec 15 00:12:16 2003 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 117  sub data2xml { Line 119  sub data2xml {
119          delete $cache->{swish_data};          delete $cache->{swish_data};
120          delete $cache->{swish_exact_data};          delete $cache->{swish_exact_data};
121          delete $cache->{index_data};          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 137  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 164  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 177  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                          ($s,$se,$d,$i) = (0,0,0,1) if (lc($x->{type}) eq "index");                          ($s,$se,$d,$i) = (0,1,0,1) if (lc($x->{type}) eq "index");
198                          ($s,$se,$d,$i) = (0,1,0,0) if (lc($x->{type}) eq "swish_exact");                          ($s,$se,$d,$i) = (0,1,0,0) if (lc($x->{type}) eq "swish_exact");
199                          ($s,$se,$d,$i,$il) = (0,1,0,0,1) if (lc($x->{type}) =~ /^lookup/);                          ($s,$se,$d,$i,$il) = (0,1,0,0,1) if (lc($x->{type}) =~ /^lookup/);
200    
# Line 193  sub data2xml { Line 210  sub data2xml {
210    
211                          # placeholder for all repeatable entries for index                          # placeholder for all repeatable entries for index
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);                                                  if ($se) {
286                                                            if ($swish_exact_data) {
287                                                                    $swish_exact_data .= "xxexx xxbxx ".$tmp;
288                                                            } else {
289                                                                    $swish_exact_data .= $tmp;
290                                                            }
291                                                    }
292    
293                                          } else {                                          } else {
294                                                  $swish_data .= $swish if ($s);                                                  $swish_data .= $swish if ($s);
295                                                  $swish_exact_data .= $swish if ($se);                                                  if ($se) {
296                                                            if ($swish_exact_data) {
297                                                                    $swish_exact_data .= "xxexx xxbxx ".$swish;
298                                                            } else {
299                                                                    $swish_exact_data .= $swish;
300                                                            }
301                                                    }
302                                          }                                          }
303                                  }                                  }
304    
# Line 360  sub data2xml { Line 389  sub data2xml {
389                                                          @index_data = @{$cache->{index_data}->{$field}->[$page]};                                                          @index_data = @{$cache->{index_data}->{$field}->[$page]};
390                                                  }                                                  }
391                                                  if ($x->{append}) {                                                  if ($x->{append}) {
392                                                          $index_data[$#index_data] .= $idisplay;                                                          if (@index_data) {
393                                                                    $index_data[$#index_data] .= $idisplay;
394                                                            } else {
395                                                                    push @index_data, $idisplay;
396                                                            }
397                                                  } else {                                                  } else {
398                                                          push @index_data, $idisplay;                                                          push @index_data, $idisplay;
399                                                  }                                                  }
# Line 371  sub data2xml { Line 404  sub data2xml {
404                          }                          }
405    
406                          if (! $iterate_by_page) {                          if (! $iterate_by_page) {
407                                    my $idel = $x->{index_delimiter};
408                                  # fill data in index                                  # fill data in index
409                                  foreach my $d (@index_data) {                                  foreach my $tmp (@index_data) {
410                                          $index->insert($field, $d, $path);                                          my $i = $d = $tmp;
411                                            if ($idel && $tmp =~ m/$idel/) {
412                                                    ($i,$d) = split(/$idel/,$tmp);
413                                            }
414                                            $index->insert($field, $i, $d, $path);
415                                  }                                  }
416                                  @index_data = ();                                  @index_data = ();
417                          }                          }
# Line 423  sub data2xml { Line 461  sub data2xml {
461  #print STDERR "field '$field' iterate over ",($nr_pages || 0)," pages...\n";  #print STDERR "field '$field' iterate over ",($nr_pages || 0)," pages...\n";
462  #print STDERR Dumper($cache->{display_data});  #print STDERR Dumper($cache->{display_data});
463                          for (my $page=0; $page <= $nr_pages; $page++) {                          for (my $page=0; $page <= $nr_pages; $page++) {
464                                    my $display_data;
465                                  my $display_data = $cache->{display_data}->{$field}->[$page];                                  if ($cache->{format}->{$field}) {
466                                            $display_data=mkformat($cache->{format}->{$field},$cache->{display_data}->{$field}->[$page]);
467                                    } else {
468                                            $display_data = $cache->{display_data}->{$field}->[$page];
469                                    }
470                                  if ($display_data) { # default                                  if ($display_data) { # default
471                                          if ($field eq "headline") {                                          if ($field eq "headline") {
472                                                  $xml .= xmlify("headline", $display_data);                                                  $xml .= xmlify("headline", $display_data);
# Line 455  sub data2xml { Line 497  sub data2xml {
497                                          $xml .= xmlify($field."_swish_exact", unac_string($codepage,'xxbxx '.$swish_exact_data.' xxexx'));                                          $xml .= xmlify($field."_swish_exact", unac_string($codepage,'xxbxx '.$swish_exact_data.' xxexx'));
498                                  }                                  }
499                                                                    
500                                  foreach my $d (@{$cache->{index_data}->{$field}->[$page]}) {                                  my $idel = $cache->{index_delimiter}->{$field};
501                                          $index->insert($field, $d, $path);                                  foreach my $tmp (@{$cache->{index_data}->{$field}->[$page]}) {
502  #print STDERR "index $field: $d [$path]\n";                                          my $i = $tmp;
503                                            my $d = $tmp;
504                                            if ($idel && $tmp =~ m/$idel/) {
505                                                    ($i,$d) = split(/$idel/,$tmp);
506                                            }
507                                            $index->insert($field, $i, $d, $path);
508    #print STDERR "index [$idel] $field: $i --> $d [$path]\n";
509                                  }                                  }
510                          }                          }
511                    

Legend:
Removed from v.182  
changed lines
  Added in v.196

  ViewVC Help
Powered by ViewVC 1.1.26