perldoc > Plucene::Index::Writer

πŸ“› NAME

Plucene::Index::Writer - write an index.

πŸš€ Quick Reference

Use CaseCommandDescription
Create writermy $writer = Plucene::Index::Writer->new($path, $analyser, $create);Open or create an index
Add a document$writer->add_document($doc);Add document to index
Merge other indexes$writer->add_indexes(@dirs);Merge external indexes
Optimize for search$writer->optimize;Single segment (call before close)
Document count$writer->doc_count;Number of documents
Get merge factor$writer->mergefactor;Current merge threshold
Set merge factor$writer->set_mergefactor($value);Adjust merge threshold

πŸ“– 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);

πŸ“ DESCRIPTION

This is the writer class.

If an index will not have more documents added for a while and optimal search performance is desired, then the optimize method should be called before the index is closed.

πŸ”§ METHODS

πŸ†• new

my $writer = Plucene::Index::Writer->new($path, $analyser, $create);

This will create a new Plucene::Index::Writer object.

The third argument to the constructor determines whether a new index is created, or whether an existing index is opened for the addition of new documents.

πŸ”€ mergefactor / set_mergefactor

my $mergefactor = $writer->mergefactor;
$writer->set_mergefactor($value);

πŸ”§ Get / set the merge factor. It defaults to 5.

πŸ”’ doc_count

my $doc_count = $writer->doc_count;

πŸ“Š Returns the number of documents in the index.

πŸ“„ add_document

$writer->add_document($doc);

βž• Adds a document to the index. 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.

πŸ”€ optimize

$writer->optimize;

🧩 Merges all segments together into a single segment, optimizing an index for search. This should be the last method called on an indexer, as it invalidates the writer object.

πŸ“₯ add_indexes

$writer->add_indexes(@dirs);

πŸ“‚ Merges all segments from an array of indexes into this index.

⚑ 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.

βœ… After this completes, the index is optimized.

Plucene::Index::Writer
πŸ“› NAME πŸš€ Quick Reference πŸ“– SYNOPSIS πŸ“ DESCRIPTION πŸ”§ METHODS
πŸ†• new πŸ”€ mergefactor / set_mergefactor πŸ”’ doc_count πŸ“„ add_document πŸ”€ optimize πŸ“₯ add_indexes

Generated by phpman v4.9.29 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-20 18:34 @2600:1f28:365:80b0:8802:8bb4:3873:328e
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format