File: dump_index

package info (click to toggle)
libkinosearch1-perl 1.01-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,580 kB
  • sloc: perl: 6,805; java: 168; makefile: 3
file content (82 lines) | stat: -rwxr-xr-x 2,077 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/perl
use strict;
use warnings;

use KinoSearch1::Index::IndexReader;

my $where = shift @ARGV;
if( !$where || ! -e $where ){
    die "please specify an index location at the command line\n"; 
}

my $r = KinoSearch1::Index::IndexReader->new( invindex => $where );

my @readers = ref $r->{sub_readers} eq 'ARRAY' ? @{ $r->{sub_readers} } : $r;
print "We have " . @readers . " readers\n"; 

print "\n\nDocuments:\n";
for my $reader (@readers) {
    print "Segment "
      . $reader->get_seg_name . " has "
      . $reader->max_doc
      . " docs\n"; 
    my $finfos    = $reader->get_finfos;
    my $term_enum = $reader->terms;
    print "Fields:\n";
    my %fields;
    for my $field ( $finfos->get_infos ) {
        $fields{ $field->get_field_num } = $field->get_name; 
        print "\t" . $field->get_field_num . ": " . $field->get_name;
        my @info;
        foreach my $i (qw(indexed stored analyzed vectorized binary compressed))
        {
            my $method = "get_$i";
            push @info, $i if ( $field->$method );
        }
        print " [" . join( ',', map { substr( $_, 0, 1 ) } sort @info ) . "]"
          if (@info); 
        print "\n";
    }
    print "Terms:\n";
    my $td = $reader->term_docs;
    while ( $term_enum->next ) {
        my $term = $term_enum->get_term;
        print $term->to_string . "\n";
        $td->seek($term);
        while ( $td->next ) {
            print "\t Doc "
              . $td->get_doc . " (" 
              . $td->get_doc_freq
              . " occurrences)\n";
        }
    }
}
print "Total documents: " . $r->max_doc . " in " . @readers . " segments\n"; 

__END__

=head1 NAME

dump_index - dump the contents of an index

=head1 SYNOPSIS

	perl dump_index $INDEX_LOCATION

=head1 DESCRIPTION

This will dump out an index in human readable form.

=head1 AUTHOR

Adapted from a Plucene-based version by Brian Phillips.

=head1 COPYRIGHT AND LICENCE

Copyright 2006 Brian Phillips.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut