Samplestack extensions not compatible with MarkLogic 9 JavaScript
Hi Charles— I’m playing around with the Optic EA3 stuff (instructions at https://ea.marklogic.com/features/data-integration/optic-api/) and I’m trying to use the UI. The port is open, no errors in the log, but the server is throwing this error:
2016-09-27 11:42:34.839 Info: Status 500: JS-JAVASCRIPT: var sourceDoc = fn.doc(uri).next().value; -- Error running JavaScript request: TypeError: fn.doc(...).next is not a function
The UI is giving me this exception:
{"data":{"status":400,"message":"com.marklogic.client.FailedRequestException: Local message: search failed: Bad Request. Server Message: JS-JAVASCRIPT: var sourceDoc = fn.doc(uri).next().value; -- Error running JavaScript request: TypeError: fn.doc(...).next is not a function"},"status":400,"config":{"method":"POST","transformRequest":[null],"transformResponse":[null,null],"url":"/v1/search","data":{"search":{"qtext":["","sort:active"],"start":1,"timezone":"America/New_York"}},"timeout":60000,"headers":{"Accept":"application/json, text/plain, /","Content-Type":"application/json;charset=utf-8"}},"statusText":"Bad Request”}
$scope.runSearch/<@http://localhost:8090/app/states/explore.js:300:21 processQueue@http://localhost:8090/deps/angular/angular.js:13170:27 scheduleProcessQueue/<@http://localhost:8090/deps/angular/angular.js:13186:27 $RootScopeProvider/this.$get
This would appear to be a compatibility issue that arose when we changed the iterable api in ML. I believe the solution would be to fix the JS transform in the server.
https://github.com/marklogic/marklogic-samplestack/blob/master/database/transforms/search-response.sjs#L98
var answersSource = sourceDoc.xpath(answerNodePath).next().value;
to something like
const pos = sourceDoc.xpath(answerNodePath);
const answersSource = pos.toArray ? pos.toArray()[0] : pos.next().value;
would probably do it, I think, but not tested.
fn.head(…) will work in MarkLogic ≥8.
Verified that this bug prevents the application from working, and also prevents loading of RDF data. The database is other wise loaded correctly.
After making these changes in search-response.sjs following tests are giving assertions error at the time of deploying samplestack.
DatabaseQnADocumentSearchIT. guestSearchSeesOnlyResolvedQuestions
DatabaseQnADocumentSearchIT. testAcceptedSearch
DatabaseQnADocumentSearchIT. testActivitySearch
DatabaseQnADocumentSearchIT. testResponseExtracts
QnADocumentControllerIT. testAnonymousAccessToAccepted
TagControllerIT. testRelatedTags
TagControllerIT. testSortFrequency