Search in sources :

Example 6 with SolrServerFacade

use of cz.mzk.recordmanager.server.solr.SolrServerFacade in project RecordManager2 by moravianlibrary.

the class IndexIndividualHarvestedRecordsTasklet method execute.

@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
    SolrServerFacade solrServer = solrServerFactory.create(solrUrl, null, LoggingSolrIndexingExceptionHandler.INSTANCE);
    List<SolrInputDocument> documents = new ArrayList<SolrInputDocument>(recordIds.size());
    for (String solrId : recordIds) {
        HarvestedRecord rec = harvestedRecordDao.findBySolrId(solrId);
        if (rec == null) {
            throw new IllegalArgumentException(String.format("Harvested record %s not found", solrId));
        }
        SolrInputDocument document = solrInputDocumentFactory.create(rec);
        documents.add(SolrUtils.removeHiddenFields(document));
    }
    solrServer.add(documents, commitWithinMs);
    solrServer.commit();
    return RepeatStatus.FINISHED;
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) ArrayList(java.util.ArrayList) SolrServerFacade(cz.mzk.recordmanager.server.solr.SolrServerFacade) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord)

Example 7 with SolrServerFacade

use of cz.mzk.recordmanager.server.solr.SolrServerFacade in project RecordManager2 by moravianlibrary.

the class KrameriusHarvester method sendRequest.

public SolrDocumentList sendRequest(String nextPid) {
    SolrDocumentList documents = new SolrDocumentList();
    SolrServerFacade solr = solrServerFactory.create(params.getUrl(), Mode.KRAMERIUS);
    SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    if (nextPid != null) {
        query.add("fq", SolrUtils.createFieldQuery(PID_FIELD, SolrUtils.createRange(nextPid, null)));
    }
    // works with all possible models in single configuration
    String harvestedModelsStatement = String.join(" OR ", FedoraModels.HARVESTED_MODELS);
    query.add("fq", harvestedModelsStatement);
    if (params.getFrom() != null || params.getUntil() != null) {
        String range = SolrUtils.createDateRange(params.getFrom(), params.getUntil());
        query.add("fq", SolrUtils.createFieldQuery("modified_date", range));
    }
    logger.info("nextPid: {}", nextPid);
    query.setFields(PID_FIELD);
    query.setSort(PID_FIELD, ORDER.asc);
    query.setRows((params.getQueryRows() != null) ? params.getQueryRows().intValue() : 100);
    query.setTimeAllowed(MAX_TIME_ALLOWED);
    try {
        QueryResponse response = solr.query(query);
        documents = response.getResults();
    } catch (SolrServerException sse) {
        logger.error("Harvesting list of uuids from Kramerius API: caused SolrServerException for model: %s, url:%s and nextPid:%s", params.getModel(), params.getUrl(), nextPid);
        logger.error(sse.getMessage());
        return new SolrDocumentList();
    }
    return documents;
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrServerFacade(cz.mzk.recordmanager.server.solr.SolrServerFacade)

Example 8 with SolrServerFacade

use of cz.mzk.recordmanager.server.solr.SolrServerFacade in project RecordManager2 by moravianlibrary.

the class IndexIndividualRecordsTasklet method execute.

@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
    SolrServerFacade solrServer = solrServerFactory.create(solrUrl, null, LoggingSolrIndexingExceptionHandler.INSTANCE);
    for (String solrId : recordIds) {
        HarvestedRecord rec = harvestedRecordDao.findBySolrId(solrId);
        if (rec == null) {
            throw new IllegalArgumentException(String.format("Harvested record %s not found", solrId));
        }
        DedupRecord dedupRecord = rec.getDedupRecord();
        if (dedupRecord == null) {
            throw new IllegalArgumentException(String.format("Harvested record %s is not deduplicated, run dedup first.", solrId));
        }
        List<HarvestedRecord> records = harvestedRecordDao.getByDedupRecord(dedupRecord);
        List<SolrInputDocument> documents = solrInputDocumentFactory.create(dedupRecord, records);
        documents = SolrUtils.removeHiddenFields(documents);
        solrServer.add(documents, commitWithinMs);
    }
    solrServer.commit();
    return RepeatStatus.FINISHED;
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) DedupRecord(cz.mzk.recordmanager.server.model.DedupRecord) SolrServerFacade(cz.mzk.recordmanager.server.solr.SolrServerFacade) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord)

Example 9 with SolrServerFacade

use of cz.mzk.recordmanager.server.solr.SolrServerFacade in project RecordManager2 by moravianlibrary.

the class KrameriusHarvesterNoSorting method sendRequest.

public SolrDocumentList sendRequest(Integer start, String... fields) {
    SolrDocumentList documents = new SolrDocumentList();
    int numProcessed = 0;
    long numFound = 0;
    SolrServerFacade solr = solrServerFactory.create(params.getUrl(), Mode.KRAMERIUS);
    SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    // works with all possible models in single configuration
    String harvestedModelsStatement = String.join(" OR ", FedoraModels.HARVESTED_MODELS);
    query.add("fq", harvestedModelsStatement);
    if (params.getFrom() != null || params.getUntil() != null) {
        String range = SolrUtils.createDateRange(params.getFrom(), params.getUntil());
        query.add("fq", SolrUtils.createFieldQuery("modified_date", range));
    }
    logger.info("query: {}", query.getQuery());
    query.setFields(fields);
    if (start != null) {
        query.setStart(start);
    }
    query.setRows((params.getQueryRows() != null) ? params.getQueryRows().intValue() : 10);
    try {
        QueryResponse response = solr.query(query);
        documents = response.getResults();
        numFound = documents.getNumFound();
        numProcessed += response.getResults().size();
    } catch (SolrServerException sse) {
        logger.error("Harvesting list of uuids from Kramerius API: caused SolrServerException for model: %s, url:%s, when processed:%s of %s", params.getModel(), params.getUrl(), numProcessed, numFound);
        logger.error(sse.getMessage());
        return new SolrDocumentList();
    }
    return documents;
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrServerFacade(cz.mzk.recordmanager.server.solr.SolrServerFacade)

Aggregations

SolrServerFacade (cz.mzk.recordmanager.server.solr.SolrServerFacade)9 SolrQuery (org.apache.solr.client.solrj.SolrQuery)6 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)6 HashMap (java.util.HashMap)4 Job (org.springframework.batch.core.Job)4 JobExecution (org.springframework.batch.core.JobExecution)4 JobParameter (org.springframework.batch.core.JobParameter)4 JobParameters (org.springframework.batch.core.JobParameters)4 Test (org.testng.annotations.Test)4 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)2 SolrServerException (org.apache.solr.client.solrj.SolrServerException)2 SolrDocumentList (org.apache.solr.common.SolrDocumentList)2 SolrInputDocument (org.apache.solr.common.SolrInputDocument)2 DedupRecord (cz.mzk.recordmanager.server.model.DedupRecord)1 ArrayList (java.util.ArrayList)1 SolrDocument (org.apache.solr.common.SolrDocument)1 StepContribution (org.springframework.batch.core.StepContribution)1 StepScope (org.springframework.batch.core.configuration.annotation.StepScope)1 ChunkContext (org.springframework.batch.core.scope.context.ChunkContext)1 Tasklet (org.springframework.batch.core.step.tasklet.Tasklet)1