Search in sources :

Example 11 with SolrIndexerException

use of org.xwiki.search.solr.internal.api.SolrIndexerException in project xwiki-platform by xwiki.

the class ObjectSolrReferenceResolver method getReferences.

@Override
public List<EntityReference> getReferences(EntityReference objectReference) throws SolrIndexerException {
    List<EntityReference> result = new ArrayList<>();
    // Object itself
    result.add(objectReference);
    // Object properties
    DocumentReference documentReference = new DocumentReference(objectReference.getParent());
    XWikiDocument document;
    try {
        document = getDocument(documentReference);
    } catch (Exception e) {
        throw new SolrIndexerException("Failed to get document for object [" + objectReference + "]", e);
    }
    BaseObject object = document.getXObject(objectReference);
    if (object != null) {
        for (Object field : object.getFieldList()) {
            BaseProperty<ObjectPropertyReference> objectProperty = (BaseProperty<ObjectPropertyReference>) field;
            ObjectPropertyReference objectPropertyReference = objectProperty.getReference();
            try {
                Iterables.addAll(result, this.objectPropertyResolverProvider.get().getReferences(objectPropertyReference));
            } catch (Exception e) {
                this.logger.error("Failed to resolve references for object property [" + objectPropertyReference + "]", e);
            }
        }
    }
    return result;
}
Also used : SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ObjectPropertyReference(org.xwiki.model.reference.ObjectPropertyReference) EntityReference(org.xwiki.model.reference.EntityReference) ArrayList(java.util.ArrayList) BaseObject(com.xpn.xwiki.objects.BaseObject) BaseProperty(com.xpn.xwiki.objects.BaseProperty) DocumentReference(org.xwiki.model.reference.DocumentReference) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 12 with SolrIndexerException

use of org.xwiki.search.solr.internal.api.SolrIndexerException in project xwiki-platform by xwiki.

the class SpaceSolrReferenceResolver method getReferences.

@Override
public List<EntityReference> getReferences(EntityReference spaceReference) throws SolrIndexerException {
    List<EntityReference> result = new ArrayList<EntityReference>();
    EntityReference wikiReference = spaceReference.extractReference(EntityType.WIKI);
    String localSpaceReference = this.localEntityReferenceSerializer.serialize(spaceReference);
    // Ignore the space reference because it is not indexable.
    // Make sure the list of spaces is from the requested wiki
    List<String> documentNames;
    try {
        documentNames = this.queryManager.getNamedQuery("getSpaceDocsName").setWiki(wikiReference.getName()).bindValue("space", localSpaceReference).execute();
    } catch (QueryException e) {
        throw new SolrIndexerException("Failed to query space [" + spaceReference + "] documents", e);
    }
    for (String documentName : documentNames) {
        EntityReference documentReference = new EntityReference(documentName, EntityType.DOCUMENT, spaceReference);
        try {
            Iterables.addAll(result, this.documentResolverProvider.get().getReferences(documentReference));
        } catch (Exception e) {
            this.logger.error("Failed to resolve references for document [" + documentReference + "]", e);
        }
    }
    return result;
}
Also used : SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) QueryException(org.xwiki.query.QueryException) EntityReference(org.xwiki.model.reference.EntityReference) ArrayList(java.util.ArrayList) QueryException(org.xwiki.query.QueryException) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException)

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