I know this is kinda old but I actually had occasion to do precisely what the author is asking here.

In a nutshell...
  1. Get yourself an IndexReader (of some kind) by calling IndexReader->open on your inverted index (check the API). Call it $reader.
  2. for $i = 1 to $reader->num_docs(), call $reader->fetch_doc_vec($i). The return value is a DocVector.
Here you run into trouble..
as far as I can tell. Take a look at DocVector.pm. The method "term_vector" appears to require that you specify a term for which to retrieve positional and frequency data. But if you're iterating over all the documents, presumably you didn't have any specific terms in mind. :) I decided to write my own method at this point and to add it to the DocVector.pm class. Here it is... it's kinda ugly. It returns an associative array of terms to in-document term frequencies.
sub get_term_data { my ( $self ) = @_; my @fields = $self->get_field_names(); my $termdata = {}; for my $field (@fields) { my $field_vector = $self->{field_vectors}{$field}; if ( !defined $field_vector ) { my $field_string = $self->{field_strings}{$field}; return unless defined $field_string; $field_vector = $self->{field_vectors}{$field} = _extract_tv_cache($field_string); } my @terms_for_field = keys %{$field_vector}; for my $term (@terms_for_field) { my ($positions, $starts, $ends) = _extract_posdata($fie +ld_vector- >{$term}); my $termvector = KinoSearch::Index::TermVector->new( field => $field, text => $term, positions => $positions, start_offsets => $starts, end_offsets => $ends, ); # ok.. we have the term vector. how do we get the # term frequency for this document? my $term_freq = scalar(@{$positions}); $termdata->{$term} = $term_freq; } } return $termdata; }

In reply to Re: KinoSearch - is there a way to iterate over all documents in an index? by Anonymous Monk
in thread KinoSearch - is there a way to iterate over all documents in an index? by isync

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.