}
// process the hits, build the results
LOGGER.finer("Processing "+nTotal+" records from: "+(startRecord+1)+" to: "+numDocs);
Storeable storeable;
DiscoveredRecords records = discoveryResult.getRecords();
IndexReader reader = searcher.getIndexReader();
for (int i=startRecord; i<numDocs; i++) {
ScoreDoc scoreDoc = scoreDocs[i];
Document document = reader.document(scoreDoc.doc);
DiscoveredRecord record = new DiscoveredRecord();
// Dublin Core based responses
if (isDublinCoreResponse) {
for (Discoverable target: returnables) {
ArrayList<Object> values = new ArrayList<Object>();
storeable = (Storeable)target.getStorable();
if (storeable instanceof AnyTextProperty) {
values = null;
} else if (storeable instanceof GeometryProperty) {
GeometryProperty geom = (GeometryProperty)storeable;
values.add(geom.readEnvelope(document));
} else if (target.getMeaning().getMeaningType().equals(PropertyMeaningType.XMLURL)) {
String uuid = document.get(Storeables.FIELD_UUID);
uuid = URLEncoder.encode(uuid,"UTF-8");
values.add("?getxml="+uuid);
} else {
DatastoreField retrievalField = storeable.getRetrievalField();
Field[] fields = document.getFields(retrievalField.getName());
if (fields != null) {
for (Field f: fields) {
Object value = retrievalField.makeValueToReturn(f.stringValue());
values.add(value);
}
}
}
if (values != null) {
Object [] oValues = null;
if (values.size() >= 0) oValues = values.toArray();
record.addField(target,oValues);
}
}
// non Dublin Core based responses
} else {
String responseXml = null;
if (isBriefResponse && (responseXml == null)) {
Field field = document.getField(Storeables.FIELD_XML_BRIEF);
if (field != null) {
responseXml = field.stringValue();
}
} else if (isSummaryResponse && (responseXml == null)) {
Field field = document.getField(Storeables.FIELD_XML_SUMMARY);
if (field != null) {
responseXml = field.stringValue();
}
} else if (responseXml == null) {
Field field = document.getField(Storeables.FIELD_XML);
if (field != null) {
responseXml = field.stringValue();
}
}
record.setResponseXml(responseXml);
}
onRecord(record, document);
records.add(record);
}
int nPopulated = records.size();
LOGGER.finer("Populated "+nPopulated+" records.");
} finally {
getIndexAdapter().closeSearcher(searcher);
}