/** Extracts document and cluster lists before serialization. */
  @Persist
  private void beforeSerialization() {
    /*
     * See http://issues.carrot2.org/browse/CARROT-693; this monitor does not save us
     * in multi-threaded environment anyway. A better solution would be to prepare
     * this eagerly in the constructor, but we try to balance overhead and full
     * correctness here.
     */
    synchronized (this) {
      query = (String) attributes.get(AttributeNames.QUERY);

      if (getDocuments() != null) {
        documents = Lists.newArrayList(getDocuments());
      } else {
        documents = null;
      }

      if (getClusters() != null) {
        clusters = Lists.newArrayList(getClusters());
      } else {
        clusters = null;
      }

      otherAttributesForSerialization = MapUtils.asHashMap(SimpleXmlWrappers.wrap(attributes));
      otherAttributesForSerialization.remove(AttributeNames.QUERY);
      otherAttributesForSerialization.remove(AttributeNames.CLUSTERS);
      otherAttributesForSerialization.remove(AttributeNames.DOCUMENTS);
      if (otherAttributesForSerialization.isEmpty()) {
        otherAttributesForSerialization = null;
      }
    }
  }
Exemple #2
0
 @ElementMap(entry = "field", key = "key", attribute = true, inline = true, required = false)
 @SuppressWarnings("unused")
 private void setOtherFieldsXml(
     HashMap<String, SimpleXmlWrapperValue> otherFieldsForSerialization) {
   if (otherFieldsForSerialization != null) {
     // No need to synchronize here, the object is being deserialized,
     // so it can't yet be seen by other threads.
     fields.putAll(SimpleXmlWrappers.unwrap(otherFieldsForSerialization));
   }
 }
Exemple #3
0
  @Commit
  @SuppressWarnings("unused")
  private void afterDeserialization() throws Exception {
    if (otherAttributesForSerialization != null) {
      attributes.putAll(SimpleXmlWrappers.unwrap(otherAttributesForSerialization));
    }

    phrasesView = Collections.unmodifiableList(phrases);
    subclustersView = Collections.unmodifiableList(subclusters);
    // Documents will be restored on the ProcessingResult level
  }
Exemple #4
0
 @ElementMap(entry = "field", key = "key", attribute = true, inline = true, required = false)
 @SuppressWarnings("unused")
 private HashMap<String, SimpleXmlWrapperValue> getOtherFieldsXml() {
   final HashMap<String, SimpleXmlWrapperValue> otherFieldsForSerialization;
   synchronized (this) {
     otherFieldsForSerialization = MapUtils.asHashMap(SimpleXmlWrappers.wrap(fields));
   }
   otherFieldsForSerialization.remove(TITLE);
   otherFieldsForSerialization.remove(SUMMARY);
   otherFieldsForSerialization.remove(CONTENT_URL);
   otherFieldsForSerialization.remove(SOURCES);
   otherFieldsForSerialization.remove(LANGUAGE);
   otherFieldsForSerialization.remove(SCORE);
   fireSerializationListeners(otherFieldsForSerialization);
   return otherFieldsForSerialization.isEmpty() ? null : otherFieldsForSerialization;
 }
Exemple #5
0
  @Persist
  @SuppressWarnings("unused")
  private void beforeSerialization() {
    documentIds =
        Lists.transform(
            documents,
            new Function<Document, DocumentRefid>() {
              public DocumentRefid apply(Document document) {
                return new DocumentRefid(document.getId());
              }
            });

    // Remove score from attributes for serialization
    otherAttributesForSerialization = MapUtils.asHashMap(SimpleXmlWrappers.wrap(attributes));
    otherAttributesForSerialization.remove(SCORE);
    if (otherAttributesForSerialization.isEmpty()) {
      otherAttributesForSerialization = null;
    }
  }
  /** Transfers document and cluster lists to the attributes map after deserialization. */
  @Commit
  private void afterDeserialization() throws Exception {
    if (otherAttributesForSerialization != null) {
      attributes = SimpleXmlWrappers.unwrap(otherAttributesForSerialization);
    }

    attributesView = Collections.unmodifiableMap(attributes);

    attributes.put(AttributeNames.QUERY, query != null ? query.trim() : null);
    attributes.put(AttributeNames.DOCUMENTS, documents);
    attributes.put(AttributeNames.CLUSTERS, clusters);

    // Convert document ids to the actual references
    if (clusters != null && documents != null) {
      final Map<String, Document> documentsById = Maps.newHashMap();
      for (Document document : documents) {
        documentsById.put(document.getStringId(), document);
      }

      for (Cluster cluster : clusters) {
        documentIdToReference(cluster, documentsById);
      }
    }
  }
 /*
  * Register selected SimpleXML wrappers for Lucene data types.
  */
 static {
   SimpleXmlWrappers.addWrapper(FSDirectory.class, FSDirectoryWrapper.class, false);
 }