Is there any other option to extract columns from result than using the op.xpath?
For my code:
var data = op
.fromSearchDocs(cts.collectionQuery('xxx'))
.limit(100)
.select(columns.map(x => op.as(x, op.xpath('doc', '/' + x))))
.result()
.toArray()
data
This select:
.select(columns.map(x => op.as(x, op.xpath('doc', '/' + x))))
Increases the execution time of my code 10 times. The number of columns I want to extract is up to 500 and it is dynamic.
In other hand extracting data with jsearch:
import jsearch from '/MarkLogic/jsearch.mjs';
var res = jsearch
.documents()
.where(cts.collectionQuery('Transactions'))
.slice(0, 10000)
.map({extract: {paths: columns.map(x => '/' + x)}})
.result('iterator');
res
The result is return 4-5 times faster.
I want to use optic because I do some joins before select.
You do not mention how many items you have in your "columns" variable. 1? 100?
Whatever number that is, then multiply it by 100 *your limit). xPath has to go into the data and often extract it from compacted content.
For what you show above, I would suggest just pre-extracting your content into a view using a TDE template.
Your sample does not make use of any of the items from op.fromSearchDocs such as score for ordering etc, so in that case, you could just use:
op.fromView(your view info here)
.where(cts.collectionQuery('xxx'))
.limit(100)
....