예제 #1
0
  private void addField(String name, Object value) {
    if (value == null) {
      return;
    }

    if (value instanceof LocalDate) { // TODO: is this correct? Shouldnt we use LocalTime here?
      DateTime time = ((LocalDate) value).toDateTimeAtStartOfDay();
      addDateTimeInUTC(name, time);
    } else if (value instanceof Interval) {
      Interval interval = (Interval) value;
      DateTime start = interval.getStart();
      DateTime end = interval.getEnd();
      addDateTimeInUTC(name + "_start", start);
      addDateTimeInUTC(name + "_end", end);
    } else if (value instanceof ValueObject) {
      ValueObject object = (ValueObject) value;
      inputDocument.addField(name, object.getIndexingValue());
    } else if (value instanceof AbstractEntity) {
      AbstractEntity object = (AbstractEntity) value;
      inputDocument.addField(name, object.getId());
    } else if (value instanceof Collection) {
      Collection list = (Collection) value;
      if (!list.isEmpty()) {
        for (Object object : list) {
          addField(name, object);
        }
      }
    } else {
      inputDocument.addField(name, value.toString());
    }
  }
예제 #2
0
 /**
  * This method will always add these fields to the solr index:
  *
  * <ul>
  *   <li>id
  *   <li>tags
  *   <li>type
  * </ul>
  *
  * It will also try to add the keywords list and name properties if they exist.
  *
  * @param resource
  * @param additionalFields
  * @throws Exception
  */
 public void add(final AbstractEntity resource, final Map<String, Object> additionalFields) {
   addField("id", resource.getId());
   addField("tags", resource.getTags());
   addTypeField(resource);
   maybeAddNamedProperty("keywords", resource);
   maybeAddNamedProperty("name", resource);
   if (additionalFields != null) {
     for (Map.Entry<String, Object> entry : additionalFields.entrySet()) {
       addField(entry.getKey(), entry.getValue());
     }
   }
 }