--- trunk/html/swish.cgi 2004/04/18 08:36:35 79 +++ trunk/html/swish.cgi 2004/05/22 18:33:33 80 @@ -16,6 +16,7 @@ my $config=XMLin(undef, # keyattr => { label => "value" }, forcecontent => 0, + ForceArray => [ 'path' ], ); my $from_utf8 = Text::Iconv->new('UTF8', $config->{charset}); @@ -40,6 +41,7 @@ # FIX: doesn't work very well if ($config->{findaffix}) { foreach my $findaffix (split(/[, ]+/,x($config->{findaffix}))) { + next if (! -f $findaffix); my $spelling_alt = new Lingua::Spelling::Alternative; $spelling_alt->load_findaffix($findaffix); push @spellings,$spelling_alt; @@ -47,6 +49,7 @@ } if ($config->{affix}) { foreach my $affix (split(/[, ]+/,x($config->{affix}))) { + next if (! -f $affix); my $spelling_alt = new Lingua::Spelling::Alternative; $spelling_alt->load_affix($affix); push @spellings,$spelling_alt; @@ -170,56 +173,12 @@ $hit_fmt = x($config->{hit}) if (x($config->{hit})); } -# my $sh = SWISH->connect('Fork', -# prog => x($config->{prog}), -# indexes => x($config->{index}), -# results => sub { -# my ($sh,$hit) = @_; -# -# if ($config->{url}) { -# printf ($hit_fmt ,"http://".virtual_host().x($config->{url}).$hit->swishdocpath,e($hit->swishtitle) || 'untitled',$hit->swishrank, map($hit->$_, @properties)); -# } else { -# printf ($hit_fmt ,$hit->swishdocpath,e($hit->swishtitle) || 'untitled',$hit->swishrank, map($hit->$_, @properties) ); -# -# } -# -## print $_[1]->as_string,"
\n"; -## my @fields = $hit->field_names; -## print "Field '$_' = '", $hit->$_, "'
\n" for sort @fields; -# }, -# maxhits => param('max_hits') || $max_hits, -# \%params, -# ); -# -# die $SWISH::errstr unless $sh; -# -# $hits = $sh->query($s); -# -# if ($hits && $hits > 0) { -# print p,hr; -# printf (x($config->{text}->{hits}),$hits,param('max_hits') || $max_hits,$s); -# } else { -# print p; -# printf (x($config->{text}->{no_hits}),$s,$sh->errstr); -# } -# if ($hits && $hits > 0) { -# print p,hr; -# printf (x($config->{text}->{hits}),$hits,param('max_hits') || $max_hits,$s); -# } else { -# print p; -# printf (x($config->{text}->{no_hits}),$s,$sh->errstr); -# } - my $swish = SWISH::API->new($config->{index}); - $swish->AbortLastError if $swish->Error; - my $results = $swish->Query($s); - my $hits = $results->Hits; - # build pager my $current_page = param('page') || 1; @@ -242,6 +201,11 @@ printf (x($config->{text}->{hits}),$i,$results->Hits,$s); } + my %path2title; + use Data::Dumper; + foreach my $p (@{$config->{path2title}->{path}}) { + $path2title{$p->{dir}} = $p->{content}; + } for(my $i=$pager->first; $i<=$pager->last; $i++) { @@ -263,11 +227,21 @@ my $rank = $result->Property("swishrank"); my $host = $result->Property("swishdocpath"); $host = "http://".virtual_host().x($config->{url}).$result->Property("swishdocpath") if ($config->{url}); + + foreach my $p (keys %path2title) { + if ($host =~ m/$p/i) { + $title =~ s/$path2title{$p}\s*[:-]+\s*//; + $title = $path2title{$p}." :: ".$title; + last; + } + } + print $tr_pre,$i,". "; # print collection name which is not link if ($title =~ s/^(.+? :: )//) { print $1; } + printf($hit_fmt, $host, $title || 'untitled', $rank, @arr); print $tr_post;