@Override
 public boolean addDynamicField(final String name, final String value, final StringMode mode) {
   if (value == null) {
     return false;
   } else {
     switch (mode) {
       case STRING:
         {
           super.addField(name + stringSuffix, value);
           return true;
         }
       case TEXT:
         {
           super.addField(name + textSuffix, value);
           return true;
         }
       case SPLIT:
         {
           super.addField(name + collectionSuffix, value);
           return true;
         }
       default:
         {
           return false;
         }
     }
   }
 }
 @Override
 public void addBooleanField(final String name, final Boolean b) {
   if (b == null) {
     super.addField(name, Boolean.FALSE.toString());
   } else {
     super.addField(name, b.toString());
   }
 }
 @Override
 public boolean addDynamicField(final String name, final Float f) {
   if (f == null) {
     return false;
   } else {
     super.addField(name + floatSuffix, f.toString());
     return true;
   }
 }
 @Override
 public boolean addDynamicField(final String name, final Integer i) {
   if (i == null) {
     return false;
   } else {
     super.addField(name + intSuffix, i.toString());
     return true;
   }
 }
 @Override
 public boolean addDynamicField(final String name, final String value) {
   if (value == null) {
     return false;
   } else {
     super.addField(name + stringSuffix, value);
     return true;
   }
 }
 @Override
 public boolean addDynamicField(final String name, final Collection<?> c) {
   if (c == null) {
     return false;
   } else {
     super.addField(name + collectionSuffix, JOINER.join(c));
     return true;
   }
 }
 @Override
 public boolean addDynamicField(final String name, final Double d) {
   if (d == null) {
     return false;
   } else {
     super.addField(name + doubleSuffix, d.toString());
     return true;
   }
 }
 @Override
 public boolean addDynamicField(final String name, final Long l) {
   if (l == null) {
     return false;
   } else {
     super.addField(name + longSuffix, l.toString());
     return true;
   }
 }
 @Override
 public boolean addDateField(final String name, final Date dt) {
   if (dt == null) {
     return false;
   } else {
     synchronized (SOLR_DATETIMEFORMAT) {
       final String dateFormatted = SOLR_DATETIMEFORMAT.format(dt);
       super.addField(name, dateFormatted);
     }
     return true;
   }
 }
  @Override
  public <K> boolean addDynamicField(
      final String name,
      final Collection<? extends K> c,
      final Function<? super K, String> function) {

    if (c == null || c.size() == 0 || function == null) {
      return false;
    } else {
      super.addField(name + collectionSuffix, JOINER.join(Iterables.transform(c, function)));
      return true;
    }
  }
 @Override
 public boolean addMultiField(final String name, final Collection<?> values) {
   if (values == null) {
     return false;
   } else {
     boolean wasAdded = false;
     for (Object value : values) {
       if (value == null) continue;
       super.addField(name, value.toString());
       wasAdded = true;
     }
     return wasAdded;
   }
 }
Ejemplo n.º 12
0
  private static SolrDocument toSolrDoc(SolrInputDocument sdoc, IndexSchema schema) {
    // TODO: do something more performant than this double conversion
    Document doc = DocumentBuilder.toDocument(sdoc, schema);

    // copy the stored fields only
    StoredDocument out = new StoredDocument();
    for (IndexableField f : doc.getFields()) {
      if (f.fieldType().stored()) {
        out.add((StorableField) f);
      }
    }

    return toSolrDoc(out, schema);
  }
 @Override
 public void addNumericField(final String name, final int i) {
   super.addField(name, Integer.toString(i));
 }
 @Override
 public void addNumericField(final String name, final double d) {
   super.addField(name, Double.toString(d));
 }
 @Override
 public void addNumericField(final String name, final long l) {
   super.addField(name, Long.toString(l));
 }
 @Override
 public boolean addDynamicField(final String name, final int i) {
   super.addField(name + intSuffix, Integer.toString(i));
   return true;
 }
 @Override
 public boolean addDynamicField(final String name, final long l) {
   super.addField(name + longSuffix, Long.toString(l));
   return true;
 }
 @Override
 public boolean addDynamicField(final String name, final float f) {
   super.addField(name + floatSuffix, Float.toString(f));
   return true;
 }
 @Override
 public void addBooleanField(final String name, final boolean b) {
   super.addField(name, Boolean.toString(b));
 }
 @Override
 public boolean addDynamicField(final String name, final double d) {
   super.addField(name + doubleSuffix, Double.toString(d));
   return true;
 }