--- trunk/spider/filter.pm 2004/01/20 18:40:06 51
+++ trunk/spider/filter.pm 2004/01/25 16:49:50 57
@@ -1,5 +1,8 @@
sub filter {
my $contents = shift || return;
+
+# my $verbose = 1;
+
# if you don't want content to be indexed, include it in
# foobar tags or surround it with comments
# foobar
@@ -37,6 +40,55 @@
}
+ # is second argument collection?
+ my $collection = shift || return $contents;
+
+ # construct new title (from various parts of DocBook if available)
+ my $new_title;
+
+ if ($contents =~ m,,is) {
+ $new_title = $1;
+ } elsif ($contents =~ m,]*>([^<]+),is) {
+ $new_title = $1;
+ } elsif ($contents =~ m,]*>([^<]+),is) {
+ $new_title = $1;
+ } elsif ($contents =~ m,]*>([^<]+),is) {
+ $new_title = $1;
+ } else {
+ if ($contents =~ m,
([^<]+),is) {
+ $new_title = $1;
+ } elsif ($contents =~ m,]*>([^<]+),is) {
+ $new_title = $1;
+ }
+ }
+
+ if ($new_title) {
+ # check if new title is same as collection name
+ my ($a,$b) = ($new_title,$collection);
+ $a =~ s/([^a-zA-Z])+/ /gs;
+ $b =~ s/([^a-zA-Z])+/ /gs;
+ if ($a =~ m/$b/i) {
+ $new_title = $collection;
+ } else {
+ $new_title = "$collection :: $new_title";
+ }
+ } else {
+ # fall-back to collection title
+ $new_title = $collection;
+ }
+
+ $new_title =~ s/\s\s+/ /g;
+
+ if ($contents =~ s,(.*),$new_title,is) {
+ print STDERR "replace title '$1' with '$new_title'\n" if ($verbose);
+ } elsif (
+ # try to insert after , or at top
+ $contents =~ s,(),$1$new_title,is ||
+ $contents =~ s,(),$1$new_title,is ||
+ $contents =~ s,^,$new_title, ) {
+ print STDERR "adding new title '$new_title'\n" if ($verbose);
+ }
+
return $contents;
}