tags:

views:

18

answers:

1

I have a set of ACLs in Couch and I want to create a view that matches applicable ones. So, given the data:

[
  {
    "_id": "/protected",
    "type": "valid-user"
  },
  {
    "_id": "/protected/group1",
    "type": "require group group1"
  },
  {
    "_id": "/protected/group1/public",
    "type": "public"
  },
  {
    "_id": "/protected/group2",
    "type": "require group group2"
  },
  {
    "_id": "/admin",
    "type": "require user admin"
  }
]

I'd like to create a view that'd allow me to pass in a string and have it find the "best" (that is to say the longest) match.

The best I've been able to do is to create a view that returns the ID split into an array and then spam queries trimming the last element off until I get a match. Surely there's a way to do this on the server side ...

+1  A: 

You could create a list function to accomplish that.

duluthian
I've spent a couple of days banging on list functions and haven't gotten any traction. As near as I can tell, they exist only to transform the native JSON into something else like XML. Perhaps you could expand on what you where thinking?
BonkaBonka
Can you give me and example string and expected match? Just want to make sure I understand what you're trying to do fully.
duluthian