use of org.talend.components.marklogic.connection.MarkLogicConnection in project components by Talend.
the class MarkLogicCriteriaReader method start.
@Override
public boolean start() throws IOException {
MarkLogicConnection connection = (MarkLogicConnection) getCurrentSource();
result = new ResultWithLongNB();
connectionClient = connection.connect(container);
if (connectionClient == null) {
return false;
}
docManager = connectionClient.newDocumentManager();
boolean isDocContentFieldPresent = (settings.outputSchema.getFields().size() >= 2);
if (isDocContentFieldPresent) {
docContentField = settings.outputSchema.getFields().get(1);
}
docContentReader = new DocContentReader(docManager, settings.outputSchema, docContentField);
if (settings.useQueryOption && StringUtils.isNotEmpty(settings.queryOptionName)) {
prepareQueryOption();
}
queryManager = connectionClient.newQueryManager();
stringQueryDefinition = (settings.useQueryOption) ? queryManager.newStringDefinition(settings.queryOptionName) : queryManager.newStringDefinition();
stringQueryDefinition.setCriteria(settings.criteria);
searchHandle = queryManager.search(stringQueryDefinition, new SearchHandle());
matchedDocuments = searchHandle.getTotalResults();
pageSize = (settings.pageSize <= 0) ? matchedDocuments : settings.pageSize;
// if < 0 - it will be ignored
maxRetrieve = settings.maxRetrieve;
queryManager.setPageLength(pageSize);
documentCounter = 1;
readNextPage();
return (matchedDocuments > 0);
}
Aggregations