The Perl Advent Calendar needs more articles for 2022. Submit your idea today!
use strict;
use warnings;
use KinoSearch;

package KSx::Search::MockScorer;
BEGIN { our @ISA = qw( KSx::Search::MockMatcher ) }

sub new {
    my ( $either, %args ) = @_;
    confess("Missing doc_ids") unless ref( $args{doc_ids} ) eq 'ARRAY';
    my $doc_ids = KinoSearch::Object::I32Array->new( ints => $args{doc_ids} );
    my $size = $doc_ids->get_size;
    my $scores;
    if ( ref( $args{scores} ) eq 'ARRAY' ) {
        confess("Mismatch between scores and doc_ids array sizes")
            unless scalar @{ $args{scores} } == $size;
        $scores = KinoSearch::Object::ByteBuf->new(
            pack( "f$size", @{ $args{scores} } ) );

    return $either->_new(
        doc_ids => $doc_ids,
        scores  => $scores,




    parcel       => "KinoSearch",
    class_name   => "KSx::Search::MockMatcher",
    bind_constructors => ["_new|init"],


=head1 NAME

KSx::Search::MockScorer - Matcher with arbitrary docs and scores.


Used for testing combining L<Matchers|KinoSearch::Search::Matcher> such as
ANDScorer, MockScorer allows arbitrary match criteria to be supplied,
obviating the need for clever index construction to cover corner cases.

MockScorer is a testing and demonstration class; it is unsupported.


=head2 new( [I<labeled params>] )


=item *

B<doc_ids> - A sorted array of L<doc_ids|KinoSearch::Docs::DocIDs>.

=item *

B<scores> - An array of scores, one for each doc_id.



Copyright 2007-2011 Marvin Humphrey

This program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.