/[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 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 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);                                                  $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 360  sub data2xml { Line 377  sub data2xml {
377                                                          @index_data = @{$cache->{index_data}->{$field}->[$page]};                                                          @index_data = @{$cache->{index_data}->{$field}->[$page]};
378                                                  }                                                  }
379                                                  if ($x->{append}) {                                                  if ($x->{append}) {
380                                                          $index_data[$#index_data] .= $idisplay;                                                          if (@index_data) {
381                                                                    $index_data[$#index_data] .= $idisplay;
382                                                            } else {
383                                                                    push @index_data, $idisplay;
384                                                            }
385                                                  } else {                                                  } else {
386                                                          push @index_data, $idisplay;                                                          push @index_data, $idisplay;
387                                                  }                                                  }
# Line 371  sub data2xml { Line 392  sub data2xml {
392                          }                          }
393    
394                          if (! $iterate_by_page) {                          if (! $iterate_by_page) {
395                                    my $idel = $x->{index_delimiter};
396                                  # fill data in index                                  # fill data in index
397                                  foreach my $d (@index_data) {                                  foreach my $tmp (@index_data) {
398                                          $index->insert($field, $d, $path);                                          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 = ();                                  @index_data = ();
405                          }                          }
# Line 423  sub data2xml { Line 449  sub data2xml {
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 452  sub data2xml { Line 482  sub data2xml {
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                                  foreach my $d (@{$cache->{index_data}->{$field}->[$page]}) {                                  my $idel = $cache->{index_delimiter}->{$field};
489                                          $index->insert($field, $d, $path);                                  foreach my $tmp (@{$cache->{index_data}->{$field}->[$page]}) {
490  #print STDERR "index $field: $d [$path]\n";                                          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 488  sub data2xml { Line 524  sub data2xml {
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          }          }

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

  ViewVC Help
Powered by ViewVC 1.1.26