nickva opened a new pull request, #5310:
URL: https://github.com/apache/couchdb/pull/5310
Try to see what a simple selector-based views might look like. Inspired by
comments in the "allow_fallback" pr and the discussion in CouchDB dev meeting.
This is as simple as possible:
* We already have support for design doc languages, so go with that: use
"selector" as a language, then use the regular `_design/../_view` API
* `selector` picks documents to be indexed. The usual selector syntax,
nothing new
* `keys` - list of field values emitted as the key (an array)
* `values` - list of fields values emitted as the value (an array)
Example (DB=http://adm:[email protected]:15984)
```
echo "Recreating DB"
http -q delete $DB/db1
http -b put $DB/db1
echo "Adding some docs"
http -b put $DB/db1/a k:='1' v=x s:='10'
http -b put $DB/db1/b k:='3' v=x s:='11'
http -b put $DB/db1/c k:='4' v=y s:='12'
http -b put $DB/db1/d k:='2' v=x s:='13'
http -b put $DB/db1/e k:='5' v=x s:='14'
http -b put $DB/db1/f w:='1' v=x s:='15'
http -b put $DB/db1/g k:='3' o=o s:='16'
echo "Add two silly selector thingers"
http -b put $DB/db1/_design/s language=selector views:='{
"v1": {"map": {"selector": {"s":{"$gt":12}}, "keys":["k"],
"values":["v"]}},
"v2": {"map": {"keys":["w"]}}
}'
echo "Query the silly selector thinger"
http -b $DB/db1/_design/s/_view/v1
echo "Query the even sillier one without a selector"
http -b $DB/db1/_design/s/_view/v2
```
Query the silly selector thinger
```
{
"offset": 0,
"rows": [
{"id": "d", "key": [2], "value": ["x"]},
{"id": "e", "key": [5], "value": ["x"]}
],
"total_rows": 2
}
```
Query the even sillier one without a selector. Pick docs based on `keys`
only.
```
{
"offset": 0,
"rows": [
{"id": "f", "key": [1], "value": null}
],
"total_rows": 1
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]