Author image Marvin Humphrey
and 1 contributors


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


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


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.



    my $sort_spec = KinoSearch::Search::SortSpec->new;

Constructor. Takes no arguments.


        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 2007 Marvin Humphrey


See KinoSearch version 0.20.