@Override
 public void writeTo(StreamOutput out) throws IOException {
   boolean regexBased = isRegexBased();
   out.writeBoolean(regexBased);
   if (regexBased) {
     out.writeOptionalString(include == null ? null : include.getOriginalString());
     out.writeOptionalString(exclude == null ? null : exclude.getOriginalString());
   } else {
     boolean hasIncludes = includeValues != null;
     out.writeBoolean(hasIncludes);
     if (hasIncludes) {
       out.writeVInt(includeValues.size());
       for (BytesRef value : includeValues) {
         out.writeBytesRef(value);
       }
     }
     boolean hasExcludes = excludeValues != null;
     out.writeBoolean(hasExcludes);
     if (hasExcludes) {
       out.writeVInt(excludeValues.size());
       for (BytesRef value : excludeValues) {
         out.writeBytesRef(value);
       }
     }
     if (out.getVersion().onOrAfter(Version.V_5_2_0_UNRELEASED)) {
       out.writeVInt(incNumPartitions);
       out.writeVInt(incZeroBasedPartition);
     }
   }
 }
 @Override
 public void writeTo(StreamOutput out) throws IOException {
   super.writeTo(out);
   out.writeByte(percolatorTypeId);
   out.writeVLong(requestedSize);
   out.writeVLong(count);
   out.writeVInt(matches.length);
   for (BytesRef match : matches) {
     out.writeBytesRef(match);
   }
   out.writeVLong(scores.length);
   for (float score : scores) {
     out.writeFloat(score);
   }
   out.writeVInt(hls.size());
   for (Map<String, HighlightField> hl : hls) {
     out.writeVInt(hl.size());
     for (Map.Entry<String, HighlightField> entry : hl.entrySet()) {
       out.writeString(entry.getKey());
       entry.getValue().writeTo(out);
     }
   }
   out.writeOptionalStreamable(aggregations);
   if (pipelineAggregators == null) {
     out.writeBoolean(false);
   } else {
     out.writeBoolean(true);
     out.writeVInt(pipelineAggregators.size());
     for (PipelineAggregator pipelineAggregator : pipelineAggregators) {
       out.writeBytesReference(pipelineAggregator.type().stream());
       pipelineAggregator.writeTo(out);
     }
   }
 }
 @Override
 public void writeTo(StreamOutput out) throws IOException {
   out.writeString(name);
   out.writeVLong(length);
   out.writeString(checksum);
   out.writeString(writtenBy.toString());
   out.writeBytesRef(hash);
 }
Example #4
0
 @Override
 public void writeTo(StreamOutput out) throws IOException {
   out.writeBytesRef(termBytes);
   out.writeVLong(getDocCount());
   if (showDocCountError) {
     out.writeLong(docCountError);
   }
   aggregations.writeTo(out);
 }
  @Override
  public void writeTo(StreamOutput out) throws IOException {
    // Encode flag
    out.writeBoolean(this.isPruned());

    // Encode size of list
    out.writeInt(set.size());

    // Encode BytesRefs
    BytesRef reusable = new BytesRef();
    for (int i = 0; i < this.set.size(); i++) {
      this.set.get(i, reusable);
      out.writeBytesRef(reusable);
    }
  }
  /**
   * Serialize
   *
   * @param out the output
   * @throws IOException
   */
  @Override
  public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);

    // Encode flag
    out.writeBoolean(isPruned);
    // Encode size
    out.writeVInt(size);
    // Encode type of encoding
    out.writeVInt(termsEncoding.ordinal());
    // Encode terms
    out.writeBytesRef(encodedTerms);
    // Release terms
    encodedTerms = null;
  }
Example #7
0
  public static void writeTopDocs(StreamOutput out, TopDocs topDocs, int from) throws IOException {
    if (topDocs.scoreDocs.length - from < 0) {
      out.writeBoolean(false);
      return;
    }
    out.writeBoolean(true);
    if (topDocs instanceof TopFieldDocs) {
      out.writeBoolean(true);
      TopFieldDocs topFieldDocs = (TopFieldDocs) topDocs;

      out.writeVInt(topDocs.totalHits);
      out.writeFloat(topDocs.getMaxScore());

      out.writeVInt(topFieldDocs.fields.length);
      for (SortField sortField : topFieldDocs.fields) {
        if (sortField.getField() == null) {
          out.writeBoolean(false);
        } else {
          out.writeBoolean(true);
          out.writeString(sortField.getField());
        }
        if (sortField.getComparatorSource() != null) {
          writeSortType(
              out,
              ((IndexFieldData.XFieldComparatorSource) sortField.getComparatorSource())
                  .reducedType());
        } else {
          writeSortType(out, sortField.getType());
        }
        out.writeBoolean(sortField.getReverse());
      }

      out.writeVInt(topDocs.scoreDocs.length - from);
      int index = 0;
      for (ScoreDoc doc : topFieldDocs.scoreDocs) {
        if (index++ < from) {
          continue;
        }
        FieldDoc fieldDoc = (FieldDoc) doc;
        out.writeVInt(fieldDoc.fields.length);
        for (Object field : fieldDoc.fields) {
          if (field == null) {
            out.writeByte((byte) 0);
          } else {
            Class type = field.getClass();
            if (type == String.class) {
              out.writeByte((byte) 1);
              out.writeString((String) field);
            } else if (type == Integer.class) {
              out.writeByte((byte) 2);
              out.writeInt((Integer) field);
            } else if (type == Long.class) {
              out.writeByte((byte) 3);
              out.writeLong((Long) field);
            } else if (type == Float.class) {
              out.writeByte((byte) 4);
              out.writeFloat((Float) field);
            } else if (type == Double.class) {
              out.writeByte((byte) 5);
              out.writeDouble((Double) field);
            } else if (type == Byte.class) {
              out.writeByte((byte) 6);
              out.writeByte((Byte) field);
            } else if (type == Short.class) {
              out.writeByte((byte) 7);
              out.writeShort((Short) field);
            } else if (type == Boolean.class) {
              out.writeByte((byte) 8);
              out.writeBoolean((Boolean) field);
            } else if (type == BytesRef.class) {
              out.writeByte((byte) 9);
              out.writeBytesRef((BytesRef) field);
            } else {
              throw new IOException("Can't handle sort field value of type [" + type + "]");
            }
          }
        }

        out.writeVInt(doc.doc);
        out.writeFloat(doc.score);
      }
    } else {
      out.writeBoolean(false);
      out.writeVInt(topDocs.totalHits);
      out.writeFloat(topDocs.getMaxScore());

      out.writeVInt(topDocs.scoreDocs.length - from);
      int index = 0;
      for (ScoreDoc doc : topDocs.scoreDocs) {
        if (index++ < from) {
          continue;
        }
        out.writeVInt(doc.doc);
        out.writeFloat(doc.score);
      }
    }
  }