Lucy::...rtSpec(3pm)

πŸ“¦
version 0.6.2 Β· 2 versions
, in fedora 43

✨ Lucy::Search::SortSpec β€” the vibe-sorting manual ✨

okay bestie, welcome to Lucy::Search::SortSpec from the User Contributed Perl Documentation collection πŸ’– this is the page that tells you how to make your search results come back in your order instead of the default one. she's giving main character energy for real πŸŽ€


🌸 NAME 🌸

Lucy::Search::SortSpec β€” Specify a custom sort order for search results. yes literally that's her whole job and she ate πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

my $sort_spec = Lucy::Search::SortSpec->new(
    rules => [
        Lucy::Search::SortRule->new( field => 'date' ),
        Lucy::Search::SortRule->new( type  => 'doc_id' ),
    ],
);
my $hits = $searcher->hits(
    query     => $query,
    sort_spec => $sort_spec,
);

look at her go 😭 build a SortSpec, hand it to hits(), and suddenly your results are sorted however you want. iconic behavior tbh.


🌈 DESCRIPTION 🌈

so by default, searches return results in order of relevance. that's the whole default vibe. but if you want a different order, SortSpec lets you say so β€” you just pass in an array of SortRules and she'll sort accordingly ✨

heads up bestie: fields you wish to sort against must be "sortable". no sortable field, no sorting, no exceptions 🫢

and if you want a stable sort β€” which is super important when you're paging through results, like literally do not skip this β€” add a sort-by-doc rule as the last SortRule. that's the move. periodt. πŸ‘‘


πŸŽ€ CONSTRUCTORS πŸŽ€

πŸ’– new

my $sort_spec = Lucy::Search::SortSpec->new( rules => \@rules );

Create a new SortSpec. slay, that's it, that's the constructor πŸ’…

  • rules β€” An array of SortRules. that's the whole thing, just hand her your rules and let her cook πŸ“

πŸ‘‘ INHERITANCE πŸ‘‘

Lucy::Search::SortSpec isa Clownfish::Obj. so she's got that Clownfish lineage, iykyk πŸ¦‹


and that's the whole page bestie, no notes πŸ’œ this lil' manual came to you from Lucy::...rtSpec(3pm), dated 2025-07-25, running on perl v5.42.0 πŸŽ€ go forth and sort responsibly, mwah 😘

πŸ“¦ where this page comes from