The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

KinoSearch::Search::Hits - Access search results.

SYNOPSIS

    my $hits = $searcher->search(
        query      => $query,
        offset     => 0,
        num_wanted => 10,
    );
    while ( my $hashref = $hits->fetch_hit_hashref ) {
        print "<p>$hashref->{title} <em>$hashref->{score}</em></p>\n";
    }

DESCRIPTION

Hits objects are iterators used to access the results of a search.

A classic application would be paging through hits. After the first 10 hits are displayed, if the user wants to see more -- and there are more than 10 total hits -- the Hits object may seek() to an OFFSET of 10 and retrieve 10 more documents. And so on.

METHODS

seek

    $hits->seek( OFFSET, NUM_WANTED );

Position the Hits iterator at OFFSET and capture NUM_WANTED docs.

total_hits

    my $num_that_matched = $hits->total_hits;

Return the total number of documents which matched the query used to produce the Hits object. (This number is unlikely to match NUM_WANTED.)

fetch_hit_hashref

    while ( my $hashref = $hits->fetch_hit_hashref ) {
        # ...
    }

Return the next hit as a hashref, with the field names as keys and the field values as values. An entry for score will also be present, as will an entry for excerpts if create_excerpts() was called earlier.

create_excerpts

    my $highlighter = KinoSearch::Highlight::Highlighter->new;
    $highlighter->add_spec( field => 'body' );   
    $hits->create_excerpts( highlighter => $highlighter );

Use the supplied highlighter to generate excerpts. See KinoSearch::Highlight::Highlighter.

COPYRIGHT

Copyright 2005-2007 Marvin Humphrey

LICENSE, DISCLAIMER, BUGS, etc.

See KinoSearch version 0.20.