Mailing List Archive

new IndexReader on empty Index
Hi,

Is there a reason it isn't possible to create a new IndexReader on an
empty index? I get a Carp::confess() from
/usr/lib/perl5/vendor_perl/5.8.4/i686-linux/KinoSearch/Index/IndexReader.pm
line 106.
This is with KinoSearch-0.20_04. Here is a snippet of code I am using:
my $hostname = hostname();
die "Can't get unique hostname" unless $hostname;

my $invindex = GT::Maildir::KinoSearch::Schema->open($path);
my $lock_factory = KinoSearch::Store::LockFactory->new(
folder => $invindex->get_folder,
agent_id => $hostname,
);
my $reader = KinoSearch::Index::IndexReader->open(
invindex => $invindex,
lock_factory => $lock_factory,
);
return KinoSearch::Searcher->new(
invindex => $invindex,
reader => $reader
);

Am I doing something wrong?

Also, on a side note, the docs here:
http://www.rectangular.com/kinosearch/docs/devel/KinoSearch/Store/LockFactory.html
say to use KinoSearch::Index::IndexReader->new(), not ->open(), but
that gives an error.

Thanks,

Scott
new IndexReader on empty Index [ In reply to ]
On Aug 17, 2007, at 10:14 AM, Scott Beck wrote:

> Is there a reason it isn't possible to create a new IndexReader on an
> empty index?

There are two scenarios that could be described as "empty index".

The first is the one that is likely to be an incorrectly specified
filepath: either the directory exists but there aren't any index
files in it, or the index directory doesn't exist. Trying to create
an IndexReader against such a filepath should throw an exception, in
keeping with the anti-typo parameter validation strategy deployed
throughout the KS code base.

The second is that index files are present, but no documents have
been added. In this case, the behavior ought to be an empty but
valid IndexReader. However, that is not currently the case. This
code produces an error:

my $invindexer = KinoSearch::InvIndexer->new(
invindex => USConSchema->clobber('dummy_index') );
$invindexer->finish;

my $reader = KinoSearch::Index::IndexReader->open(
invindex => USConSchema->open('dummy_index') );
print "Max doc: " . $reader->max_doc . "\n";

The problem is that InvIndexer->finish declines to change the index
if nothing has happened, so we end up with only the starter file and
not a complete set of index files. I believe this is the error you
encountered, based on the line number you reported.

If that were fixed, would it solve your current problem?

> Also, on a side note, the docs here:
> http://www.rectangular.com/kinosearch/docs/devel/KinoSearch/Store/
> LockFactory.html
> say to use KinoSearch::Index::IndexReader->new(), not ->open(), but
> that gives an error.

Thank you for catching that. Fixed by revision 2494.

Marvin Humphrey
Rectangular Research
http://www.rectangular.com/
new IndexReader on empty Index [ In reply to ]
Hi Marvin,

On 8/19/07, Marvin Humphrey <marvin@rectangular.com> wrote:
>
> On Aug 17, 2007, at 10:14 AM, Scott Beck wrote:
>
> > Is there a reason it isn't possible to create a new IndexReader on an
> > empty index?
>
> The problem is that InvIndexer->finish declines to change the index
> if nothing has happened, so we end up with only the starter file and
> not a complete set of index files. I believe this is the error you
> encountered, based on the line number you reported.
>

I believe this is the case. The only file that exists in the index directory is:
segments_1.yaml

> If that were fixed, would it solve your current problem?
>

I tried commenting out the error checking in IndexReader.pm line 106
and it did fix the issue I'm having.

Thanks,

Scott