use of com.odysseusinc.arachne.portal.model.solr.SolrValue in project ArachneCentralAPI by OHDSI.
the class BaseSolrServiceImpl method createSolrDocument.
private SolrInputDocument createSolrDocument(final String entityType, final Long id, final Map<T, Object> values) {
final SolrInputDocument document = new SolrInputDocument();
for (final Map.Entry<T, Object> field : values.entrySet()) {
final T solrField = field.getKey();
final Object rawValue = field.getValue();
// Note: value for filtering and value for full-text search can differ.
// E.g. main value may be an id of object,
// and full-text search should be done over human-readable representation of such object
Object value = null;
Object queryValue = null;
// Parse saved value
if (rawValue != null) {
if (rawValue instanceof Collection<?>) {
final Collection rawValueList = (Collection) rawValue;
final int arrSize = rawValueList.size();
final Object[] valArray = new Object[arrSize];
final Object[] queryValArray = new Object[arrSize];
int index = 0;
for (final Object rawValueEntry : rawValueList) {
if (rawValueEntry instanceof SolrValue) {
valArray[index] = ((SolrValue) rawValueEntry).getSolrValue();
queryValArray[index] = ((SolrValue) rawValueEntry).getSolrQueryValue();
} else {
valArray[index] = rawValueEntry.toString();
queryValArray[index] = rawValueEntry.toString();
}
index++;
}
value = valArray;
queryValue = Arrays.toString(queryValArray);
} else {
if (rawValue instanceof SolrValue) {
value = ((SolrValue) rawValue).getSolrValue();
queryValue = ((SolrValue) rawValue).getSolrQueryValue();
} else {
value = rawValue.toString();
queryValue = rawValue.toString();
}
}
if (solrField.getSearchable()) {
document.addField(QUERY_FIELD_PREFIX + solrField.getName(), queryValue);
}
}
document.addField(solrField.getSolrName(), value);
if (solrField.isSortNeeded() && solrField.isMultiValuesType()) {
String valueForSort = null;
if (!StringUtils.isEmpty((String) queryValue)) {
final List<String> list = Arrays.asList(StringUtils.split(((String) queryValue)));
Collections.sort(list);
valueForSort = String.join(" ", list);
}
document.addField(solrField.getMultiValuesTypeFieldName(), valueForSort);
}
}
// these two fields will be concatenated into solr document id
if (document.getField(ID) == null) {
if (id == null) {
throw new IllegalArgumentException("Id cannot be null");
} else {
document.addField(ID, id);
}
}
document.addField(TYPE, entityType);
return document;
}
Aggregations