or die "Error creating DB: $!";
while (my ($k, $v) = each(%package_postfixes)) {
$v =~ s/.$//s;
- my $nr = $v;
- $nr =~ s/[^\000]//g;
- $nr = length($nr) + 1; # < number of hits
+ my $nr = ($v =~ tr/\000/\000/) + 1;
if ($nr > $MAX_PACKAGE_POSTFIXES) {
- $v = "\001" . $nr;
+ $v = ($v =~ /\^/) ? "^\001" . $nr
+ : "\001" . $nr;
}
$package_postfixes_db{$k} = $v;
}
my $first_keyword = lc shift @$keywords;
@$keywords = map { lc $_ } @$keywords;
-
+
my ($key, $prefixes) = ($first_keyword, '');
- my %pkgs;
+ my (%pkgs, %pkgs_min);
$postfixes->seq( $key, $prefixes, R_CURSOR );
while (index($key, $first_keyword) >= 0) {
- if ($prefixes =~ /^\001(\d+)/o) {
- debug( "$key has too many hits", 2 ) if DEBUG;
- $too_many_hits += $1;
+ if ($prefixes =~ /^(\^)?\001(\d+)/o) {
+ debug("$key has too many hits", 2 ) if DEBUG;
+ $too_many_hits += $2;
+ if ($1) { # use the empty prefix
+ foreach my $k (@$keywords) {
+ next unless $key =~ /\Q$k\E/;
+ }
+ debug("add key $key", 2) if DEBUG;
+ $pkgs{$key}++;
+ $pkgs_min{$key}++;
+ }
} else {
PREFIX:
foreach (split /\000/o, $prefixes) {
foreach my $k (@$keywords) {
next PREFIX unless $word =~ /\Q$k\E/;
}
- debug( "add word $word", 2) if DEBUG;
+ debug("add word $word", 2) if DEBUG;
$pkgs{$word}++;
+ $pkgs_min{$word}++ if $_ eq '';
}
}
last if $postfixes->seq( $key, $prefixes, R_NEXT ) != 0;
- last if $too_many_hits or keys %pkgs >= 100;
+ last if keys %pkgs_min >= 100;
}
-
- my $no_results = keys %pkgs;
- if ($too_many_hits || ($no_results >= 100)) {
- $too_many_hits += $no_results;
- %pkgs = ( $first_keyword => 1 ) unless @$keywords;
+
+ my $nr = keys %pkgs;
+ my $min_nr = keys %pkgs_min;
+ debug("nr=$nr min_nr=$min_nr too_many_hits=$too_many_hits", 1) if DEBUG;
+ if ($nr >= 100) {
+ $too_many_hits += $nr - $min_nr + 1;
+ %pkgs = %pkgs_min;
}
foreach my $pkg (sort keys %pkgs) {
&$read_entry( $packages, $pkg, $results, $non_results, $opts );