| 1 | package KinoSearch1::Search::HitQueue; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use KinoSearch1::Util::ToolSet; | ||
| 5 | use base qw( KinoSearch1::Util::PriorityQueue ); | ||
| 6 | |||
| 7 | BEGIN { __PACKAGE__->init_instance_vars() } | ||
| 8 | |||
| 9 | use KinoSearch1::Search::Hit; | ||
| 10 | |||
| 11 | sub new { | ||
| 12 | my $either = shift; | ||
| 13 | my $self = $either->SUPER::new(@_); | ||
| 14 | |||
| 15 | $self->define_less_than; | ||
| 16 | |||
| 17 | return $self; | ||
| 18 | } | ||
| 19 | |||
| 20 | # Create an array of "empty" Hit objects -- they have scores and ids, | ||
| 21 | # but the stored fields have yet to be retrieved. | ||
| 22 | sub hits { | ||
| 23 | my ( $self, $start_offset, $num_wanted, $searcher ) = @_; | ||
| 24 | my @hits = @{ $self->pop_all }; | ||
| 25 | |||
| 26 | if ( defined $start_offset and defined $num_wanted ) { | ||
| 27 | @hits = splice( @hits, $start_offset, $num_wanted ); | ||
| 28 | } | ||
| 29 | |||
| 30 | @hits = map { | ||
| 31 | KinoSearch1::Search::Hit->new( | ||
| 32 | id => unpack( 'N', "$_" ), | ||
| 33 | score => 0 + $_, | ||
| 34 | searcher => $searcher | ||
| 35 | ) | ||
| 36 | } @hits; | ||
| 37 | |||
| 38 | return \@hits; | ||
| 39 | } | ||
| 40 | |||
| 41 | 1; | ||
| 42 | |||
| 43 | __END__ |