pgj opened a new pull request, #4704:
URL: https://github.com/apache/couchdb/pull/4704

   Facet results are rendered inconsistently in the JSON response because a 
single zero-valued scalar is added to the place of the object which would 
otherwise represent the detailed statistics.
   
   For example, a "no match" search with counts faceting, such as
   
   ```
   /{db}/_design/{ddoc}/_search/{idx}?limit=0&q=city1:London*&counts=["city2"]
   ```
   
   (where there are no documents matching the query, i.e. no `city1` field has 
a value `London`) results in the following JSON:
   
   ```json
   "counts": {
     "city2": 0.0
   }
   ```
   
   but it should be like this instead:
   
   ```json
   "counts": {
     "city2": {}
   }
   ```
   
   That is because the expectation is that `city2` would contain a map of other 
city counts (if there were matches), e.g.
   
   ```json
   "counts": {
     "city2": {
       "Aberystwyth": 1004,
       "Bristol": 1019
     }
   }
   ```
   
   There is a similar impact for ranges.  Although the following one is a 
meaningless query (because there is no range defined), it manifests the same 
issue:
   
   ```
   /{db}/_design/{ddoc}/_search/{idx}?q=*:*&limit=0&ranges={"code":{"high":""}}
   ```
   
   Response:
   
   ```json
   {
     "total_rows": 5095,
     "bookmark": "g2o",
     "rows": [],
     "ranges": {
       "code": 0
     }
   }
   ```
   
   which should be:
   
   ```json
   {
     "total_rows": 5095,
     "bookmark": "g2o",
     "rows": [],
     "ranges": {
       "code": {}
     }
   }
   ```
   
   That is because the expectation is that the value for the field code should 
be the mapping of ranges to counts, not a count itself, viz.
   
   ```
   
/{db}/_design/{ddoc}/_search/{idx}?q=*:*&limit=0&ranges={"code":{"low":"[0%20TO%2010]","high":"[11%20TO%20Infinity]"}}
   ```
   
   returns
   
   ```json
   {
     "total_rows": 5095,
     "bookmark": "g2o",
     "rows": [],
     "ranges": {
       "code": {
         "high": 0,
         "low": 5095
       }
     }
   }
   ```
   
   This makes hard to properly capture the schema of the respective API and 
complicates the development of the SDK.
   
   Thanks @ricellis for the detailed analysis of the problem, the examples, and 
his proposal about the solution.
   
   ## Checklist
   
   - [x] Code is written and works correctly
   - [x] Changes are covered by tests
   


-- 
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]

Reply via email to