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;
}
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;
}
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;
}
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;
}
Aggregations