Author image Marvin Humphrey
and 1 contributors

NAME

KinoSearch::Search::SortSpec - Specify a custom sort order for search results.

SYNOPSIS

    my $sort_spec = KinoSearch::Search::SortSpec->new;
    $sort_spec->add( field => 'date' );
    my $hits = $searcher->search(
        query     => $query,
        sort_spec => $sort_spec,
    );

DESCRIPTION

By default, searches return results in order of relevance. SortSpec allows you to indicate an alternate order, using the contents of one or more fields.

Fields you wish to sort against must be indexed but must not be analyzed, as each document needs to be associated with a single value.

Memory and Caching

Each field that you sort against requires a sort cache, which is a C array of 32-bit integers. For each cache, the memory requirements are 4 bytes for each document in the index, plus loose change for object overhead. Additionally, a cache comprising some fraction of the terms in the index must be loaded. The time it takes to warm these caches on the first sorted search can be noticeable, but if you reuse your Searcher subsequent searches should be faster.

METHODS

new

Constructor. Takes no arguments.

add

    $sort_spec->add( 
        field   => $field_name,   # required
        reverse => 1,             # default: 0
    );

Add a field to sort against. Multiple sort criteria are processed in the order they were added (so the first to be added is the most important). Takes labeled parameters.

  • field - The name of a field which is indexed but not analyzed.

  • reverse - Reverse the order of the sort for this particular field.

COPYRIGHT

Copyright 2007 Marvin Humphrey

LICENSE, DISCLAIMER, BUGS, etc.

See KinoSearch version 0.20.