@Override
 public void doWriteTo(StreamOutput out) throws IOException {
   suggestMode.writeTo(out);
   out.writeFloat(accuracy);
   sort.writeTo(out);
   stringDistance.writeTo(out);
   out.writeVInt(maxEdits);
   out.writeVInt(maxInspections);
   out.writeFloat(maxTermFreq);
   out.writeVInt(prefixLength);
   out.writeVInt(minWordLength);
   out.writeFloat(minDocFreq);
 }
 @Override
 protected void doWriteTo(StreamOutput out) throws IOException {
   out.writeString(fieldName);
   out.writeGenericValue(value);
   type.writeTo(out);
   operator.writeTo(out);
   out.writeVInt(slop);
   out.writeVInt(prefixLength);
   out.writeVInt(maxExpansions);
   out.writeBoolean(fuzzyTranspositions);
   out.writeBoolean(lenient);
   zeroTermsQuery.writeTo(out);
   // optional fields
   out.writeOptionalString(analyzer);
   out.writeOptionalString(minimumShouldMatch);
   out.writeOptionalString(fuzzyRewrite);
   if (fuzziness == null) {
     out.writeBoolean(false);
   } else {
     out.writeBoolean(true);
     fuzziness.writeTo(out);
   }
   if (cutoffFrequency == null) {
     out.writeBoolean(false);
   } else {
     out.writeBoolean(true);
     out.writeFloat(cutoffFrequency);
   }
 }
 @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
 protected void doWriteTo(StreamOutput out) throws IOException {
   out.writeString(this.fieldName);
   out.writeGenericValue(this.text);
   highFreqOperator.writeTo(out);
   lowFreqOperator.writeTo(out);
   out.writeOptionalString(analyzer);
   out.writeOptionalString(lowFreqMinimumShouldMatch);
   out.writeOptionalString(highFreqMinimumShouldMatch);
   out.writeBoolean(disableCoord);
   out.writeFloat(cutoffFrequency);
 }
Beispiel #5
0
  @Override
  public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeFloat(minScore);
    out.writeOptionalString(routing);
    out.writeOptionalString(preference);
    out.writeBytesReference(source);
    out.writeStringArray(types);

    if (out.getVersion().onOrAfter(Version.V_1_4_0_Beta1)) {
      out.writeVInt(terminateAfter);
    }
  }
Beispiel #6
0
 public static void writeExplanation(StreamOutput out, Explanation explanation)
     throws IOException {
   out.writeFloat(explanation.getValue());
   out.writeString(explanation.getDescription());
   Explanation[] subExplanations = explanation.getDetails();
   if (subExplanations == null) {
     out.writeBoolean(false);
   } else {
     out.writeBoolean(true);
     out.writeVInt(subExplanations.length);
     for (Explanation subExp : subExplanations) {
       writeExplanation(out, subExp);
     }
   }
 }
 @Override
 protected void doWriteTo(StreamOutput out) throws IOException {
   out.writeString(queryText);
   out.writeInt(fieldsAndWeights.size());
   for (Map.Entry<String, Float> entry : fieldsAndWeights.entrySet()) {
     out.writeString(entry.getKey());
     out.writeFloat(entry.getValue());
   }
   out.writeInt(flags);
   out.writeOptionalString(analyzer);
   defaultOperator.writeTo(out);
   out.writeBoolean(settings.lowercaseExpandedTerms());
   out.writeBoolean(settings.lenient());
   out.writeBoolean(settings.analyzeWildcard());
   out.writeString(settings.locale().toLanguageTag());
   out.writeOptionalString(minimumShouldMatch);
 }
  @Override
  public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeFloat(minScore);

    out.writeBytesReference(querySource);

    out.writeVInt(types.length);
    for (String type : types) {
      out.writeString(type);
    }
    if (filteringAliases != null) {
      out.writeVInt(filteringAliases.length);
      for (String alias : filteringAliases) {
        out.writeString(alias);
      }
    } else {
      out.writeVInt(0);
    }
    out.writeVLong(nowInMillis);
  }
 @Override
 protected void doWriteTo(StreamOutput out) throws IOException {
   writeQueries(out, queries);
   out.writeFloat(tieBreaker);
 }
  public void writeTo(StreamOutput out, InternalSearchHits.StreamContext context)
      throws IOException {
    out.writeFloat(score);
    out.writeText(id);
    out.writeText(type);
    out.writeOptionalStreamable(nestedIdentity);
    out.writeLong(version);
    out.writeBytesReference(source);
    if (explanation == null) {
      out.writeBoolean(false);
    } else {
      out.writeBoolean(true);
      writeExplanation(out, explanation);
    }
    if (fields == null) {
      out.writeVInt(0);
    } else {
      out.writeVInt(fields.size());
      for (SearchHitField hitField : fields().values()) {
        hitField.writeTo(out);
      }
    }
    if (highlightFields == null) {
      out.writeVInt(0);
    } else {
      out.writeVInt(highlightFields.size());
      for (HighlightField highlightField : highlightFields.values()) {
        highlightField.writeTo(out);
      }
    }

    if (sortValues.length == 0) {
      out.writeVInt(0);
    } else {
      out.writeVInt(sortValues.length);
      for (Object sortValue : sortValues) {
        if (sortValue == null) {
          out.writeByte((byte) 0);
        } else {
          Class type = sortValue.getClass();
          if (type == String.class) {
            out.writeByte((byte) 1);
            out.writeString((String) sortValue);
          } else if (type == Integer.class) {
            out.writeByte((byte) 2);
            out.writeInt((Integer) sortValue);
          } else if (type == Long.class) {
            out.writeByte((byte) 3);
            out.writeLong((Long) sortValue);
          } else if (type == Float.class) {
            out.writeByte((byte) 4);
            out.writeFloat((Float) sortValue);
          } else if (type == Double.class) {
            out.writeByte((byte) 5);
            out.writeDouble((Double) sortValue);
          } else if (type == Byte.class) {
            out.writeByte((byte) 6);
            out.writeByte((Byte) sortValue);
          } else if (type == Short.class) {
            out.writeByte((byte) 7);
            out.writeShort((Short) sortValue);
          } else if (type == Boolean.class) {
            out.writeByte((byte) 8);
            out.writeBoolean((Boolean) sortValue);
          } else if (sortValue instanceof Text) {
            out.writeByte((byte) 9);
            out.writeText((Text) sortValue);
          } else {
            throw new IOException("Can't handle sort field value of type [" + type + "]");
          }
        }
      }
    }

    if (matchedQueries.length == 0) {
      out.writeVInt(0);
    } else {
      out.writeVInt(matchedQueries.length);
      for (String matchedFilter : matchedQueries) {
        out.writeString(matchedFilter);
      }
    }

    if (context.streamShardTarget() == InternalSearchHits.StreamContext.ShardTargetType.STREAM) {
      if (shard == null) {
        out.writeBoolean(false);
      } else {
        out.writeBoolean(true);
        shard.writeTo(out);
      }
    } else if (context.streamShardTarget()
        == InternalSearchHits.StreamContext.ShardTargetType.LOOKUP) {
      if (shard == null) {
        out.writeVInt(0);
      } else {
        out.writeVInt(context.shardHandleLookup().get(shard));
      }
    }

    if (innerHits == null) {
      out.writeVInt(0);
    } else {
      out.writeVInt(innerHits.size());
      for (Map.Entry<String, InternalSearchHits> entry : innerHits.entrySet()) {
        out.writeString(entry.getKey());
        entry
            .getValue()
            .writeTo(
                out,
                InternalSearchHits.streamContext()
                    .streamShardTarget(InternalSearchHits.StreamContext.ShardTargetType.NO_STREAM));
      }
    }
  }
 @Override
 public void writeTo(StreamOutput out) throws IOException {
   boolean hasAggregations = aggregations != null;
   out.writeBoolean(hasAggregations);
   if (hasAggregations) {
     out.writeVInt(aggregations.size());
     for (BytesReference aggregation : aggregations) {
       out.writeBytesReference(aggregation);
     }
   }
   out.writeOptionalBoolean(explain);
   FetchSourceContext.optionalWriteToStream(fetchSourceContext, out);
   boolean hasFieldDataFields = fieldDataFields != null;
   out.writeBoolean(hasFieldDataFields);
   if (hasFieldDataFields) {
     out.writeVInt(fieldDataFields.size());
     for (String field : fieldDataFields) {
       out.writeString(field);
     }
   }
   boolean hasFieldNames = fieldNames != null;
   out.writeBoolean(hasFieldNames);
   if (hasFieldNames) {
     out.writeVInt(fieldNames.size());
     for (String field : fieldNames) {
       out.writeString(field);
     }
   }
   out.writeVInt(from);
   boolean hasHighlightBuilder = highlightBuilder != null;
   out.writeBoolean(hasHighlightBuilder);
   if (hasHighlightBuilder) {
     out.writeBytesReference(highlightBuilder);
   }
   boolean hasIndexBoost = indexBoost != null;
   out.writeBoolean(hasIndexBoost);
   if (hasIndexBoost) {
     out.writeVInt(indexBoost.size());
     for (ObjectCursor<String> key : indexBoost.keys()) {
       out.writeString(key.value);
       out.writeFloat(indexBoost.get(key.value));
     }
   }
   boolean hasInnerHitsBuilder = innerHitsBuilder != null;
   out.writeBoolean(hasInnerHitsBuilder);
   if (hasInnerHitsBuilder) {
     out.writeBytesReference(innerHitsBuilder);
   }
   boolean hasMinScore = minScore != null;
   out.writeBoolean(hasMinScore);
   if (hasMinScore) {
     out.writeFloat(minScore);
   }
   boolean hasPostQuery = postQueryBuilder != null;
   out.writeBoolean(hasPostQuery);
   if (hasPostQuery) {
     out.writeQuery(postQueryBuilder);
   }
   boolean hasQuery = queryBuilder != null;
   out.writeBoolean(hasQuery);
   if (hasQuery) {
     out.writeQuery(queryBuilder);
   }
   boolean hasRescoreBuilders = rescoreBuilders != null;
   out.writeBoolean(hasRescoreBuilders);
   if (hasRescoreBuilders) {
     out.writeVInt(rescoreBuilders.size());
     for (BytesReference rescoreBuilder : rescoreBuilders) {
       out.writeBytesReference(rescoreBuilder);
     }
   }
   boolean hasScriptFields = scriptFields != null;
   out.writeBoolean(hasScriptFields);
   if (hasScriptFields) {
     out.writeVInt(scriptFields.size());
     for (ScriptField scriptField : scriptFields) {
       scriptField.writeTo(out);
     }
   }
   out.writeVInt(size);
   boolean hasSorts = sorts != null;
   out.writeBoolean(hasSorts);
   if (hasSorts) {
     out.writeVInt(sorts.size());
     for (BytesReference sort : sorts) {
       out.writeBytesReference(sort);
     }
   }
   boolean hasStats = stats != null;
   out.writeBoolean(hasStats);
   if (hasStats) {
     out.writeVInt(stats.size());
     for (String stat : stats) {
       out.writeString(stat);
     }
   }
   boolean hasSuggestBuilder = suggestBuilder != null;
   out.writeBoolean(hasSuggestBuilder);
   if (hasSuggestBuilder) {
     out.writeBytesReference(suggestBuilder);
   }
   out.writeVInt(terminateAfter);
   out.writeLong(timeoutInMillis);
   out.writeBoolean(trackScores);
   out.writeOptionalBoolean(version);
   boolean hasExt = ext != null;
   out.writeBoolean(hasExt);
   if (hasExt) {
     out.writeBytesReference(ext);
   }
 }
Beispiel #12
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);
      }
    }
  }
Beispiel #13
0
 @Override
 public void writeTo(StreamOutput out) throws IOException {
   out.writeText(text);
   out.writeVInt(freq);
   out.writeFloat(score);
 }