Lucy::...earcher(3pm)

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

πŸ’– Lucy::Search::IndexSearcher β€” the manual, but make it cute πŸ’–

Perl documentation, user-contributed edition β€” yes bestie, this is a 3pm page, we're in the cool section of the manual πŸ’…


✨ NAME ✨

Lucy::Search::IndexSearcher β€” go run searches against one single index. That's the whole job. She's focused. She's got main character energy. πŸŽ€


🌸 SYNOPSIS 🌸

my $searcher = Lucy::Search::IndexSearcher->new(
    index => '/path/to/index'
);
my $hits = $searcher->hits(
    query      => 'foo bar',
    offset     => 0,
    num_wanted => 100,
);

Look at her go. Build the searcher, ask for hits, done. Iconic. ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so here's the tea β˜• β€” you use the IndexSearcher class to run search queries against an index. That's it, that's the vibe. And if you're tryna search multiple indexes at once? Not her job, bestie β€” go look at PolySearcher instead. 🫢

Now, the important part, and I need you to hear me on this one: IndexSearchers operate against a single point-in-time view β€” a Snapshot β€” of the index. So if the index gets modified, your searcher does NOT magically see it. You have to open a new IndexSearcher to access the changes. No cap. 🚨


πŸŽ€ CONSTRUCTORS πŸŽ€

πŸ’« new

my $searcher = Lucy::Search::IndexSearcher->new(
    index => '/path/to/index'
);

Create a new IndexSearcher. Fresh out the box, ready to serve πŸ’–

  • index β€” Either a string filepath, a Folder, or an IndexReader. Pick your fighter, any of the three works. 🌈

πŸ‘‘ METHODS πŸ‘‘

πŸ“Š doc_max

my $int = $index_searcher->doc_max();

Returns the maximum number of docs in the collection that the Searcher represents β€” which is also the highest possible internal doc id. And heads up: documents that have been marked as deleted but not yet purged are still counted in this number. She counts them anyway. Messy but honest πŸ’€


πŸ” doc_freq

my $int = $index_searcher->doc_freq(
    field => $field,  # required
    term  => $term,   # required
);

Returns the number of documents that contain the term in the given field.

  • field β€” Field name. (required, no skipping πŸ™ˆ)
  • term β€” The term to look up. (also required, bestie πŸ‘€)

🧺 collect

$index_searcher->collect(
    query     => $query,      # required
    collector => $collector,  # required
);

Iterate over hits, feeding them into a Collector. Like a little conveyor belt of results going straight into the collector's hands πŸ“

  • query β€” A Query.
  • collector β€” A Collector.

πŸ“„ fetch_doc

my $hit_doc = $index_searcher->fetch_doc($doc_id);

Retrieve a document. And ⚠️ β€” she throws an error if the doc id is out of range. So don't come at her with a bogus id, she will absolutely not be chill about it 😭

  • doc_id β€” A document id.

πŸ“– get_reader

my $index_reader = $index_searcher->get_reader();

Accessor for the object's "reader" member. Just hands you the reader, no drama, we love a simple girl πŸ’…


🌈 INHERITANCE 🌈

Lucy::Search::IndexSearcher isa Lucy::Search::Searcher isa Clownfish::Obj.

Three generations of iconic lineage, we stan a family tree πŸ‘‘


Reminder bestie: index changed? new searcher. That's the whole moral of the story, iykyk 🧚

And that's the page! 🫢 This was perl v5.42.0, dated 2025-07-25, from the one and only Lucy::...earcher(3pm) β€” User Contributed Perl Documentation. Slay, go search something. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from