112 |
# lookup key |
# lookup key |
113 |
my $lookup_key; |
my $lookup_key; |
114 |
|
|
115 |
|
# cache for field in pages |
116 |
|
$cache->{display_data} = (); |
117 |
|
$cache->{swish_data} = (); |
118 |
|
$cache->{swish_exact_data} = (); |
119 |
|
my @page_fields; # names of fields |
120 |
|
|
121 |
|
|
122 |
|
# subs used to produce output |
123 |
|
|
124 |
|
sub get_field_name($$$) { |
125 |
|
my ($config,$field,$field_usage) = @_; |
126 |
|
|
127 |
|
# find field name (signular, plural) |
128 |
|
my $field_name = ""; |
129 |
|
if ($config->{indexer}->{$field}->{name_singular} && $field_usage == 1) { |
130 |
|
$field_name = $config->{indexer}->{$field}->{name_singular}; |
131 |
|
} elsif ($config->{indexer}->{$field}->{name_plural}) { |
132 |
|
$field_name = $config->{indexer}->{$field}->{name_plural}; |
133 |
|
} elsif ($config->{indexer}->{$field}->{name}) { |
134 |
|
$field_name = $config->{indexer}->{$field}->{name}; |
135 |
|
} else { |
136 |
|
print STDERR "WARNING: field '$field' doesn't have 'name' attribute!"; |
137 |
|
} |
138 |
|
if ($field_name) { |
139 |
|
return x($field_name); |
140 |
|
} |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
|
# begin real work: go field by field |
145 |
foreach my $field (@sorted_tags) { |
foreach my $field (@sorted_tags) { |
146 |
|
|
147 |
$field=x($field); |
$field=x($field); |
155 |
my ($swish,$display); |
my ($swish,$display); |
156 |
|
|
157 |
my $tag = $type2tag{$type} || die "can't find which tag to use for type $type"; |
my $tag = $type2tag{$type} || die "can't find which tag to use for type $type"; |
158 |
|
|
159 |
|
# is this field page-by-page? |
160 |
|
my $iterate_by_page = $config->{indexer}->{$field}->{iterate_by_page}; |
161 |
|
push @page_fields,$field if ($iterate_by_page); |
162 |
|
my %page_max = (); |
163 |
|
# default line_delimiter if using |
164 |
|
my $page_line_delimiter = $config->{indexer}->{$field}->{page_line_delimiter} || '<br/>'; |
165 |
|
|
166 |
foreach my $x (@{$config->{indexer}->{$field}->{$tag}}) { |
foreach my $x (@{$config->{indexer}->{$field}->{$tag}}) { |
167 |
|
|
168 |
my $format = x($x->{content}); |
my $format = x($x->{content}); |
169 |
my $delimiter = x($x->{delimiter}) || ' '; |
my $delimiter = x($x->{delimiter}) || ' '; |
170 |
|
|
171 |
my $repeat_off = 0; # repeatable offset |
my $repeat_off = 0; # init repeatable offset |
172 |
|
|
173 |
# swish, swish_exact, display, index, index_lookup |
# swish, swish_exact, display, index, index_lookup |
174 |
# swish and display defaults |
# swish and display defaults |
221 |
|
|
222 |
# while because of repeatable fields |
# while because of repeatable fields |
223 |
while ($swish || $display) { |
while ($swish || $display) { |
224 |
|
my $page = $repeat_off; |
225 |
|
$page_max{$field} = $page if ($iterate_by_page && $page > ($page_max{$field} || 0)); |
226 |
($swish,$display) = parse_format($type, $format,$row,$repeat_off++,$import2cp); |
($swish,$display) = parse_format($type, $format,$row,$repeat_off++,$import2cp); |
227 |
if ($repeat_off > 1000) { |
if ($repeat_off > 1000) { |
228 |
print STDERR "loop (more than 1000 repeatable fields) deteced in $row, $format\n"; |
print STDERR "loop (more than 1000 repeatable fields) deteced in $row, $format\n"; |
231 |
|
|
232 |
# is this field is lookup? |
# is this field is lookup? |
233 |
if ($display && $x->{lookup}) { |
if ($display && $x->{lookup}) { |
234 |
|
my $null = "<!-- null -->"; |
235 |
if ($use_lhash_cache) { |
if ($use_lhash_cache) { |
236 |
if (!defined($cache->{lhash}->{$display})) { |
if (!defined($cache->{lhash}->{$display})) { |
237 |
my $new_display = $lhash{$display}; |
my $new_display = $lhash{$display}; |
238 |
if ($new_display) { |
if (defined($new_display)) { |
239 |
#print STDERR "lookup cache store '$display' = '$new_display'\n"; |
#print STDERR "lookup cache store '$display' = '$new_display'\n"; |
240 |
$display = $new_display; |
$display = $new_display; |
241 |
$cache->{lhash}->{$display} = $new_display; |
$cache->{lhash}->{$display} = $new_display; |
242 |
} else { |
} else { |
243 |
print STDERR "WARNING: lookup for '$display' didn't find anything.\n"; |
print STDERR "WARNING: lookup for '$display' didn't find anything.\n"; |
244 |
$display = ""; |
$display = ""; |
245 |
$cache->{lhash}->{$display} = ""; |
$cache->{lhash}->{$display} = $null; |
246 |
} |
} |
247 |
} else { |
} else { |
248 |
$display = $cache->{lhash}->{$display}; |
$display = $cache->{lhash}->{$display}; |
249 |
} |
} |
250 |
} else { |
} else { |
251 |
$display = $lhash{$display} || ""; |
$display = $lhash{$display} || $null; |
252 |
} |
} |
253 |
} |
} |
254 |
|
|
277 |
if ($d && $display) { |
if ($d && $display) { |
278 |
if ($line_delimiter && $display_data) { |
if ($line_delimiter && $display_data) { |
279 |
$display_data .= $line_delimiter; |
$display_data .= $line_delimiter; |
|
undef $line_delimiter; |
|
280 |
} |
} |
281 |
if ($filter) { |
if ($filter) { |
282 |
no strict 'refs'; |
no strict 'refs'; |
322 |
print STDERR "WARNING: no lookup_key defined for '$display'?"; |
print STDERR "WARNING: no lookup_key defined for '$display'?"; |
323 |
} |
} |
324 |
} |
} |
325 |
|
|
326 |
|
} |
327 |
|
|
328 |
|
# store data for page-by-page repeatable fields |
329 |
|
if ($iterate_by_page) { |
330 |
|
sub iterate_fld($$$$$$) { |
331 |
|
my ($cache,$what,$field,$page,$data,$append) = @_; |
332 |
|
return if (!$data); |
333 |
|
my $line_delimiter = $page_line_delimiter; |
334 |
|
$line_delimiter = " " if ($append); |
335 |
|
if (! $cache->{$what}->{$field}->[$page]) { |
336 |
|
$cache->{$what}->{$field}->[$page] = $data; |
337 |
|
} else { |
338 |
|
$cache->{$what}->{$field}->[$page] .= $line_delimiter.$data; |
339 |
|
} |
340 |
|
} |
341 |
|
|
342 |
|
if ($display_data) { |
343 |
|
print STDERR "line delimiter: ",Dumper($line_delimiter) if ($line_delimiter); |
344 |
|
iterate_fld($cache,'display_data',$field,$page,$display_data,$x->{append}); |
345 |
|
} |
346 |
|
$display_data = ""; |
347 |
|
if ($swish_data) { |
348 |
|
iterate_fld($cache,'swish_data',$field,$page,$swish_data,$x->{append}); |
349 |
|
$swish_data = ""; |
350 |
|
} |
351 |
|
if ($swish_exact_data) { |
352 |
|
iterate_fld($cache,'swish_exact_data',$field,$page,$swish_exact_data,$x->{append}); |
353 |
|
$swish_exact_data = ""; |
354 |
|
} |
355 |
} |
} |
356 |
} |
} |
357 |
|
|
380 |
$index->insert($field, $val, $path) if ($i); |
$index->insert($field, $val, $path) if ($i); |
381 |
} |
} |
382 |
|
|
383 |
|
if ($iterate_by_page) { |
384 |
|
# FIXME data from config tag will appear just |
385 |
|
# on first page!!! |
386 |
|
my $page = 0; |
387 |
|
if ($display_data) { |
388 |
|
$cache->{display_data}->{$field}->[$page] = $display_data; |
389 |
|
$display_data = ""; |
390 |
|
} |
391 |
|
if ($swish_data) { |
392 |
|
$cache->{swish_data}->{$field}->[$page] = $swish_data; |
393 |
|
$swish_data = ""; |
394 |
|
} |
395 |
|
if ($swish_exact_data) { |
396 |
|
$cache->{swish_exact_data}->{$field}->[$page] = $swish_exact_data; |
397 |
|
$swish_exact_data = ""; |
398 |
|
} |
399 |
|
} |
400 |
} |
} |
401 |
|
|
402 |
|
# save data page-by-page |
403 |
|
foreach my $field (@page_fields) { |
404 |
|
my $nr_pages = $page_max{$field} || next; |
405 |
|
#print STDERR "field '$field' iterate over ",($nr_pages || 0)," pages...\n"; |
406 |
|
#print STDERR Dumper($cache->{display_data}); |
407 |
|
for (my $page=0; $page <= $nr_pages; $page++) { |
408 |
|
|
409 |
|
my $display_data = $cache->{display_data}->{$field}->[$page]; |
410 |
|
if ($display_data) { # default |
411 |
|
if ($field eq "headline") { |
412 |
|
$xml .= xmlify("headline", $display_data); |
413 |
|
} else { |
414 |
|
|
415 |
if ($display_data) { |
# fallback to empty field name if needed |
416 |
|
$html .= get_field_name($config,$field,$field_usage{$field}) || ''; |
417 |
if ($field eq "headline") { |
$html .= "#-#".$display_data."###\n"; |
418 |
$xml .= xmlify("headline", $display_data); |
} |
|
} else { |
|
|
|
|
|
# find field name (signular, plural) |
|
|
my $field_name = ""; |
|
|
if ($config->{indexer}->{$field}->{name_singular} && $field_usage{$field} == 1) { |
|
|
$field_name = $config->{indexer}->{$field}->{name_singular}."#-#"; |
|
|
} elsif ($config->{indexer}->{$field}->{name_plural}) { |
|
|
$field_name = $config->{indexer}->{$field}->{name_plural}."#-#"; |
|
|
} elsif ($config->{indexer}->{$field}->{name}) { |
|
|
$field_name = $config->{indexer}->{$field}->{name}."#-#"; |
|
|
} else { |
|
|
print STDERR "WARNING: field '$field' doesn't have 'name' attribute!"; |
|
419 |
} |
} |
420 |
if ($field_name) { |
|
421 |
$html .= x($field_name); |
my $swish_data = $cache->{swish_data}->{$field}->[$page]; |
422 |
|
if ($swish_data) { |
423 |
|
# remove extra spaces |
424 |
|
$swish_data =~ s/ +/ /g; |
425 |
|
$swish_data =~ s/ +$//g; |
426 |
|
|
427 |
|
$xml .= xmlify($field."_swish", unac_string($codepage,$swish_data)); |
428 |
|
} |
429 |
|
|
430 |
|
my $swish_exact_data = $cache->{swish_exact_data}->{$field}->[$page]; |
431 |
|
if ($swish_exact_data) { |
432 |
|
$swish_exact_data =~ s/ +/ /g; |
433 |
|
$swish_exact_data =~ s/ +$//g; |
434 |
|
|
435 |
|
# add delimiters before and after word. |
436 |
|
# That is required to produce exact match |
437 |
|
$xml .= xmlify($field."_swish_exact", unac_string($codepage,'xxbxx '.$swish_exact_data.' xxexx')); |
438 |
} |
} |
|
$html .= $display_data."###\n"; |
|
439 |
} |
} |
440 |
|
|
441 |
} |
} |
442 |
if ($swish_data) { |
|
443 |
# remove extra spaces |
if (! $iterate_by_page) { |
444 |
$swish_data =~ s/ +/ /g; |
if ($display_data) { |
445 |
$swish_data =~ s/ +$//g; |
if ($field eq "headline") { |
446 |
|
$xml .= xmlify("headline", $display_data); |
447 |
|
} else { |
448 |
|
|
449 |
$xml .= xmlify($field."_swish", unac_string($codepage,$swish_data)); |
# fallback to empty field name if needed |
450 |
} |
$html .= get_field_name($config,$field,$field_usage{$field}) || ''; |
451 |
|
$html .= "#-#".$display_data."###\n"; |
452 |
|
} |
453 |
|
} |
454 |
|
if ($swish_data) { |
455 |
|
# remove extra spaces |
456 |
|
$swish_data =~ s/ +/ /g; |
457 |
|
$swish_data =~ s/ +$//g; |
458 |
|
|
459 |
if ($swish_exact_data) { |
$xml .= xmlify($field."_swish", unac_string($codepage,$swish_data)); |
460 |
$swish_exact_data =~ s/ +/ /g; |
} |
|
$swish_exact_data =~ s/ +$//g; |
|
461 |
|
|
462 |
# add delimiters before and after word. |
if ($swish_exact_data) { |
463 |
# That is required to produce exact match |
$swish_exact_data =~ s/ +/ /g; |
464 |
$xml .= xmlify($field."_swish_exact", unac_string($codepage,'xxbxx '.$swish_exact_data.' xxexx')); |
$swish_exact_data =~ s/ +$//g; |
465 |
|
|
466 |
|
# add delimiters before and after word. |
467 |
|
# That is required to produce exact match |
468 |
|
$xml .= xmlify($field."_swish_exact", unac_string($codepage,'xxbxx '.$swish_exact_data.' xxexx')); |
469 |
|
} |
470 |
} |
} |
|
|
|
|
|
|
471 |
} |
} |
472 |
|
|
473 |
# dump formatted output in <html> |
# dump formatted output in <html> |