Lucy::...Reader(3pm)
๐ Lucy::Index::IndexReader โ read from an inverted index, bestie ๐
okay so this is Lucy::Index::IndexReader from the Perl docs (user contributed, we love that for us). it's giving the way to peek inside an index. let's get into it ๐ฆ
โจ NAME โจ
Lucy::Index::IndexReader โ read from an inverted index. that's it. that's the whole vibe. ๐โจ
๐ธ SYNOPSIS ๐ธ
here's the lil taste test, no cap:
my $reader = Lucy::Index::IndexReader->open(
index => '/path/to/index',
);
my $seg_readers = $reader->seg_readers;
for my $seg_reader (@$seg_readers) {
my $seg_name = $seg_reader->get_segment->get_name;
my $num_docs = $seg_reader->doc_max;
print "Segment $seg_name ($num_docs documents):\n";
my $doc_reader = $seg_reader->obtain("Lucy::Index::DocReader");
for my $doc_id ( 1 .. $num_docs ) {
my $doc = $doc_reader->fetch_doc($doc_id);
print " $doc_id: $doc->{title}\n";
}
}
likeโฆ look at her go ๐
๐ DESCRIPTION ๐
so IndexReader is the interface through which IndexSearcher objects access the content of an index. that's the whole job. it's the plug, the gateway, the main character ๐
and here's the thing you HAVE to remember bestie: IndexReader objects always represent a point-in-time view of an index, like, as it existed at the exact moment the reader was created. frozen. a lil time capsule ๐ฐ๏ธ. so if you want your search results to reflect modifications to an index, you must create a new IndexReader after the update process completes. no shortcuts, no vibes-based hoping. periodt.
also IndexReaders are composites โ most of the work is done by individual DataReader sub-components, which you can get at via fetch() and obtain(). but lowkey the most efficient and powerful access to index data happens at the segment level, via SegReader's sub-components. iykyk ๐ซถ
๐ CONSTRUCTORS ๐
open
my $reader = Lucy::Index::IndexReader->open(
index => '/path/to/index', # required
snapshot => $snapshot,
manager => $index_manager,
);
plot twist: IndexReader is an abstract base class โ so open() returns the IndexReader subclass PolyReader, which channels the output of 0 or more SegReaders. zero!! or more!! the range is wild fr fr.
indexโ either a string filepath or aFolder. you gotta give her something to read ๐snapshotโ aSnapshot. if you don't supply it, the most recent snapshot file gets used. no thoughts, just the freshest one โจmanagerโ anIndexManager. heads up: read-locking is off by default, and supplying this argument turns it on. so that's the switch bestie ๐
๐ฆ ABSTRACT METHODS ๐ฆ
doc_max
my $int = $index_reader->doc_max();
return the maximum number of documents available to the reader โ which is also the highest possible internal document id. and yes, documents that have been marked as deleted but not yet purged from the index are included in this count. they're still on the roster, they just don't get playtime ๐
doc_count
my $int = $index_reader->doc_count();
return the number of documents available to the reader, subtracting any that are marked as deleted. so this one's the honest count, the "minus the ghosts" number ๐ป
del_count
my $int = $index_reader->del_count();
return the number of documents that have been marked as deleted but not yet purged from the index. the graveyard tally ๐ชฆ
offsets
my $i32_array = $index_reader->offsets();
return an array with one entry for each segment, corresponding to segment doc_id start offset. one per segment, no skipping ๐งฎ
seg_readers
my $arrayref = $index_reader->seg_readers();
return an array of all the SegReaders represented within the IndexReader. the whole squad, assembled ๐
๐ METHODS ๐
obtain
my $data_reader = $index_reader->obtain($api);
fetch a component โ or throw an error if the component can't be found. she does not do silence, she does not do ambiguity. dramatic? yes. useful? also yes ๐ญ
apiโ the name of theDataReadersubclass that the desired component must implement.
fetch
my $data_reader = $index_reader->fetch($api);
fetch a component โ or return undef if the component can't be found. the chill version of obtain. no drama, just undef ๐
apiโ the name of theDataReadersubclass that the desired component must implement.
๐ INHERITANCE ๐
Lucy::Index::IndexReader isa Lucy::Index::DataReader isa Clownfish::Obj.
a whole family tree, and she's got main character energy at every level ๐
that's the page bestie!! this manual came from perl v5.42.0, dated 2025-07-25, and it's filed under Lucy::...Reader(3pm) ๐โจ go forth and read your index, you've got this ๐ซถ๐
๐ฆ where this page comes from
- fedora 43: perl-Lucy 0.6.2-26.fc43 ยท Apache-2.0 AND MIT AND Unicode-DFS-2015
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms