couchdb-nano
couchdb-nano copied to clipboard
Search drilldown fails with multiple parameters
The db.search
function has an optional drilldown
parameter which can be either
- an array e.g.
db.search('ddoc', 'search', {
q: '*:*',
drilldown: ['author','Dickens']
})
or
- an array of arrays e.g.
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 becomedrilldown=["author","Dickens"]&drilldown=["publisher","Penguin"]
Steps to Reproduce (for bugs)
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
FYI, new releases of CouchDB allow for new ways of supplying drilldown
: https://github.com/apache/couchdb-documentation/pull/561/files