Plucen...Writer(3pm)

πŸ“¦
version 1.25 Β· 2 versions
  • 1.25 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 1.25 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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