Some more examples for the cookbook
Nobody has claimed this yet.
- Dominant language
- CSS
- Stars
- 118
- Forks
- 161
- PR merge metrics
- No merged PRs in 30d
Description
Here are some possible solutions to problems I have helped users solve. It might help them if they were in the cookbook or the secondary index page.
Filter by one field and order by another
A naive query would look like
.filter(r.row['a'] == val).orderBy('b')
It is tempting to try to optimize it like this, but it doesn't work because explanation.
.indexCreate('a')
.indexCreate('b')
.getAll(val, {index: 'a'}).orderBy({index: 'b'}) # error
A compound index could be used instead.
.indexCreate('a_b', [r.row('a'), r.row('b')])
.between([val, r.minval], [val, r.maxval], {index: 'a_b'}).orderBy({index: 'a_b'})
Tags
Disjunction:
.indexCreate('tags', {multi: true})
.getAll('hunting', 'fishing', {index: 'tags'})
Conjuntion:
.indexCreate('tags_powerset',
r.row('tags').orderBy(function(a){return a}).map(
function(elem){ return [[], [elem]]}).reduce(function(as,bs){
return as.concatMap(function(a){ return bs.map(function(b){ return a.add(b)})})}),
{multi: true})
.getAll(r.expr(['cooking', 'asia']).orderBy(r.row), {index: 'tags_powerset'})
Multiple queries in a single request
Homogeneous write queries:
var query = function(param){ return ... };
r.expr([1,2,3,'a','b']).forEach(query)
Homogeneous read queries:
var query = function(param){ return ... };
r.expr([1,2,3,'a','b']).concatMap(query)
Heterogeneous queries:
var query1 = function(){ return ... };
var query2 = function(query1_result){ return ... /* a stream */ };
var query3 = function(query2_result){ return ... });
query1().do(function(query1_result){
return query2(query1_result).coerceTo('array').do(function(query2_result){
return query3(query2_result)})})
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the supplied examples and locate the cookbook or secondary index page mentioned in the issue. Check how existing examples are organized and add the filtering, tags, and multiple-query material in the appropriate documentation location. Done means the examples are integrated consistently and the relevant page navigation or index is updated if needed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100