Project

General

Profile

« Previous | Next » 

Revision 8503

check for existing index document before trying to use existing fields.

View differences:

metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/SolrIndex.java
388 388
			// copy the original values already indexed for this document	
389 389
	    	SolrQuery query = new SolrQuery("id:\"" + pid.getValue() + "\"");
390 390
	    	QueryResponse res = solrServer.query(query);
391
	    	SolrDocument orig = res.getResults().get(0);
392 391
	    	SolrDoc doc = new SolrDoc();
393
	        IndexSchema indexSchema = SolrQueryServiceController.getInstance().getSchema();
394
	    	for (String fieldName: orig.getFieldNames()) {
395
	        	//  don't transfer the copyTo fields, otherwise there are errors
396
	        	if (indexSchema.isCopyFieldTarget(indexSchema.getField(fieldName))) {
397
	        		continue;
398
	        	}
399
	        	for (Object value: orig.getFieldValues(fieldName)) {
400
	        		String stringValue = value.toString();
401
	        		// special handling for dates in ISO 8601
402
	        		if (value instanceof Date) {
403
	        			stringValue = DateTimeMarshaller.serializeDateToUTC((Date)value);
404
	        			SolrDateConverter converter = new SolrDateConverter();
405
	        			stringValue = converter.convert(stringValue);
406
	        		}
407
					SolrElementField field = new SolrElementField(fieldName, stringValue);
408
					log.debug("Adding field: " + fieldName);
409
					doc.addField(field);
410
	        	}
392
	    	
393
	    	// include existing values if they exist
394
	        if (res.getResults().size() > 0) {
395
		        SolrDocument orig = res.getResults().get(0);
396
		        IndexSchema indexSchema = SolrQueryServiceController.getInstance().getSchema();
397
		    	for (String fieldName: orig.getFieldNames()) {
398
		        	//  don't transfer the copyTo fields, otherwise there are errors
399
		        	if (indexSchema.isCopyFieldTarget(indexSchema.getField(fieldName))) {
400
		        		continue;
401
		        	}
402
		        	for (Object value: orig.getFieldValues(fieldName)) {
403
		        		String stringValue = value.toString();
404
		        		// special handling for dates in ISO 8601
405
		        		if (value instanceof Date) {
406
		        			stringValue = DateTimeMarshaller.serializeDateToUTC((Date)value);
407
		        			SolrDateConverter converter = new SolrDateConverter();
408
		        			stringValue = converter.convert(stringValue);
409
		        		}
410
						SolrElementField field = new SolrElementField(fieldName, stringValue);
411
						log.debug("Adding field: " + fieldName);
412
						doc.addField(field);
413
		        	}
414
		        }
411 415
	        }
412 416
	    	
413 417
	        // add the additional fields we are trying to include in the index

Also available in: Unified diff