Skip to content

Instantly share code, notes, and snippets.

@andrewrjones
Created January 19, 2012 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewrjones/1640933 to your computer and use it in GitHub Desktop.
Save andrewrjones/1640933 to your computer and use it in GitHub Desktop.
Dump the KinoSearch1 index.
#!/usr/bin/perl
use strict;
use warnings;
use KinoSearch1::Index::IndexReader;
my $r = KinoSearch1::Index::IndexReader->new( invindex => '/path/to/index' );
# get one or more readers
my @readers = ref $r->{sub_readers} eq 'ARRAY' ? @{ $r->{sub_readers} } : $r;
for my $reader (@readers) {
print "Segment "
. $reader->get_seg_name . " has "
. $reader->max_doc
. " docs\n";
# the index is numbered from 0 to max_doc, so just loop
# through them and get the documents
for(my $i = 0; $i < $reader->max_doc; $i ++){
# A KinoSearch1::Document::Doc object
my $doc = $reader->fetch_doc($i);
# this will depend on how your index has been set up
my $title = $doc->get_value('title');
print "$title\n";
}
}
print "Total documents: " . $r->max_doc . " in " . @readers . " segments\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment