[KinoSearch] Dynamic schemas - How?

Marc Elser melser at gmx.ch
Tue Feb 27 04:12:23 PST 2007



Hi Marvin,

> At index time, it's possible, though kludgy.
> 
>     for my $field_name (@field_names) {
>         eval qq|
>             package MySchema::$field_name;
>             use base qw( KinoSearch::Schema::Field );
>         |;
>         die $@ if $@;
>     }
>     MySchema->init_fields(@field_names);
> 
> That's essentially what I'm doing in my provisional implementation of 
> KinoSearch::Simple.
Well, that was also the best I could come up with, and as I do have the 
field_names to be indexed/searched also in the searcher I could do the 
same evals and also create the KinoSearch::Schema::Field packages with eval.

But I agree that this solution is not very nice, it's just some kind of 
workaround.

> You don't know the field names in advance at index-time, but you must 
> know exactly how you're going to define the fields -- otherwise, you 
> couldn't make this work with KS 0.1x.  So we have a field spec.  We just 
> need to associate it with field names.
> 
> Are there multiple specs?
Yes there are multiple specs because I have multiple indexes.
> 
> Do they ever change?
Well, they do change occasionally and then the index with the changed 
field is beeing rebuilt.
> 
> Do you ever need to add fields in the middle of an indexing session or 
> do you know them all up front?
I know them upfront because they're defined in an xml which is parsed, 
but they never change in the middle of indexing. You have to re-start 
our application which means the config files get parsed and 
Apache/mod_perl is restarted.
> 
> What we probably need is a new KinoSearch::Schema class method, akin to 
> init_fields() but with one more layer of indirection.  Instead of 
> telling your Schema about a field, you tell it about a FieldSpec 
> subclass and one or more field names.  Are you with me?   Could that 
> work for you?
If I understand this right, you wouldn't use any 
KinoSearch::Schema::FieldSpec classes anymore but instead you set it up 
with a KinoSearch::Schema subclass through a class method which defines 
the fields.

This still leaves me with the problem you can not only specify the 
fields you want to index in our config-xml but also the indexes you want 
to create. So I would also have to define the KinoSearch::Schema classes 
through an eval, but it would at least save me another eval for setting 
up the fields. But maybe you also know of a better solution for the 
subclassing problem for every index.

Best regards,

Marc


_______________________________________________
KinoSearch mailing list
KinoSearch at rectangular.com
http://www.rectangular.com/mailman/listinfo/kinosearch




More information about the kinosearch mailing list