[elephant-devel] Re: questions about persistent classes
Alex Mizrahi
killerstorm at newmail.ru
Thu Apr 17 10:41:59 UTC 2008
RS> 3) How do I implement something to do efficient (i.e. not O(n)) LIMIT
RS> and OFFSET queries?
this probably depends on what you're trying to do..
if you do paging, you need query like "next 15 entries starting from this
one".
it's quite easy to achieve either using cursor API,
or passing special kind of enumartion function into map-index to do control
transfer to stop iteration when desired amount is retrieved.
RS> I was thinking of maintaining a counter
i don't see how counter will help you to do LIMIT and OFFSET queries, but it
might be useful for paging -- to display count of pages.
if you really _have_ to display it, indeed persistent counter will do that.
RS> (my intuition would be to use a class allocated slot, but I think that
RS> class objects are not serialized---am I right?)
yep, it's not, but you can make persistent class counter that is essentially
a pair <class_name, count>, or just a btree..
RS> 4) What is the intended use of `add-class-derived-index'? I must say
RS> that the documentation isn't very clear about it (specially figuring
RS> out what is a valid `derived-defun' wasn't trivial). Tight now I think
RS> I am supposed to run it once (it complains about a duplicate index if
RS> run a second time). This isn't exactly handy, because I would prefer
RS> that defining a derived index to left a clear trace in my code. Right
RS> now I am calling it wrapped with `handler-case'.
yes, this API pretty much sucks, so in my application i've made a more handy
inteface:
(defvar *derived-indices* (make-hash-table :test 'equal))
(defmacro def-derived-index (class index (arg) &body code)
(let ((fn (intern (format nil "IDX-FN-~a-~a" class index) :app)))
`(progn
(defun ,fn (,arg)
, at code)
(setf (gethash (cons ',class ',index) *derived-indices*) ',fn))))
(defun initialize-derived-indices ()
(loop for (class . index) being each hash-key of *derived-indices*
using (hash-value code)
unless (ele:find-inverted-index class index :null-on-fail t)
do (ele:add-class-derived-index class index code)))
in new version derived indicices are part of class definition, so stuff like
this isn't needed
More information about the elephant-devel
mailing list