[elephant-devel] inherited indices

Alex Mizrahi killerstorm at newmail.ru
Tue Apr 26 21:12:11 UTC 2011


Index inheritance is a nice feature for the case when you have several 
sub-classes inheriting from a common base class and you want to lookup 
instances by a slot value regadless of the sub-class.
E.g. if super-from and mega-frob inherit from frob base class you can look 
up any kind of frob by frob-id if it is inherited.

But what's about the case where you want to be able to do queries both among 
all subclasses and for a specific sub-class?

id slot is probably a bad example since it is likely to be unique, so let's 
say we have frob-style slot.

Sometimes I want get any kind of frob with a specific style:

  (ele:get-instances-by-value 'frob 'frob-style "vanilla")

Sometimes I want to get instances of a specific class with a certain 
property:

  (ele:get-instances-by-value 'super-frob 'frob-style "vanilla")

But if slot frob-style has inherited index it doesn't matter what specific 
class is passed to get-instances-by-value, it can return frobs and 
mega-frobs even if you're asking for super-frobs.

I think ideally this would be resolved with a new type of 'hierarchical' 
slot indices where instances will be indexed in many indices at once -- when 
you make super-frob instance it will be indexed by frob-style both in 
super-frob and frob index (and, generally, in all super-classes). In this 
case get-instances-by-... semantics will be cleaner.

But perhaps that would be rather hard to implement.

As a quick fix, maybe we can filter instances on get-instances-by-... or 
map-inverted-index level?
These functions have information about actual class so filtering instances 
using type-of should be trivial.

Of course that will have sub-optimal performance as more instances will be 
pulled from database.
But it is better than nothing and it fixes non-intuitive behaviour 
(instances of wrong type are returned if you look at it from API point of 
view).

Users might achieve this functionality using derived indices -- say, normal 
frob-style slot won't have inherited index but derived slot frob-style* will 
be inherited and will just mirror frob-style. Thus when you want to lookup 
among all sub-classes you should use frob-style* instead of frob-style.
But this looks a bit cumbersome in class definitions.






More information about the elephant-devel mailing list