}
// Make sure the resource is not being referenced elsewhere
if (allRevisions || uri.getVersion() == Resource.LIVE) {
SearchQuery searchByResource = new SearchQueryImpl(uri.getSite());
searchByResource.withVersion(Resource.LIVE);
searchByResource.withProperty("resourceid", uri.getIdentifier());
if (searchIndex.getByQuery(searchByResource).getDocumentCount() > 0) {
logger.debug("Resource '{}' is still being referenced", uri);
throw new ReferentialIntegrityException(uri.getIdentifier());
}