Search in sources :

Example 1 with MarkLogicConnection

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);
}
Also used : MarkLogicConnection(org.talend.components.marklogic.connection.MarkLogicConnection) SearchHandle(com.marklogic.client.io.SearchHandle) DocContentReader(org.talend.components.marklogic.runtime.input.strategies.DocContentReader)

Aggregations

SearchHandle (com.marklogic.client.io.SearchHandle)1 MarkLogicConnection (org.talend.components.marklogic.connection.MarkLogicConnection)1 DocContentReader (org.talend.components.marklogic.runtime.input.strategies.DocContentReader)1