Plucen...Writer(3pm)
π Plucene::Index::Writer β write an index π
okay bestie, so this is Plucene::Index::Writer, straight out of the User Contributed Perl Documentation, and it's literally the class that writes an index. no cap. let's get into it β¨
β¨ SYNOPSIS β¨
my $writer = Plucene::Index::Writer->new($path, $analyser, $create);
$writer->add_document($doc);
$writer->add_indexes(@dirs);
$writer->optimize; # called before close
my $doc_count = $writer->doc_count;
my $mergefactor = $writer->mergefactor;
$writer->set_mergefactor($value);
that's the whole vibe check right there π
πΈ DESCRIPTION πΈ
This is the writer class. that's the whole summary, she's simple, she's iconic.
okay but here's the tea: if an index is not gonna have more documents added to it for a while, and you want optimal search performance, then you should call the "optimize" method before the index gets closed. don't forget, fr fr. π«Ά
π METHODS π
π new
my $writer = Plucene::Index::Writer->new($path, $analyser, $create);
This will create a new Plucene::Index::Writer object. main character energy.
The third argument to the constructor is the one that decides whether a new index is created, or whether an existing index is opened for the addition of new documents. so like, third arg = the decision-maker. respect her. π
π¦ mergefactor / set_mergefactor
my $mergefactor = $writer->mergefactor;
$writer->set_mergefactor($value);
Get / set the mergefactor. It defaults to 5. that's it, that's the whole thing, slay.
π doc_count
my $doc_count = $writer->doc_count;
π add_document
$writer->add_document($doc);
Adds a document to the index. and here's the part you gotta know β after the document has been added, a merge takes place if there are more than $Plucene::Index::Writer::mergefactor segments in the index. This defaults to 10, but can be set to whatever value is optimal for your application. iykyk π₯
β optimize
$writer->optimize;
Merges all segments together into a single segment, optimizing an index for search. she's the closer, periodt.
β οΈ This should be the last method called on an indexer, as it invalidates the writer object. like, after this she's gone, do not try to use her again bestie π
π§ add_indexes
$writer->add_indexes(@dirs);
Merges all segments from an array of indexes into this index. so many segments, so little time.
This may be used to parallelize batch indexing. A large document collection can be broken into sub-collections. Each sub-collection can be indexed in parallel, on a different thread, process or machine. The complete index can then be created by merging sub-collection indexes with this method. it's giving teamwork, it's giving distributed girlboss π
After this completes, the index is optimized. β¨
and that's the page, bestie!! π go write an index, you got this, no cap.
sign-off vibes: this was brought to you by perl v5.36.0, dated 2022-12-04, and filed under Plucen...Writer(3pm) in the User Contributed Perl Documentation. mwah π
π¦ where this page comes from
- debian bookworm: libplucene-perl 1.25-5
- debian trixie: libplucene-perl 1.25-5
- ubuntu noble: libplucene-perl 1.25-5
- ubuntu resolute: libplucene-perl 1.25-5
- ubuntu stonking: libplucene-perl 1.25-5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms