Example #1
0
  public XContentBuilder toXContentEmbedded(XContentBuilder builder, Params params)
      throws IOException {
    List<GetField> metaFields = new ArrayList<>();
    List<GetField> otherFields = new ArrayList<>();
    if (fields != null && !fields.isEmpty()) {
      for (GetField field : fields.values()) {
        if (field.getValues().isEmpty()) {
          continue;
        }
        if (field.isMetadataField()) {
          metaFields.add(field);
        } else {
          otherFields.add(field);
        }
      }
    }

    for (GetField field : metaFields) {
      builder.field(field.getName(), field.getValue());
    }

    builder.field(Fields.FOUND, exists);

    if (source != null) {
      XContentHelper.writeRawField("_source", source, builder, params);
    }

    if (!otherFields.isEmpty()) {
      builder.startObject(Fields.FIELDS);
      for (GetField field : otherFields) {
        builder.startArray(field.getName());
        for (Object value : field.getValues()) {
          builder.value(value);
        }
        builder.endArray();
      }
      builder.endObject();
    }
    return builder;
  }
 private Fields generateTermVectors(
     Collection<GetField> getFields,
     boolean withOffsets,
     @Nullable Map<String, String> perFieldAnalyzer)
     throws IOException {
   /* store document in memory index */
   MemoryIndex index = new MemoryIndex(withOffsets);
   for (GetField getField : getFields) {
     String field = getField.getName();
     Analyzer analyzer = getAnalyzerAtField(field, perFieldAnalyzer);
     for (Object text : getField.getValues()) {
       index.addField(field, text.toString(), analyzer);
     }
   }
   /* and read vectors from it */
   return MultiFields.getFields(index.createSearcher().getIndexReader());
 }
Example #3
0
 @Override
 public void readFrom(StreamInput in) throws IOException {
   index = in.readString();
   type = in.readOptionalString();
   id = in.readString();
   version = in.readLong();
   exists = in.readBoolean();
   if (exists) {
     source = in.readBytesReference();
     if (source.length() == 0) {
       source = null;
     }
     int size = in.readVInt();
     if (size == 0) {
       fields = emptyMap();
     } else {
       fields = new HashMap<>(size);
       for (int i = 0; i < size; i++) {
         GetField field = readGetField(in);
         fields.put(field.getName(), field);
       }
     }
   }
 }