make index with lookup field working with iterate on page
[webpac] / all2xml.pl
index 8ff7d56..ee276f6 100755 (executable)
@@ -116,6 +116,7 @@ sub data2xml {
        delete $cache->{display_data};
        delete $cache->{swish_data};
        delete $cache->{swish_exact_data};
+       delete $cache->{index_data};
        my @page_fields;        # names of fields
 
 
@@ -150,6 +151,7 @@ sub data2xml {
                my $swish_data = "";
                my $swish_exact_data = "";
                my $display_data = "";
+               my @index_data;
                my $line_delimiter;
 
                my ($swish,$display);
@@ -177,10 +179,10 @@ sub data2xml {
                        $d = 0 if (lc($x->{type}) eq "swish");
                        ($s,$se,$d,$i) = (0,0,0,1) if (lc($x->{type}) eq "index");
                        ($s,$se,$d,$i) = (0,1,0,0) if (lc($x->{type}) eq "swish_exact");
-                       $il = 1 if (lc($x->{type}) =~ /^lookup/);
+                       ($s,$se,$d,$i,$il) = (0,1,0,0,1) if (lc($x->{type}) =~ /^lookup/);
 
                        # what will separate last line from this one?
-                       if ($display_data && $x->{append} && $x->{append} eq "1") {
+                       if ($display_data && $x->{append}) {
                                $line_delimiter = ' ';
                        } elsif ($display_data) {
                                $line_delimiter = '<br/>';
@@ -190,7 +192,6 @@ sub data2xml {
                        ($swish,$display) = (1,1);
 
                        # placeholder for all repeatable entries for index
-                       my @index_data;
 
                        sub mkformat {
                                my $x = shift || die "mkformat needs tag reference";
@@ -294,16 +295,14 @@ sub data2xml {
                                }
                                                
                                # type="index" ; insert into index
+                               my $idisplay;
                                if ($i && $display) {
+                                       $idisplay = $display;
                                        if ($filter) {
                                                no strict 'refs';
-                                               $display = &$filter($display);
-                                       }
-                                       if ($x->{append} && @index_data) {
-                                               $index_data[$#index_data].=$display;
-                                       } else {
-                                               push @index_data, $display;
+                                               $idisplay = &$filter($idisplay);
                                        }
+                                       push @index_data, $idisplay if (! $iterate_by_page);
                                }
 
                                # store fields in lookup
@@ -329,17 +328,18 @@ sub data2xml {
                                        sub iterate_fld($$$$$$) {
                                                my ($cache,$what,$field,$page,$data,$append) = @_;
                                                return if (!$data);
-                                               my $line_delimiter = $page_line_delimiter;
-                                               $line_delimiter = " " if ($append);
+
+                                               my $ldel = $page_line_delimiter;
+                                               $ldel = " " if ($append);
+#print STDERR "line delimiter: ",Dumper($ldel) if ($ldel);
                                                if (! $cache->{$what}->{$field}->[$page]) {
                                                        $cache->{$what}->{$field}->[$page] = $data;
                                                } else {
-                                                       $cache->{$what}->{$field}->[$page] .= $line_delimiter.$data;
+                                                       $cache->{$what}->{$field}->[$page] .= $ldel.$data;
                                                }
                                        }
 
                                        if ($display_data) {
-print STDERR "line delimiter: ",Dumper($line_delimiter) if ($line_delimiter);
                                                iterate_fld($cache,'display_data',$field,$page,$display_data,$x->{append});
                                        }
                                                $display_data = "";
@@ -351,12 +351,31 @@ print STDERR "line delimiter: ",Dumper($line_delimiter) if ($line_delimiter);
                                                iterate_fld($cache,'swish_exact_data',$field,$page,$swish_exact_data,$x->{append});
                                                $swish_exact_data = "";
                                        }
+
+                                       if ($idisplay) {
+                                               my $ldel=$page_line_delimiter;
+                                               my @index_data;
+                                               if ($cache->{index_data}->{$field}->[$page]) {
+
+                                                       @index_data = @{$cache->{index_data}->{$field}->[$page]};
+                                               }
+                                               if ($x->{append}) {
+                                                       $index_data[$#index_data] .= $idisplay;
+                                               } else {
+                                                       push @index_data, $idisplay;
+                                               }
+                                               $idisplay = "";
+                                               @{$cache->{index_data}->{$field}->[$page]} = @index_data;
+                                       }
                                }
                        }
 
-                       # fill data in index
-                       foreach my $d (@index_data) {
-                               $index->insert($field, $d, $path);
+                       if (! $iterate_by_page) {
+                               # fill data in index
+                               foreach my $d (@index_data) {
+                                       $index->insert($field, $d, $path);
+                               }
+                               @index_data = ();
                        }
                }
 
@@ -435,6 +454,11 @@ print STDERR "line delimiter: ",Dumper($line_delimiter) if ($line_delimiter);
                                        # That is required to produce exact match
                                        $xml .= xmlify($field."_swish_exact", unac_string($codepage,'xxbxx '.$swish_exact_data.' xxexx'));
                                }
+                               
+                               foreach my $d (@{$cache->{index_data}->{$field}->[$page]}) {
+                                       $index->insert($field, $d, $path);
+#print STDERR "index $field: $d [$path]\n";
+                               }
                        }
        
                }