[elephant-devel] Re: traversing btree using multiple indices
Alex Mizrahi
killerstorm at newmail.ru
Fri Apr 4 10:09:20 UTC 2008
SR> (defclass test-event ()
SR> ((date :accessor date-of :initform (now))
SR> (name :accessor name-of :initform nil))
SR> (:metaclass persistent-metaclass))
SR> (defun create-date-indexer (a b c) (values t (date-of c)))
SR> (defun create-name-indexer (a b c) (values t (name-of c)))
SR> (add-index btree
SR> :index-name 'date-index
SR> :key-form 'create-date-indexer
SR> :populate t)
this looks weird. you could just write
(defclass test-event ()
((date :accessor date-of :initform (now) :index t) ...
and it will create indices for you automatically.
SR> what is the best way to map across all added events between a
SR> particular date range with the name 'Sean'?
that's not union or intersection (at least i won't call them that way) --
you need an index with custom sorting order to do this.
something like that:
(defun id-and-time (id time) (formant nil "~a,~a" id time))
(add-class-derived-index 'test-event 'by-name-and-date
'(lambda (e) (id-and-time (name-of e) (date-of e))))
then you'll get sequence like this:
Ross,37343253
Sean,31334456
Sean,32345678
Somebody,30334656
it will work fine as long as name (and date) does not contain #\, -- then
all entries will same name will be grouped together.
then you can use simple range query:
(get-instances-by-range 'test-event 'by-name-and-date
(id-and-time "Sean" start-date)
(id-and-time "Sean" end-date))
i believe that SQL RDBMS work this way too -- if one needs fast retrieval by
several keys, he should create index on them. RDMBS knows how to sort
tuples, though
More information about the elephant-devel
mailing list