Search drilldown fails with multiple parameters
- Dominant language
- JavaScript
- Stars
- 689
- Forks
- 167
- Avg merge
- 1h
- Merged PRs (30d)
- 1
Description
The `db.search` function has an optional `drilldown` parameter which can be either
1. an array e.g.
```js
db.search('ddoc', 'search', {
q: '*:*',
drilldown: ['author','Dickens']
})
```
or
2. an array of arrays e.g.
```js
db.search('ddoc', 'search', {
q: '*:*',
drilldown: [['author','Dickens'],['publisher','Penguin']]
})
```
## Expected Behavior
I should be able to supply an array on an array of arrays and have Nano produce the correct query string parameters.
## Current Behavior
It is impossible to supply an array of arrays to `drilldown`. It incorrectly JSON.stringifies everything producing a server error.
## Possible Solution
- an array of strings should be JSON.stringified
- an array of arrays should have its elements JSON.stringified
- the outgoing Request object needs `qsStringifyOptions = { arrayFormat: 'repeat' }` to force the query string to become `drilldown=["author","Dickens"]&drilldown=["publisher","Penguin"]`
## Steps to Reproduce (for bugs)
```js
var Nano = require('nano')
var nano = Nano(url)
var db = nano.db.use('books')
db.search('search', 'search', {
q: '*:*',
counts: ['publisher'],
drilldown: [ ['publisher', 'Penguin'], ['author', 'Charles Dickens'] ]
}).then(console.log)
```
## Context
The `drilldown` parameter is designed to allow a user to winnow their search results by facets within the result set. They can select individual facets (publisher = penguin) and the result set will only contain matching values. Multiple drilldowns can be selected to refine the result set further. Nano only allows a top-level drilldown because it incorrectly handles arrays of arrays.
## Your Environment
- Node 10.14
- Nano 8.0.0
Contributor guide
Research direction
Start at the db.search entry point and trace how its drilldown option reaches the outgoing Request object. Run the reproduction with multiple drilldowns and verify that the completed request uses repeated drilldown parameters, with each nested array JSON-stringified as described in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100