[Seaside] Re: Seaside and GOODS

Avi Bryant avi.bryant at gmail.com
Sat Mar 19 00:15:51 CET 2005


On Fri, 18 Mar 2005 17:43:42 -0500, Daniel Salama <dsalama at user.net> wrote:

> db root at: 'people' put: people.
> db root at: 'lastNames' put: lastNameIndex.
> 
> person := Person new; firstName: 'Daniel'; lastName: 'Salama'.
> 
> people at: 'some_magical_key_like_an_oid' put: person.
> lastNameIndex at: (person lastName) put: person.
> 
> db commit.
> 
> Basically, I create one person object and store it twice in the
> database. However, from your previous answers, only one instance of the
> object is actually stored. The other one is simply a reference.
> 
> Are my assumptions correct? Is what I did correct?

Yep, that's all fine.  Although for the lastNameIndex I would suggest
a TSTree instead (which will, for example, let you do prefix searches
as well as exact matches).

One question worth thinking about is what happens if the last name of
a person changes; in that case, you'd have to remove it from the index
at the old key and add it in at the new key.  Another is what happens
when there's more than one person with the same last name - so your
index should be mapping from strings to sets of persons, not to
individual persons.

All of this stuff gets a little tedious to manage by hand.  I know
Brian Brown has an IndexManager package that automates some of it, but
I'm not sure what the release status is...

> What would happen if I needed to sort the people by last name or maybe
> first name or some random pre-defined property? Should I implement
> multiple indices based on the potential different properties I'd like
> to sort by? Should these indices be something like SortedCollection or
> a BTree or something else from your BTree package?

Well, if you're sorting a set of objects you've already pulled out of
the database you don't need a special index for that, you just sort
them - using #sortBy: or #asSortedCollection: or whatever.  If you're
wanting to let the user browser through the entire list of persons by
last name, you probably want to use the prefix-retrieval I mentioned
earlier; BTree could/should have a similar retrieval by range of keys
though I'm not sure if it's implemented yet or not.

Avi


More information about the Seaside mailing list