/usr/share/perl5/Plucene/Search/Hits.pm is in libplucene-perl 1.25-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | package Plucene::Search::Hits;
=head1 NAME
Plucene::Search::Hits - A list of ranked documents
=head1 SYNOPSIS
my $hits = Plucene::Search::Hits->new;
my $doc = $hits->doc($n);
my $score = $hits->score($n);
my $hit_doc = $hits->hit_doc($n);
=head1 DESCRIPTION
This is a list of ranked documents, used to hold search results.
=head1 METHODS
=cut
use strict;
use warnings;
use Carp qw/croak/;
use Plucene::Search::TopDocs;
use base 'Class::Accessor::Fast';
__PACKAGE__->mk_accessors(
qw/ query searcher filter length hit_docs
first last num_docs max_docs /
);
=head2 new
my $hits = Plucene::Search::Hits->new;
=head2 query / searcher / filter / length / hit_docs / first /
last / num_docs / max_docs
Get / set these attributes.
=cut
sub new {
my $self = shift->SUPER::new(@_);
$self->num_docs(0);
$self->max_docs(200);
$self->hit_docs([]);
$self->_get_more_hits(50);
return $self;
}
sub _get_more_hits {
my ($self, $min) = @_;
if (@{ $self->{hit_docs} } > $min) { $min = @{ $self->{hit_docs} }; }
my $n = $min * 2;
my $top_docs = $self->searcher->search_top($self->query, $self->filter, $n);
$self->length($top_docs->total_hits);
my @score_docs = $top_docs->score_docs;
my $score_norm = 1.0;
$score_norm = 1 / $score_docs[0]->{score}
if $self->length > 0
and $score_docs[0]->{score} > 1.0;
my $end = $#score_docs < $self->length ? $#score_docs : $self->length;
for my $score_doc (@score_docs[ @{ $self->{hit_docs} } .. $end ]) {
push @{ $self->{hit_docs} },
Plucene::Search::HitDoc->new({
score => $score_doc->{score} * $score_norm,
id => $score_doc->{doc},
});
}
}
=head2 doc
my $doc = $hits->doc($n);
Returns the nth document.
=cut
sub doc {
my ($self, $n) = @_;
my $hit = $self->hit_doc($n);
# Not sure we need the LRU for now
return $hit->doc || $hit->doc($self->searcher->doc($hit->id));
}
=head2 score
my $score = $hits->score($n);
The score of the nth document.
=cut
sub score {
my ($self, $n) = @_;
return $self->hit_doc($n)->score;
}
=head2 hit_doc
my $hit_doc = $hits->hit_doc($n);
Returns the nth hit document.
=cut
sub hit_doc {
my ($self, $n) = @_;
if ($n >= $self->length) {
croak("Not a valid hit number: $n");
}
$self->_get_more_hits($n) if $n >= @{ $self->{hit_docs} };
return $self->{hit_docs}[$n];
}
package Plucene::Search::HitDoc;
use base 'Class::Accessor::Fast';
__PACKAGE__->mk_accessors(qw/score id doc/);
1;
|