Search in sources :

Example 1 with SolrIndexerException

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;
    }
}
Also used : InputStream(java.io.InputStream) Metadata(org.apache.tika.metadata.Metadata) XWikiException(com.xpn.xwiki.XWikiException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException)

Example 2 with SolrIndexerException

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);
    }
}
Also used : SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException)

Example 3 with SolrIndexerException

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;
}
Also used : Locale(java.util.Locale) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) EntityReference(org.xwiki.model.reference.EntityReference) ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) XWikiException(com.xpn.xwiki.XWikiException)

Example 4 with SolrIndexerException

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;
}
Also used : Locale(java.util.Locale) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException)

Example 5 with SolrIndexerException

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);
        }
    }
}
Also used : SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) IndexerRequest(org.xwiki.search.solr.internal.job.IndexerRequest)

Aggregations

SolrIndexerException (org.xwiki.search.solr.internal.api.SolrIndexerException)12 XWikiException (com.xpn.xwiki.XWikiException)7 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)5 ArrayList (java.util.ArrayList)4 Locale (java.util.Locale)4 EntityReference (org.xwiki.model.reference.EntityReference)4 XWikiContext (com.xpn.xwiki.XWikiContext)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 QueryException (org.xwiki.query.QueryException)2 BaseObject (com.xpn.xwiki.objects.BaseObject)1 BaseProperty (com.xpn.xwiki.objects.BaseProperty)1 InputStream (java.io.InputStream)1 Metadata (org.apache.tika.metadata.Metadata)1 Test (org.junit.Test)1 EntityType (org.xwiki.model.EntityType)1 ObjectPropertyReference (org.xwiki.model.reference.ObjectPropertyReference)1 IndexerRequest (org.xwiki.search.solr.internal.job.IndexerRequest)1