Copilot commented on code in PR #180:
URL: https://github.com/apache/solr-orbit/pull/180#discussion_r4763056275


##########
solrorbit/conversion/workload_converter.py:
##########
@@ -750,6 +750,26 @@ def replace(match):
     return _MERGE_WAIT_OBJECT.sub(replace, text)
 
 
+def _convert_scroll(op: dict) -> None:
+    """
+    Rewrite a search with ``pages`` as a ``paginated-search``, which pages 
with Solr's cursorMark.
+
+    The query becomes ``q`` (and its filters ``fq``); no ``fl`` is set, so 
every stored field comes back as OpenSearch
+    returns ``_source``. A cursor needs a sort ending with the uniqueKey: 
upstream's sort gets ``id asc`` appended, and a
+    search without one is sorted by ``id asc``. OpenSearch's scroll orders by 
score and then index order, which a cursor
+    cannot use (``_docid_`` is refused).
+    """
+    body = op.pop("body")
+    translated = translate_to_solr_json_dsl(body)
+    op["operation-type"] = "paginated-search"
+    op["q"] = translated["query"]
+    if translated.get("filter"):
+        op["fq"] = translated["filter"]
+    sort = translated.get("sort")
+    op["sort"] = "id asc" if not sort else (sort if 
re.search(r"(^|,)\s*id\s+(asc|desc)\s*$", sort) else sort + ",id asc")

Review Comment:
   Scroll sorts such as `["population"]` and `["_doc"]` become `population,id 
asc` and `_doc,id asc`, respectively, so Solr rejects the cursor request. 
Normalize implicit directions and remove OpenSearch's document-order 
pseudo-sort before appending the unique key. Cover shorthand, object-form 
`_doc`, and mixed sorts in the conversion tests.



##########
solrorbit/conversion/workload_converter.py:
##########
@@ -898,6 +918,11 @@ def _convert_operation(op, issues, skipped, source_dir, 
output_dir):
         if setup:
             op.update(setup)
 
+    # A search paged with pages / results-per-page is OpenSearch Benchmark's 
scroll: Solr pages with a cursor
+    if op_type == "search" and "pages" in op and 
_is_opensearch_body(op.get("body")):
+        _convert_scroll(op)
+        return True

Review Comment:
   A valid match-all scroll can omit `body`, for example 
`{"operation-type":"search","pages":25,"results-per-page":1000}`. Here 
`_is_opensearch_body(None)` is false, so it remains a single-page `search` and 
the original pagination bug persists. Treat an absent body as an empty 
match-all body when detecting and converting scrolls.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to