try {
// When using the Cache, directly get the representations!
QueryResultList<Representation> representations = cache.findRepresentation((query));
results = new ArrayList<Entity>(representations.size());
for (Representation result : representations) {
Entity entity = new EntityImpl(getId(), result, null);
results.add(entity);
initEntityMetadata(entity, siteMetadata,
singletonMap(RdfResourceEnum.isChached.getUri(), (Object) Boolean.TRUE));
}
return new QueryResultListImpl<Entity>(query, results, Entity.class);
} catch (YardException e) {
if (entitySearcher == null) {
throw new SiteException("Unable to execute query on Cache "
+ siteConfiguration.getCacheId(), e);
} else {
log.warn(
String.format(
"Error while performing query on Cache %s! Try to use remote site %s as fallback!",
siteConfiguration.getCacheId(), siteConfiguration.getQueryUri()), e);
}
}
}
QueryResultList<String> entityIds;
if (entitySearcher == null) {
throw new SiteException(String.format("The ReferencedSite %s does not support queries!",
getId()));
}
try {
entityIds = entitySearcher.findEntities(query);
} catch (IOException e) {
throw new SiteException(String.format(
"Unable to execute query on remote site %s with entitySearcher %s!",
siteConfiguration.getQueryUri(), siteConfiguration.getEntitySearcherType()), e);
}
int numResults = entityIds.size();
List<Entity> entities = new ArrayList<Entity>(numResults);
int errors = 0;
SiteException lastError = null;
for (String id : entityIds) {
Entity entity;
try {
entity = getEntity(id);
if (entity == null) {
log.warn("Unable to create Entity for ID that was selected by an FieldQuery (id=" + id
+ ")");
}
entities.add(entity);
// use the position in the list as resultSocre
entity.getRepresentation().set(RdfResourceEnum.resultScore.getUri(),
Float.valueOf((float) numResults));
} catch (SiteException e) {
lastError = e;
errors++;
log.warn(String.format("Unable to get Representation for Entity "