Skip to content

Commit 8fffb71

Browse files
paynejdclaude
andauthored
Set num_returned on $match response for analytics item_count (#856)
* OpenConceptLab/ocl_online#73 | Set num_returned on \$match response Surfaces the total number of matched items on the MetadataToConceptsListView (\$match) response so the analytics middleware can record it as APITransaction.item_count. Before this fix, \$match transactions always recorded item_count=0 because the POST handler returned Response(results) with no headers, and analytics reads item_count from response.headers.num_returned. num_returned is set to the sum of len(r['results']) across all input rows — the total matches produced by the request, which is the denominator the v2 data extraction plan (item 11) wants for mapper_items_matched_30d / "rows matched per request" metrics. Scope is \$match only. \$match-scispacy-loinc lives in ocl-scispacy-loinc and needs a separate fix if we want item counts there too. Rerank view has different semantics and is out of scope. Refs #1 (data-extraction-v2 Bundle 2 loose ends). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Trim $match item_count comment Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9575b3a commit 8fffb71

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

core/concepts/views.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,15 @@ def post(self, request, **kwargs): # pylint: disable=unused-argument
987987
{'detail': 'You are currently in waitlist for $match operation.'},
988988
status=status.HTTP_403_FORBIDDEN
989989
)
990-
return Response(self.filter_queryset())
990+
results = self.filter_queryset()
991+
response = Response(results)
992+
# num_returned is picked up by the analytics middleware as
993+
# APITransaction.item_count (see ocl_online#73).
994+
if isinstance(results, list):
995+
response['num_returned'] = sum(
996+
len(r.get('results', [])) for r in results if isinstance(r, dict)
997+
)
998+
return response
991999

9921000

9931001
class RerankConceptsListView(BaseAPIView):

0 commit comments

Comments
 (0)