The old site-wide-seach and acs-service package also implemented someting similar in pl/sql (oracle only). It was insanely complex though and wrote all the pl/sql dynamically if I recall correctly.
I like Tom's idea. Works great with postgresql.
Another option is to use an insert view and rule like the content repository. That probably doesn't really get you where you need to go. I think either Tcl with callbacks or an something with xotcl is the only maintianable solution.