/** 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 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 #3
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;
    }
  }
 @Persist
 private void beforeSerialization() {
   forSerialization = MapUtils.asHashMap(SimpleXmlWrappers.wrap(map));
 }