Lucy::...egment(3pm)
π Lucy::Index::Segment β the whole vibe π
okay so bestie, we're reading the manual page for Lucy::Index::Segment, straight out of the User Contributed Perl Documentation collection. pull up a chair, grab a strawberry π, and let's get into it.
β¨ NAME β¨
Lucy::Index::Segment β the warehouse where all the info about one segment of an inverted index lives. it's giving storage-unit-for-metadata energy. π¬
π SYNOPSIS π
first up, index-time β this is where you, a DataWriter, stash your stuff:
# Index-time.
package MyDataWriter;
use base qw( Lucy::Index::DataWriter );
sub finish {
my $self = shift;
my $segment = $self->get_segment;
my $metadata = $self->SUPER::metadata();
$metadata->{foo} = $self->get_foo;
$segment->store_metadata(
key => 'my_component',
metadata => $metadata
);
}
then search-time, where a DataReader comes back for its little treasures:
# Search-time.
package MyDataReader;
use base qw( Lucy::Index::DataReader );
sub new {
my $self = shift->SUPER::new(@_);
my $segment = $self->get_segment;
my $metadata = $segment->fetch_metadata('my_component');
if ($metadata) {
$self->set_foo( $metadata->{foo} );
...
}
return $self;
}
π¦ DESCRIPTION π¦
so, Apache Lucy's indexes? they're made up of individual βsegmentsβ, and every single one of those is its own independent inverted index. yes, they're all out here with main character energy. π
on the file system, each segment is a directory sitting inside the main index directory, and its name starts with βseg_β β think βseg_2β, βseg_5aβ, etc. π
every Segment object keeps track of info about one index segment: its fields, its document count, and so on. the Segment object itself writes exactly one file, segmeta.json. and honestly? besides storing the info Segment itself needs, that βsegmetaβ file is a whole central repository for metadata generated by other index components too β which lowkey relieves them of the burden of storing metadata themselves. iconic teamwork fr fr. π«Ά
π METHODS π
πΈ add_field
my $int = $segment->add_field($field);
register a brand new field and hand it a field number. and if the field was already known? nothing happens. no drama, no fuss. π
fieldβ the field name.
Returns: the field's field number, which is a positive integer.
πΈ store_metadata
$segment->store_metadata(
key => $key, # required
metadata => $metadata, # required
);
stash arbitrary info in the segment's metadata hash so it can get serialized later. β οΈ heads up bestie: it throws an error if key is used twice. no double-dipping. π
keyβ a string identifying an index component.metadataβ a JSON-izable data structure.
πΈ fetch_metadata
my $obj = $segment->fetch_metadata($key);
grab a value back out of the Segment's metadata hash. the lil reunion moment. π₯Ή
πΈ field_num
my $int = $segment->field_num($field);
give it a field name, it gives you back that field's number for this segment β and yes, that number can absolutely differ from its number in other segments, because every segment has its own thing going on. if the field name can't be found, you get 0 back, which is an invalid field number. π
fieldβ the field name.
πΈ field_name
my $string = $segment->field_name($field_num);
hand it a field number, get the name of its field back. if the field name can't be found, it's undef. that's it, that's the method. π§
πΈ get_name
my $string = $segment->get_name();
getter for the object's seg name. simple, clean, slays. β¨
πΈ get_number
my $int = $segment->get_number();
getter for the segment number.
πΈ set_count
$segment->set_count($count);
setter for the object's document count.
πΈ get_count
my $int = $segment->get_count();
getter for the object's document count. yes we do love a matching pair. π
πΈ compare_to
my $int = $segment->compare_to($other);
compares by segment number. that's the whole thing, no notes. β
π INHERITANCE π
Lucy::Index::Segment isa Clownfish::Obj. the bloodline is strong, the lineage is documented. π
aaaand that's the whole page bestie, we ate and left no crumbs π
β¨ this little manual page came to you as part of perl v5.42.0, dated 2025-07-25, and it lives at Lucy::...egment(3pm). mwah, bye! ππ¦π
π¦ 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