Skip to content

Commit

Permalink
Add generated record ID to Solr document if it is not extractable fro…
Browse files Browse the repository at this point in the history
…m the data source
  • Loading branch information
pkiraly committed Nov 13, 2024
1 parent fe2debe commit 798f2f8
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main/java/de/gwdg/metadataqa/api/calculator/Indexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,30 @@ public class Indexer extends QaSolrClient implements Calculator, Shutdownable, S
private static final Logger LOGGER = Logger.getLogger(Indexer.class.getCanonicalName());

public static final String CALCULATOR_NAME = "indexer";
private int generatedRecordId;
private int indexCounter;


public Indexer(SolrClient solrClient, Schema schema) {
super(solrClient, schema);
solrClient.deleteAll();
generatedRecordId = 1;
indexCounter = 0;
LOGGER.info("Indexer created " + solrClient.getClass().getCanonicalName());
}

@Override
public List<MetricResult> measure(Selector cache) {
try {
List<String> extractedValues = extractValue(cache, schema.getRecordId().getPath());
if (extractedValues.isEmpty())
throw new RuntimeException(String.format("Missing record ID (path: %s)", schema.getRecordId().getPath()));
String recordId = extractedValues.get(0);
String recordId = null;
if (extractedValues.isEmpty()) {
LOGGER.severe("id label: " + schema.getRecordId().getLabel());
LOGGER.severe(String.format("Missing record ID (path: %s)", schema.getRecordId().getPath()));
recordId = "unknownId-" + generatedRecordId++;
} else {
recordId = extractedValues.get(0);
}

Map<String, List<String>> resultMap = new HashMap<>();
for (UniquenessField solrField : solrFields) {
Expand All @@ -45,6 +56,7 @@ public List<MetricResult> measure(Selector cache) {
resultMap.put(solrField.getSolrField(), values);
}
solrClient.indexMap(recordId, resultMap);
indexCounter++;
} catch (IOException | SolrServerException e) {
e.printStackTrace();
} catch (Exception e) {
Expand Down Expand Up @@ -75,7 +87,7 @@ public String getCalculatorName() {

@Override
public void shutDown() {
LOGGER.info("shutDown");
LOGGER.info("shutDown solr. Counter: " + indexCounter);
solrClient.commit();
}
}

0 comments on commit 798f2f8

Please sign in to comment.