I am execution below SPARQL query into qconsole, this query executed properly and returned a solution with 2346 items
, it took 5 ms
.
xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics" at "/MarkLogic/semantics.xqy";
let $distinct-ids := '
SELECT DISTINCT ?itemId
WHERE {
?itemId <hasListName> ?listName .
FILTER (lcase(str(?listName)) = "test")
}
'
return sem:sparql($distinct-ids)
My requirement is, I want to get the result as sequence
of items for further processing instead of solution.
I tried doing something like return map:get(sem:sparql($distinct-ids), "itemId")
, and it is Woking fine but took longer time (90 ms)
to get the result.
Is there any other way that is faster to get the sequence of items without using map:get
?
Does it make a difference if you specifically iterate over the results and call map:get()
for each item instead of relying on function mapping?
sem:sparql($distinct-ids) ! map:get(., "itemId")
What about applying the array
option to sem:sparql()
, and then for each item get the value with json:array-values()
?
sem:sparql($distinct-ids, (), "array") ! json:array-values(.)