couchdb-nano icon indicating copy to clipboard operation
couchdb-nano copied to clipboard

Search drilldown fails with multiple parameters

Open glynnbird opened this issue 5 years ago • 1 comments

The db.search function has an optional drilldown parameter which can be either

  1. an array e.g.
db.search('ddoc', 'search', {
  q: '*:*',
  drilldown: ['author','Dickens']
})

or

  1. 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 become drilldown=["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

glynnbird avatar Mar 15 '19 09:03 glynnbird

FYI, new releases of CouchDB allow for new ways of supplying drilldown: https://github.com/apache/couchdb-documentation/pull/561/files

bessbd avatar Jul 06 '20 10:07 bessbd