| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
dump_index - dump the contents of an index |
| 6 |
|
| 7 |
=head1 SYNOPSIS |
| 8 |
|
| 9 |
perl -w dump_index $DIR |
| 10 |
|
| 11 |
=head1 DESCRIPTION |
| 12 |
|
| 13 |
This will dump out an index in human readable form. It can be used when |
| 14 |
debugging to compare indexes create with Plucene to those created with |
| 15 |
Lucene. |
| 16 |
|
| 17 |
=cut |
| 18 |
|
| 19 |
use strict; |
| 20 |
use warnings; |
| 21 |
|
| 22 |
use Plucene::Index::Reader; |
| 23 |
|
| 24 |
my $where = shift @ARGV; |
| 25 |
my $r = Plucene::Index::Reader->open($where); |
| 26 |
|
| 27 |
no strict 'refs'; |
| 28 |
my @readers = (@{ $r->{readers} } ? @{ $r->{readers} } : $r); |
| 29 |
print "We have " . @readers . " readers\n"; |
| 30 |
if (@readers == 1 and $r->isa("Plucene::Index::SegmentsReader")) { |
| 31 |
die "But no segments\n"; |
| 32 |
} |
| 33 |
|
| 34 |
print "\n\nDocuments:\n"; |
| 35 |
for my $reader (@readers) { |
| 36 |
print "Segment " |
| 37 |
. $reader->{segment} . " has " |
| 38 |
. $reader->max_doc |
| 39 |
. " docs\n"; |
| 40 |
my @terms = $reader->terms; |
| 41 |
print "Fields:\n"; |
| 42 |
for my $field ($reader->field_infos->fields) { |
| 43 |
print "\t" . $field->number . ": " . $field->name; |
| 44 |
print " [indexed]" if $field->is_indexed; |
| 45 |
print "\n"; |
| 46 |
} |
| 47 |
print "Terms: \n"; |
| 48 |
my $td = $reader->term_docs; |
| 49 |
for my $t (@terms) { |
| 50 |
while ($t->next) { |
| 51 |
my $term = $t->term; |
| 52 |
print $term->field . ": " . $term->text . "\n"; |
| 53 |
$td->seek($term); |
| 54 |
my ($docs, $freqs) = $td->read; |
| 55 |
for (0 .. $#$docs) { |
| 56 |
print "\t Doc " |
| 57 |
. $docs->[$_] . " (" |
| 58 |
. $freqs->[$_] |
| 59 |
. " occurrences)\n"; |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
} |
| 65 |
print "Total documents: " . $r->max_doc . " in " . @readers . " segments\n"; |
| 66 |
|