{
    "mode": "perldoc",
    "parameter": "Plucene::Index::Writer",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Plucene%3A%3AIndex%3A%3AWriter/json",
    "generated": "2026-06-14T12:51:55Z",
    "synopsis": "my $writer = Plucene::Index::Writer->new($path, $analyser, $create);\n$writer->adddocument($doc);\n$writer->addindexes(@dirs);\n$writer->optimize; # called before close\nmy $doccount = $writer->doccount;\nmy $mergefactor = $writer->mergefactor;\n$writer->setmergefactor($value);",
    "sections": {
        "NAME": {
            "content": "Plucene::Index::Writer - write an index.\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "my $writer = Plucene::Index::Writer->new($path, $analyser, $create);\n\n$writer->adddocument($doc);\n$writer->addindexes(@dirs);\n\n$writer->optimize; # called before close\n\nmy $doccount = $writer->doccount;\n\nmy $mergefactor = $writer->mergefactor;\n\n$writer->setmergefactor($value);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This is the writer class.\n\nIf an index will not have more documents added for a while and optimal search performance is\ndesired, then the \"optimize\" method should be called before the index is closed.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "new\nmy $writer = Plucene::Index::Writer->new($path, $analyser, $create);\n\nThis will create a new Plucene::Index::Writer object.\n\nThe third argument to the constructor determines whether a new index is created, or whether an\nexisting index is opened for the addition of new documents.\n\nmergefactor / setmergefactor\nmy $mergefactor = $writer->mergefactor;\n\n$writer->setmergefactor($value);\n\nGet / set the mergefactor. It defaults to 5.\n\ndoccount\nmy $doccount = $writer->doccount;\n\nadddocument\n$writer->adddocument($doc);\n\nAdds a document to the index. After the document has been added, a merge takes place if there\nare more than $Plucene::Index::Writer::mergefactor segments in the index. This defaults to 10,\nbut can be set to whatever value is optimal for your application.\n\noptimize\n$writer->optimize;\n\nMerges all segments together into a single segment, optimizing an index for search. This should\nbe the last method called on an indexer, as it invalidates the writer object.\n\naddindexes\n$writer->addindexes(@dirs);\n\nMerges all segments from an array of indexes into this index.\n\nThis may be used to parallelize batch indexing. A large document collection can be broken into\nsub-collections. Each sub-collection can be indexed in parallel, on a different thread, process\nor machine. The complete index can then be created by merging sub-collection indexes with this\nmethod.\n\nAfter this completes, the index is optimized.\n",
            "subsections": []
        }
    },
    "summary": "Plucene::Index::Writer - write an index.",
    "flags": [],
    "examples": [],
    "see_also": []
}