No subject
Fri Jun 19 13:23:39 PDT 2009
Actually, you could. You could open a Searcher or an IndexReader alongside
the Indexer. Does that suffice?
Provided that all fields are stored, this snippet would work to regenerate an
index:
my $index_reader = KinoSearch::Index::IndexReader->open(
index => '/path/to/index',
);
my $doc_reader = $index_reader->obtain("KinoSearch::Index::DocReader");
my $indexer = KinoSearch::Indexer->new(
index => '/path/to/index',
truncate => 1,
);
for my $doc_id ( 1 .. $reader->doc_max ) {
my $doc = $doc_reader->fetch( doc_id => $doc_id );
$indexer->add_doc($doc);
}
$indexer->commit;
Incidentally, the searcher/reader would continue to show the old index data
even after commit() completes, because of the way readers always present a
point-in-time view of the index.
There's a bit of an internal caveat worth mentioning, though I'd guess that it
doesn't affect you. Indexer has an internal PolyReader, which propagates down
to SegWriter and all the individual DataWriters (DocWriter, PostingsWriter,
etc.). If 'truncate' is true, *that* reader is empty -- i.e. it's a
PolyReader with no SegReaders. So from within e.g. DocWriter, the answer to
your question is no... but that wouldn't be relevant unless you've been
messing with Architecture and writing your own DataWriter plugins, a la
KSx::Index::ZlibDocWriter.
Marvin Humphrey
More information about the kinosearch
mailing list