コード例 #1
0
  @Override
  public SolrInputDocument getSolrDocument(EntityReference entityReference)
      throws SolrIndexException, IllegalArgumentException {
    BaseObjectReference objectReference = new BaseObjectReference(entityReference);

    try {
      SolrInputDocument solrDocument = new SolrInputDocument();

      DocumentReference classReference = objectReference.getXClassReference();
      DocumentReference documentReference = new DocumentReference(objectReference.getParent());
      XWikiDocument document = getDocument(documentReference);

      BaseObject object = document.getXObject(objectReference);

      solrDocument.addField(Fields.ID, getId(object.getReference()));
      addDocumentFields(documentReference, solrDocument);
      solrDocument.addField(Fields.TYPE, objectReference.getType().name());
      solrDocument.addField(Fields.CLASS, localSerializer.serialize(classReference));

      addLanguageAndContentFields(documentReference, solrDocument, object);

      return solrDocument;
    } catch (Exception e) {
      throw new SolrIndexException(
          String.format(
              "Failed to get Solr document for '%s'", serializer.serialize(objectReference)),
          e);
    }
  }
コード例 #2
0
  @Override
  public boolean setFieldsInternal(
      LengthSolrInputDocument solrDocument, EntityReference entityReference) throws Exception {
    BaseObjectReference objectReference = new BaseObjectReference(entityReference);

    DocumentReference classReference = objectReference.getXClassReference();
    DocumentReference documentReference = new DocumentReference(objectReference.getParent());

    XWikiDocument document = getDocument(documentReference);
    BaseObject object = document.getXObject(objectReference);
    if (object == null) {
      return false;
    }

    solrDocument.setField(FieldUtils.ID, resolver.getId(object.getReference()));
    setDocumentFields(documentReference, solrDocument);
    solrDocument.setField(FieldUtils.TYPE, objectReference.getType().name());
    solrDocument.setField(FieldUtils.CLASS, localSerializer.serialize(classReference));
    solrDocument.setField(FieldUtils.NUMBER, objectReference.getObjectNumber());

    setLocaleAndContentFields(documentReference, solrDocument, object);

    return true;
  }