On Fri, Dec 05, 2008 at 08:47:25PM +0000, Henning P. Schmiedehausen wrote: > Hi, > > I am still trying to make sense on how the filtering code works. So we have > > PersonService.FilterOperation, which can be > > contains, equals, startsWith, present > > and the filterValue, which probably contains a string for these > matches. But there is also set/getFilter on the CollectionOptions, > which probably is supposed to take > > HAS_APP_FILTER, ALL_FILTER or IS_WITH_FRIENDS_FILTER (constants in > PersonService), because these can not really be well expressed with > FilterOperation/FilterValue. > > So these are actually two different filters: One for selecting a > subset of the results (HAS_APP, ALL, IS_WITH_FRIENDS) and one for > operation/value stuff (that uses Operation/Value), right?
As I read this, CollectionOptions.getFilter() returns one of the special constants OR a field name. In the first case, FilterOperation is supposed to be equals, and should in any case be ignored, and filterValue has some relevant, well, value. The appId for HAS_APP, a userId for IS_WITH_FRIENDS (and what's with that name, by the way?) In the second case, you are expected to apply the FilterOperation with the FilterValue against the named Field. In the case of composite fields (Name, Address, etc), against their principal subfield (Name.formatted, for example) In the case of plural fields, ... well, I decided to take the principal subfield, filter on that, do an AND over the collection. It's not specified, AFAICT. Some examples: filter=ALL No filtering, but set RestfulCollection.isFiltered = true filter=HAS_APP Return only users that have installed the current app. I assume filterValue=current app, but don't really use it, take the id from the token, instead. filter=IS_WITH_FRIENDS return users that are friends of filterValue. filter=id, filterValue=3, filterOperation=contains Return users whose id contains a 3 somewhere (Silly example, I know). filter=name, filterValue=Rodrigo, filterOperation=startsWith Return users whose name.formatted starts with 'Rodrigo' (Question here: at $WORK we decided to do a case ignoring comparison for these. Does that sound like a good idea?) filter=email, filterValue=example.com, filterOperation=contains Return users with at least one email address from example.com These interpretations come more from reading the REST spec than the JS one, but are consistent with both. You can actually implement HAS_APP by filtering on Person.hasApp==true, of course, and the spec alignment means that IS_WITH_FRIENDS will (behavior-wise) be a field in Person containing the list of all their friends, so that filter gets also subsummed into a 'filter by contains on that field'. Not that anyone expects any implementation to actually DO that, of course :)

