You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by "pgj (via GitHub)" <gi...@apache.org> on 2023/07/27 10:10:53 UTC

[GitHub] [couchdb] pgj opened a new pull request, #4704: fix(`dreyfus`): make faceting produce maps on empty results

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: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [couchdb] big-r81 merged pull request #4704: fix(`dreyfus`): make faceting produce maps on empty results

Posted by "big-r81 (via GitHub)" <gi...@apache.org>.
big-r81 merged PR #4704:
URL: https://github.com/apache/couchdb/pull/4704


-- 
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: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [couchdb] rnewson commented on a diff in pull request #4704: fix(`dreyfus`): make faceting produce maps on empty results

Posted by "rnewson (via GitHub)" <gi...@apache.org>.
rnewson commented on code in PR #4704:
URL: https://github.com/apache/couchdb/pull/4704#discussion_r1276085532


##########
src/dreyfus/src/dreyfus_httpd.erl:
##########
@@ -673,7 +673,12 @@ group_to_json(DbName, IncludeDocs, {Name, TotalHits, Hits}, UseNewApi) ->
 facets_to_json(Facets) ->
     {[facet_to_json(F) || F <- Facets]}.
 
-facet_to_json({K, V, []}) ->
+facet_to_json({K, V0, []}) ->
+    V =
+        case (V0 == 0) of

Review Comment:
   suggest a more concise;
   
   ```
   facet_to_json({K, 0, []}) ->
       {hd(K), {[]}};
   ```
   



-- 
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: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org