incubator-lucy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marvin Humphrey <mar...@rectangular.com>
Subject Re: [lucy-dev] Promoting new analysis components
Date Thu, 09 Feb 2012 17:49:51 GMT
On Thu, Feb 09, 2012 at 01:50:54PM +0100, Nick Wellnhofer wrote:
> On 09/02/2012 02:49, Marvin Humphrey wrote:
>> After reviewing the Lucy::Simple code, I realized that we can avoid breaking
>> compat with only a few extra lines.
>>
>>    * If the index exists during new(), extract the schema and type from what's
>>      on disk.
>>    * Otherwise, create a new EasyAnalyzer for the type.
>>
>> That way, we avoid a schema conflict crash when indexes built by Lucy::Simple
>> prior to 0.4.0 are read by 0.4.0 or above.
>
> I tried to implement this and ran into two little problems:
>
> 1. If the index doesn't exist and a schema isn't supplied, a "no schema"  
> exception is thrown, but the write lock isn't released.

Rehashing our short exchange on IRC for the benefit of the list... I suggest
using PolyReader#open for this, since it returns NULL rather than throwing an
exception on failure.  If open() is successful, the resulting reader can be
used as an argument to IndexSearcher#new:

    my $reader = Lucy::Index::PolyReader->open( index => $path );
    if ($reader) {
        $self->{searcher} = Lucy::Search::IndexSearcher->new(
            index => $reader) );
    }

>From there, getting the Schema is just an accessor call, and getting a
FieldType is annoying but doable.

The write lock fix is justified on its own, so +1 to that.

As an aside, the fact that IndexReader#open throws an exception is a legacy of
Lucene porting.  I think it might be nice to explore making our constructors
consistent, so that we use open() when there are system resources involved,
new() when there aren't, and have new() always throw exceptions and open()
consistently return NULL on failure if possible.

> 2. I didn't find a way to get the schema of an indexer from Perl.

+1 to add Indexer_Get_Schema() and to expose it from Perl.  The code in your
patch looked good.

Marvin Humphrey


Mime
View raw message