Revision 10112
Added by Jing Tao almost 8 years ago
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/SolrIndex.java | ||
---|---|---|
244 | 244 |
} |
245 | 245 |
} |
246 | 246 |
|
247 |
/*if(docs != null) { |
|
248 |
SolrDoc solrDoc = docs.get(id); |
|
249 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
250 |
solrDoc.serialize(baos, "UTF-8"); |
|
251 |
log.warn("after process the science metadata, the solr doc is \n"+baos.toString()); |
|
252 |
}*/ |
|
253 |
|
|
247 | 254 |
// TODO: in the XPathDocumentParser class in d1_cn_index_process module, |
248 | 255 |
// merge is only for resource map. We need more work here. |
249 | 256 |
for (SolrDoc mergeDoc : docs.values()) { |
... | ... | |
252 | 259 |
} |
253 | 260 |
} |
254 | 261 |
|
262 |
/*if(docs != null) { |
|
263 |
SolrDoc solrDoc = docs.get(id); |
|
264 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
265 |
solrDoc.serialize(baos, "UTF-8"); |
|
266 |
log.warn("after merge, the solr doc is \n"+baos.toString()); |
|
267 |
}*/ |
|
255 | 268 |
//SolrElementAdd addCommand = getAddCommand(new ArrayList<SolrDoc>(docs.values())); |
256 | 269 |
|
257 | 270 |
return docs; |
... | ... | |
285 | 298 |
EncoderException, XPathExpressionException, SolrServerException, ParserConfigurationException, SAXException, NotImplemented, NotFound, UnsupportedType { |
286 | 299 |
List<String> ids = new ArrayList<String>(); |
287 | 300 |
ids.add(indexDocument.getIdentifier()); |
301 |
//Retrieve the existing solr document from the solr server for the id. If it doesn't exist, null or empty solr doc will be returned. |
|
288 | 302 |
List<SolrDoc> indexedDocuments = ResourceMapSubprocessor.getSolrDocs(ids); |
289 | 303 |
SolrDoc indexedDocument = indexedDocuments == null || indexedDocuments.size() <= 0 ? null |
290 | 304 |
: indexedDocuments.get(0); |
... | ... | |
300 | 314 |
.getName().equals(SolrElementField.FIELD_RESOURCEMAP)) |
301 | 315 |
&& !indexDocument.hasFieldWithValue(field.getName(), field.getValue())) { |
302 | 316 |
indexDocument.addField(field); |
303 |
} else if (!indexSchema.isCopyFieldTarget(indexSchema.getField(field.getName())) && !indexDocument.hasField(field.getName())) { |
|
317 |
} else if (!indexSchema.isCopyFieldTarget(indexSchema.getField(field.getName())) && !indexDocument.hasField(field.getName()) && !isSystemMetadataField(field.getName())) { |
|
318 |
// we don't merge the system metadata field since they can be removed. |
|
319 |
log.debug("SolrIndex.mergeWithIndexedDocument - merge the existing solr field "+field.getName()+" with value "+field.getValue()+" from the solr server to the currently processing document of "+indexDocument.getIdentifier()); |
|
304 | 320 |
indexDocument.addField(field); |
305 | 321 |
} |
306 | 322 |
} |
... | ... | |
311 | 327 |
} |
312 | 328 |
|
313 | 329 |
/* |
330 |
* If the given field name is a system metadata field. |
|
331 |
*/ |
|
332 |
private boolean isSystemMetadataField(String fieldName) { |
|
333 |
boolean is = false; |
|
334 |
if (fieldName != null && !fieldName.trim().equals("") && sysmetaSolrFields != null) { |
|
335 |
for(SolrField field : sysmetaSolrFields) { |
|
336 |
if(field != null && field.getName() != null && field.getName().equals(fieldName)) { |
|
337 |
log.debug("SolrIndex.isSystemMetadataField - the field name "+fieldName+" matches one record of system metadata field list. It is a system metadata field."); |
|
338 |
is = true; |
|
339 |
break; |
|
340 |
} |
|
341 |
} |
|
342 |
} |
|
343 |
return is; |
|
344 |
} |
|
345 |
/* |
|
314 | 346 |
* Generate a Document from the InputStream |
315 | 347 |
*/ |
316 | 348 |
private Document generateXmlDocument(InputStream smdStream) throws SAXException { |
Also available in: Unified diff
During index merging process, if a field is a system metadata field and current document doesn't have the field, we don't need to merge it from the existing solr document.