use of org.apache.solr.client.solrj.SolrServerException in project vind by RBMHTechnology.
the class SolrSearchServer method commit.
@Override
public void commit(boolean optimize) {
try {
solrClientLogger.debug(">>> commit()");
this.solrClient.commit();
if (optimize) {
solrClientLogger.debug(">>> optimize()");
this.solrClient.optimize();
}
} catch (SolrServerException | IOException e) {
log.error("Cannot commit", e);
throw new SearchServerException("Cannot commit", e);
}
}
use of org.apache.solr.client.solrj.SolrServerException in project opencast by opencast.
the class SeriesServiceSolrIndex method getSolrDocumentByID.
/**
* Returns SolrDocument corresponding to given ID or null if such document does not exist.
*
* @param id
* SolrDocument ID
* @return corresponding document
* @throws SeriesServiceDatabaseException
* if exception occurred
*/
protected SolrDocument getSolrDocumentByID(String id) throws SeriesServiceDatabaseException {
String orgId = securityService.getOrganization().getId();
StringBuilder solrQueryString = new StringBuilder(SolrFields.COMPOSITE_ID_KEY).append(":").append(ClientUtils.escapeQueryChars(getCompositeKey(id, orgId)));
SolrQuery q = new SolrQuery(solrQueryString.toString());
QueryResponse response;
try {
response = solrServer.query(q);
if (response.getResults().isEmpty()) {
return null;
} else {
return response.getResults().get(0);
}
} catch (SolrServerException e) {
logger.error("Could not perform series retrieval:", e);
throw new SeriesServiceDatabaseException(e);
}
}
use of org.apache.solr.client.solrj.SolrServerException in project opencast by opencast.
the class SolrIndexManager method delete.
/**
* Removes the entry with the given <code>id</code> from the database. The entry can either be a series or an episode.
*
* @param id
* identifier of the series or episode to delete
* @param deletionDate
* the deletion date
* @throws SolrServerException
* if an errors occurs while talking to solr
*/
public boolean delete(String id, Date deletionDate) throws SolrServerException {
try {
// Load the existing episode
QueryResponse solrResponse = null;
try {
SolrQuery query = new SolrQuery(Schema.ID + ":" + ClientUtils.escapeQueryChars(id) + " AND -" + Schema.OC_DELETED + ":[* TO *]");
solrResponse = solrServer.query(query);
} catch (Exception e1) {
throw new SolrServerException(e1);
}
// Did we find the episode?
if (solrResponse.getResults().size() == 0) {
logger.warn("Trying to delete non-existing media package {} from the search index", id);
return false;
}
// Use all existing fields
SolrDocument doc = solrResponse.getResults().get(0);
SolrInputDocument inputDocument = new SolrInputDocument();
for (String field : doc.getFieldNames()) {
inputDocument.setField(field, doc.get(field));
}
// Set the oc_deleted field to the current date, then update
Schema.setOcDeleted(inputDocument, deletionDate);
solrServer.add(inputDocument);
solrServer.commit();
return true;
} catch (IOException e) {
throw new SolrServerException(e);
}
}
use of org.apache.solr.client.solrj.SolrServerException in project opencast by opencast.
the class SolrRequester method createSearchResult.
/**
* Creates a search result from a given solr response.
*
* @param query
* The solr query.
* @return The search result.
* @throws SolrServerException
* if the solr server is not working as expected
*/
private SearchResult createSearchResult(final SolrQuery query) throws SolrServerException {
// Execute the query and try to get hold of a query response
QueryResponse solrResponse = null;
try {
solrResponse = solrServer.query(query);
} catch (Exception e) {
throw new SolrServerException(e);
}
// Create and configure the query result
final SearchResultImpl result = new SearchResultImpl(query.getQuery());
result.setSearchTime(solrResponse.getQTime());
result.setOffset(solrResponse.getResults().getStart());
result.setLimit(solrResponse.getResults().size());
result.setTotal(solrResponse.getResults().getNumFound());
// Walk through response and create new items with title, creator, etc:
for (final SolrDocument doc : solrResponse.getResults()) {
final SearchResultItemImpl item = SearchResultItemImpl.fill(new SearchResultItem() {
private final String dfltString = null;
@Override
public String getId() {
return Schema.getId(doc);
}
/**
* {@inheritDoc}
*
* @see org.opencastproject.search.api.SearchResultItem#getOrganization()
*/
@Override
public String getOrganization() {
return Schema.getOrganization(doc);
}
@Override
public MediaPackage getMediaPackage() {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
if (serializer != null)
builder.setSerializer(serializer);
String mediaPackageFieldValue = Schema.getOcMediapackage(doc);
if (mediaPackageFieldValue != null) {
try {
return builder.loadFromXml(mediaPackageFieldValue);
} catch (Exception e) {
logger.warn("Unable to read media package from search result", e);
}
}
return null;
}
@Override
public long getDcExtent() {
if (getType().equals(SearchResultItemType.AudioVisual)) {
Long extent = Schema.getDcExtent(doc);
if (extent != null)
return extent;
}
return -1;
}
@Override
public String getDcTitle() {
final List<DField<String>> titles = Schema.getDcTitle(doc);
// try to return the first title without any language information first...
return head(filter(titles, new Predicate<DField<String>>() {
@Override
public Boolean apply(DField<String> f) {
return f.getSuffix().equals(Schema.LANGUAGE_UNDEFINED);
}
})).map(new Function<DField<String>, String>() {
@Override
public String apply(DField<String> f) {
return f.getValue();
}
}).getOrElse(new Function0<String>() {
@Override
public String apply() {
// ... since none is present return the first arbitrary title
return Schema.getFirst(titles, dfltString);
}
});
}
@Override
public String getDcSubject() {
return Schema.getFirst(Schema.getDcSubject(doc), dfltString);
}
@Override
public String getDcDescription() {
return Schema.getFirst(Schema.getDcDescription(doc), dfltString);
}
@Override
public String getDcCreator() {
return Schema.getFirst(Schema.getDcCreator(doc), dfltString);
}
@Override
public String getDcPublisher() {
return Schema.getFirst(Schema.getDcPublisher(doc), dfltString);
}
@Override
public String getDcContributor() {
return Schema.getFirst(Schema.getDcContributor(doc), dfltString);
}
@Override
public String getDcAbstract() {
return null;
}
@Override
public Date getDcCreated() {
return Schema.getDcCreated(doc);
}
@Override
public Date getDcAvailableFrom() {
return Schema.getDcAvailableFrom(doc);
}
@Override
public Date getDcAvailableTo() {
return Schema.getDcAvailableTo(doc);
}
@Override
public String getDcLanguage() {
return Schema.getDcLanguage(doc);
}
@Override
public String getDcRightsHolder() {
return Schema.getFirst(Schema.getDcRightsHolder(doc), dfltString);
}
@Override
public String getDcSpatial() {
return Schema.getFirst(Schema.getDcSpatial(doc), dfltString);
}
@Override
public String getDcTemporal() {
return null;
}
@Override
public String getDcIsPartOf() {
return Schema.getDcIsPartOf(doc);
}
@Override
public String getDcReplaces() {
return Schema.getDcReplaces(doc);
}
@Override
public String getDcType() {
return Schema.getDcType(doc);
}
@Override
public String getDcAccessRights() {
return Schema.getFirst(Schema.getDcAccessRights(doc), dfltString);
}
@Override
public String getDcLicense() {
return Schema.getFirst(Schema.getDcLicense(doc), dfltString);
}
@Override
public String getOcMediapackage() {
return Schema.getOcMediapackage(doc);
}
@Override
public SearchResultItemType getType() {
String t = Schema.getOcMediatype(doc);
return t != null ? SearchResultItemType.valueOf(t) : null;
}
@Override
public String[] getKeywords() {
if (getType().equals(SearchResultItemType.AudioVisual)) {
String k = Schema.getOcKeywords(doc);
return k != null ? k.split(" ") : new String[0];
} else
return new String[0];
}
@Override
public String getCover() {
return Schema.getOcCover(doc);
}
@Override
public Date getModified() {
return Schema.getOcModified(doc);
}
@Override
public double getScore() {
return Schema.getScore(doc);
}
@Override
public MediaSegment[] getSegments() {
if (SearchResultItemType.AudioVisual.equals(getType()))
return createSearchResultSegments(doc, query).toArray(new MediaSegmentImpl[0]);
else
return new MediaSegmentImpl[0];
}
});
// Add the item to the result set
result.addItem(item);
}
return result;
}
use of org.apache.solr.client.solrj.SolrServerException in project opencast by opencast.
the class WorkflowServiceSolrIndex method getStatistics.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.impl.WorkflowServiceIndex#getStatistics()
*/
@Override
public WorkflowStatistics getStatistics() throws WorkflowDatabaseException {
long total = 0;
long paused = 0;
long failed = 0;
long failing = 0;
long instantiated = 0;
long running = 0;
long stopped = 0;
long succeeded = 0;
WorkflowStatistics stats = new WorkflowStatistics();
// Get all definitions and then query for the numbers and the current operation per definition
try {
String orgId = securityService.getOrganization().getId();
StringBuilder queryString = new StringBuilder().append(ORG_KEY).append(":").append(escapeQueryChars(orgId));
appendSolrAuthFragment(queryString, Permissions.Action.WRITE.toString());
SolrQuery solrQuery = new SolrQuery(queryString.toString());
solrQuery.addFacetField(WORKFLOW_DEFINITION_KEY);
solrQuery.addFacetField(OPERATION_KEY);
solrQuery.setFacetMinCount(0);
solrQuery.setFacet(true);
QueryResponse response = solrServer.query(solrQuery);
FacetField templateFacet = response.getFacetField(WORKFLOW_DEFINITION_KEY);
FacetField operationFacet = response.getFacetField(OPERATION_KEY);
// For every template and every operation
if (templateFacet != null && templateFacet.getValues() != null) {
for (Count template : templateFacet.getValues()) {
WorkflowDefinitionReport templateReport = new WorkflowDefinitionReport();
templateReport.setId(template.getName());
long templateTotal = 0;
long templatePaused = 0;
long templateFailed = 0;
long templateFailing = 0;
long templateInstantiated = 0;
long templateRunning = 0;
long templateStopped = 0;
long templateSucceeded = 0;
if (operationFacet != null && operationFacet.getValues() != null) {
for (Count operation : operationFacet.getValues()) {
OperationReport operationReport = new OperationReport();
operationReport.setId(operation.getName());
StringBuilder baseSolrQuery = new StringBuilder().append(ORG_KEY).append(":").append(escapeQueryChars(orgId));
appendSolrAuthFragment(baseSolrQuery, Permissions.Action.WRITE.toString());
solrQuery = new SolrQuery(baseSolrQuery.toString());
solrQuery.addFacetField(STATE_KEY);
solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.FAILED);
solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.FAILING);
solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.INSTANTIATED);
solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.PAUSED);
solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.RUNNING);
solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.STOPPED);
solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.SUCCEEDED);
solrQuery.addFilterQuery(WORKFLOW_DEFINITION_KEY + ":" + template.getName());
solrQuery.addFilterQuery(OPERATION_KEY + ":" + operation.getName());
solrQuery.setFacetMinCount(0);
solrQuery.setFacet(true);
response = solrServer.query(solrQuery);
// Add the states
FacetField stateFacet = response.getFacetField(STATE_KEY);
for (Count stateValue : stateFacet.getValues()) {
WorkflowState state = WorkflowState.valueOf(stateValue.getName().toUpperCase());
templateTotal += stateValue.getCount();
total += stateValue.getCount();
switch(state) {
case FAILED:
operationReport.setFailed(stateValue.getCount());
templateFailed += stateValue.getCount();
failed += stateValue.getCount();
break;
case FAILING:
operationReport.setFailing(stateValue.getCount());
templateFailing += stateValue.getCount();
failing += stateValue.getCount();
break;
case INSTANTIATED:
operationReport.setInstantiated(stateValue.getCount());
templateInstantiated += stateValue.getCount();
instantiated += stateValue.getCount();
break;
case PAUSED:
operationReport.setPaused(stateValue.getCount());
templatePaused += stateValue.getCount();
paused += stateValue.getCount();
break;
case RUNNING:
operationReport.setRunning(stateValue.getCount());
templateRunning += stateValue.getCount();
running += stateValue.getCount();
break;
case STOPPED:
operationReport.setStopped(stateValue.getCount());
templateStopped += stateValue.getCount();
stopped += stateValue.getCount();
break;
case SUCCEEDED:
operationReport.setFinished(stateValue.getCount());
templateSucceeded += stateValue.getCount();
succeeded += stateValue.getCount();
break;
default:
throw new IllegalStateException("State '" + state + "' is not handled");
}
}
templateReport.getOperations().add(operationReport);
}
}
// Update the template statistics
templateReport.setTotal(templateTotal);
templateReport.setFailed(templateFailed);
templateReport.setFailing(templateFailing);
templateReport.setInstantiated(templateInstantiated);
templateReport.setPaused(templatePaused);
templateReport.setRunning(templateRunning);
templateReport.setStopped(templateStopped);
templateReport.setFinished(templateSucceeded);
// Add the definition report to the statistics
stats.getDefinitions().add(templateReport);
}
}
} catch (SolrServerException e) {
throw new WorkflowDatabaseException(e);
}
stats.setTotal(total);
stats.setFailed(failed);
stats.setFailing(failing);
stats.setInstantiated(instantiated);
stats.setPaused(paused);
stats.setRunning(running);
stats.setStopped(stopped);
stats.setFinished(succeeded);
return stats;
}
Aggregations