示例#1
0
  protected Document buildDocument(K id, Map<String, Object> fields) {
    String stringId = convert(id, String.class);
    Builder documentBuilder = Document.newBuilder();
    documentBuilder.setId(stringId);
    for (Map.Entry<String, Object> fieldData : fields.entrySet()) {
      Object value = fieldData.getValue();
      String fieldName = fieldData.getKey();
      for (Object object : getCollectionValues(value)) {
        try {
          Field field = buildField(metadata, fieldName, object);
          documentBuilder.addField(field);
        } catch (Exception e) {
          throw new SearchException(
              e,
              "Failed to add field '%s' with value '%s' to document with id '%s': %s",
              fieldName,
              value.toString(),
              id,
              e.getMessage());
        }
      }
    }

    return documentBuilder.build();
  }
示例#2
0
 @Override
 public Document toDocument() {
   Document document =
       Document.newBuilder()
           .setId(id)
           .addField(Field.newBuilder().setName(ComentarioFields.id.name()).setText(id))
           .addField(
               Field.newBuilder().setName(ComentarioFields.conteudo.name()).setText(conteudo))
           .addField(Field.newBuilder().setName(ComentarioFields.usuario.name()).setText(usuario))
           .build();
   return document;
 }
 // Index the geo location
 private void indexProduct(DProduct dProduct) {
   if (null != dProduct.getLocation()) {
     GeoPoint geoPoint =
         new GeoPoint(dProduct.getLocation().getLatitude(), dProduct.getLocation().getLongitude());
     int averageRating =
         (null != dProduct.getRatingAverage()) ? dProduct.getRatingAverage().getRating() : -1;
     Document.Builder locationBuilder =
         Document.newBuilder()
             .setId(dProduct.getProductId())
             .addField(Field.newBuilder().setName("location").setGeoPoint(geoPoint))
             .addField(Field.newBuilder().setName("averageRating").setNumber(averageRating))
             .addField(Field.newBuilder().setName("likeCount").setNumber(dProduct.getLikeCount()))
             .addField(Field.newBuilder().setName("thumbsUp").setNumber(dProduct.getThumbsUp()));
     getLocationIndex().add(locationBuilder.build());
   }
 }