[KinoSearch] Dynamic schemas - How?
Miles Crawford
mcrawfor at u.washington.edu
Fri Mar 2 14:49:02 PST 2007
I too have been looking into the schemas issue with some dismay.
The idea of class-based schemas seems to me to violate many of the ideals of
OO-perl programming, and all of the solutions presented here have struck me as
closer to hacks than to a successful application of an API.
> Hmm. Technically, you don't need an eval -- you can manipulate @ISA directly
> if you turn off strict refs.
>
> {
> no strict 'refs';
> @{ $class . '::ISA' } = ('KinoSearch::Schema');
> }
> I'd consider either that or an eval acceptable if we can't figure out a
> better way to handle things, but it's still somewhat inelegant.
My feeling is that many large, extensible applications will be working with
dynamic objects, and any API that requires the use of eval'ed code or "no
strict refs" is probably not ideal.
> If Schemas were objects rather than classes -- which is something I
> considered -- we wouldn't have this problem.
>
> my $schema = KinoSearch::Schema->new(
> analyzer => KinoSearch::Analysis::Tokenizer->new,
> );
> $schema->spec_field( name => title );
> my $invindexer = KinoSearch::InvIndexer->new(
> invindex => $schema->clobber('/path/to/invindex'),
> );
This solution seems very sane and useful to me! It's clean, easy to document
and easy to use either in a static or dynamic context.
> However, I rejected that design because I know if we did that, less
> experienced users would copy and paste the schema code between index and
> search scripts, violating DRY and leading to a bunch of nasty errors when
> conflicts arise because copies get out of sync. Shunting everyone into
> module use is less error prone and encourages good programming practice.
> However, your particular use case is less well served.
This does not strike me as a particularly reasonable objection. An
inexperienced user is just as likely to copy-paste some complex looped-over
eval or a class with a %FIELDS hash as they are an object oriented approach.
Perl package black magic sets the bar even higher for inexperienced folk.
In short, I love the Schema concept, but please, do not tie it up in classes -
90% of the customization that people want to do will be easy to add via
instance methods on objects, and for the other 10% subclassing could certainly
still be optional.
Thanks for letting us take a look at .20_01 and all your work on KinoSearch.
-Miles
__________________________________
Miles Crawford, Software Developer
Catalyst Research & Development
Office of Learning & Scholarly Technologies
University of Washington
206.616.3406
http://catalyst.washington.edu
http://solstice.eplt.washington.edu
More information about the kinosearch
mailing list