Lucy::...aWriter(3pm)

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

πŸ’– Lucy::Index::DataWriter β€” the manual page, but make it a group chat πŸ’–

okay bestie, so this page lives in the User Contributed Perl Documentation collection, and it's about Lucy::Index::DataWriter, which is literally the abstract blueprint for writing data into an index. Buckle up, it's giving "backend internals but make it cute". πŸŽ€


✨ NAME ✨

Lucy::Index::DataWriter β€” Write data to an index. no cap, that's the whole job. πŸ’…


✨ SYNOPSIS ✨

# Abstract base class.

that's it. that's the synopsis. she's abstract, she doesn't do anything by herself, she's a concept. main character energy but uninstantiable. πŸ‘‘


✨ DESCRIPTION ✨

So DataWriter is an abstract base class for writing index data, generally in segment-sized chunks. 🧩

Every single component of an index β€” think stored fields, lexicon, postings, deletions β€” gets its own lil DataWriter/DataReader pair. it's giving "couples costume but for data structures". 🫢

And here's the fun part: components may be specified per index by subclassing Architecture. iykyk. 🌸


✨ CONSTRUCTORS ✨

🌈 new

my $writer = MyDataWriter->new(
    snapshot   => $snapshot,      # required
    segment    => $segment,       # required
    polyreader => $polyreader,    # required
);

Abstract constructor. she does not exist in the flesh, only in spirit. πŸ’€

  • snapshot β€” The Snapshot that will be committed at the end of the indexing session. required, bestie, don't forget her.
  • segment β€” The Segment in progress. also required. she's mid-transformation, let her cook. πŸ”₯
  • polyreader β€” A PolyReader representing all existing data in the index. (If the index is brand new, the PolyReader will have no sub-readers β€” she's fresh out the box, no history, baby's first index. πŸ‘Ά) required.

✨ ABSTRACT METHODS ✨

these ones? you must implement them. no skipping. periodt.

πŸ¦‹ add_segment

$data_writer->add_segment(
    reader  => $reader,   # required
    doc_map => $doc_map,  # default: undef
);

Add content from an existing segment into the one currently being written. it's a glow-up merge, she's absorbing her ex's data. πŸ’…

  • reader β€” The SegReader containing content to add.
  • doc_map β€” An array of integers mapping old document ids to new ones. Deleted documents get mapped to 0, which is the signal that they should be skipped. bye felicia. πŸ‘‹

πŸ¦‹ finish

$data_writer->finish();

Complete the segment: close all streams, store metadata, etc. wrap it up, she's done, mic drop. 🎀

πŸ¦‹ format

my $int = $data_writer->format();

Every writer must specify a file format revision number, and that number should increment every time the format changes. and who's in charge of actually checking that revision? not her. πŸ‘€ Responsibility for revision checking is left to the companion DataReader. she said "that's not my job, ask my friend". πŸ’–


✨ METHODS ✨

πŸ“ delete_segment

$data_writer->delete_segment($reader);

Remove a segment's data. the default implementation is a no-op, because all files within the segment directory get automatically deleted anyway. so like, why bother. πŸ’…

Subclasses which manage their own files outside of the segment system should override this method and use it as a trigger for cleaning up obsolete data. if you're storing files somewhere weird, that's on you, bestie. 🧹

  • reader β€” The SegReader containing content to merge, which must represent a segment which is part of the current snapshot.

πŸ“ merge_segment

$data_writer->merge_segment(
    reader  => $reader,   # required
    doc_map => $doc_map,  # default: undef
);

Move content from an existing segment into the one currently being written. ✨

The default implementation calls add_segment() then delete_segment(). two-for-one special, she's efficient like that. 😌

  • reader β€” The SegReader containing content to merge, which must represent a segment which is part of the current snapshot.
  • doc_map β€” An array of integers mapping old document ids to new. Deleted documents are mapped to 0, indicating that they should be skipped.

πŸ“ metadata

my $hashref = $data_writer->metadata();

Arbitrary metadata to be serialized and stored by the Segment. the default implementation supplies a hash with a single key-value pair for "format". simple. elegant. minimal. she ate and left no crumbs. πŸŽ€

πŸ“ get_snapshot

my $snapshot = $data_writer->get_snapshot();

Accessor for the "snapshot" member var. πŸ”‘

πŸ“ get_segment

my $segment = $data_writer->get_segment();

Accessor for the "segment" member var. πŸ”‘

πŸ“ get_polyreader

my $poly_reader = $data_writer->get_polyreader();

Accessor for the "polyreader" member var. πŸ”‘

πŸ“ get_schema

my $schema = $data_writer->get_schema();

Accessor for the "schema" member var. πŸ”‘

πŸ“ get_folder

my $folder = $data_writer->get_folder();

Accessor for the "folder" member var. πŸ”‘

look at all those accessors. she's got getters for days. 🌈


✨ INHERITANCE ✨

Lucy::Index::DataWriter isa Clownfish::Obj. family tree iconic, lineage immaculate. πŸ‘‘


and that's the whole page, bestie!! this was perl v5.42.0, dated 2025-07-25, straight from the User Contributed Perl Documentation archives. you understood all of it, obviously, because you're that girl. slay, go write an index. πŸ’œπŸ¦‹βœ¨

πŸ“¦ where this page comes from