use of org.xwiki.search.solr.internal.api.SolrIndexerException in project xwiki-platform by xwiki.
the class AbstractSolrMetadataExtractor method getContentAsText.
/**
* Tries to extract text indexable content from a generic attachment.
*
* @param attachment the attachment to extract the content from
* @return the text representation of the attachment's content
* @throws SolrIndexerException if problems occur
*/
protected String getContentAsText(XWikiAttachment attachment) {
try {
Metadata metadata = new Metadata();
metadata.set(TikaMetadataKeys.RESOURCE_NAME_KEY, attachment.getFilename());
InputStream in = attachment.getContentInputStream(this.xcontextProvider.get());
try {
return TikaUtils.parseToString(in, metadata);
} finally {
in.close();
}
} catch (Exception e) {
this.logger.error("Failed to retrieve the content of attachment [{}]", attachment.getReference(), e);
return null;
}
}
use of org.xwiki.search.solr.internal.api.SolrIndexerException in project xwiki-platform by xwiki.
the class AbstractSolrMetadataExtractor method getSolrDocument.
@Override
public LengthSolrInputDocument getSolrDocument(EntityReference entityReference) throws SolrIndexerException, IllegalArgumentException {
try {
LengthSolrInputDocument solrDocument = new LengthSolrInputDocument();
solrDocument.setField(FieldUtils.ID, getResolver(entityReference).getId(entityReference));
if (!setDocumentFields(new DocumentReference(entityReference.extractReference(EntityType.DOCUMENT)), solrDocument)) {
return null;
}
solrDocument.setField(FieldUtils.TYPE, entityReference.getType().name());
if (!setFieldsInternal(solrDocument, entityReference)) {
return null;
}
return solrDocument;
} catch (Exception e) {
String message = String.format("Failed to get input Solr document for entity '%s'", entityReference);
throw new SolrIndexerException(message, e);
}
}
use of org.xwiki.search.solr.internal.api.SolrIndexerException in project xwiki-platform by xwiki.
the class DocumentSolrReferenceResolver method getReferences.
@Override
public List<EntityReference> getReferences(EntityReference reference) throws SolrIndexerException {
List<EntityReference> result = new ArrayList<EntityReference>();
XWikiContext xcontext = this.xcontextProvider.get();
DocumentReference documentReference = new DocumentReference(reference);
if (xcontext.getWiki().exists(documentReference, xcontext)) {
// Document itself
result.add(documentReference);
// https://jira.xwiki.org/browse/XWIKI-69 is the long standing issue on which the second assumption relies.
if (documentReference.getLocale() == null || documentReference.getLocale().equals(Locale.ROOT)) {
XWikiDocument document;
try {
document = getDocument(documentReference);
} catch (Exception e) {
throw new SolrIndexerException(String.format("Failed to get document [%s]", documentReference), e);
}
// Document translations
List<Locale> translatedLocales;
try {
translatedLocales = document.getTranslationLocales(xcontext);
} catch (XWikiException e) {
throw new SolrIndexerException(String.format("Failed to get document [%s] translations", documentReference), e);
}
for (Locale translatedLocale : translatedLocales) {
DocumentReference translatedDocumentReference = new DocumentReference(documentReference, translatedLocale);
result.add(translatedDocumentReference);
}
// Attachments
addAttachmentsReferences(document, result);
// Objects
addObjectsReferences(document, result);
}
}
return result;
}
use of org.xwiki.search.solr.internal.api.SolrIndexerException in project xwiki-platform by xwiki.
the class DocumentSolrReferenceResolver method getLocale.
/**
* @param documentReference reference to the document.
* @return the locale code of the referenced document.
* @throws SolrIndexerException if problems occur.
*/
protected Locale getLocale(DocumentReference documentReference) throws SolrIndexerException {
Locale locale = null;
try {
if (documentReference.getLocale() != null && !documentReference.getLocale().equals(Locale.ROOT)) {
locale = documentReference.getLocale();
} else {
XWikiContext xcontext = this.xcontextProvider.get();
locale = xcontext.getWiki().getDocument(documentReference, xcontext).getRealLocale();
}
} catch (Exception e) {
throw new SolrIndexerException(String.format("Exception while fetching the locale of the document '%s'", documentReference), e);
}
return locale;
}
use of org.xwiki.search.solr.internal.api.SolrIndexerException in project xwiki-platform by xwiki.
the class SolrIndexInitializeListener method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
if (this.configuration.synchronizeAtStartup()) {
// Start synchronization
IndexerRequest request = new IndexerRequest();
request.setId(Arrays.asList("solr", "indexer"));
try {
this.solrIndexer.get().startIndex(request);
} catch (SolrIndexerException e) {
this.logger.error("Failed to start initial Solr index synchronization", e);
}
}
}
Aggregations