Exemplo n.º 1
0
 @Override
 protected Field parseCreateField(ParseContext context) throws IOException {
   if (context.parser().currentName() != null
       && context.parser().currentName().equals(Defaults.NAME)) {
     // we are in the parsing of _parent phase
     String parentId = context.parser().text();
     context.sourceToParse().parent(parentId);
     return new Field(
         names.indexName(), Uid.createUid(context.stringBuilder(), type, parentId), fieldType);
   }
   // otherwise, we are running it post processing of the xcontent
   String parsedParentId = context.doc().get(Defaults.NAME);
   if (context.sourceToParse().parent() != null) {
     String parentId = context.sourceToParse().parent();
     if (parsedParentId == null) {
       if (parentId == null) {
         throw new MapperParsingException(
             "No parent id provided, not within the document, and not externally");
       }
       // we did not add it in the parsing phase, add it now
       return new Field(
           names.indexName(), Uid.createUid(context.stringBuilder(), type, parentId), fieldType);
     } else if (parentId != null
         && !parsedParentId.equals(Uid.createUid(context.stringBuilder(), type, parentId))) {
       throw new MapperParsingException(
           "Parent id mismatch, document value is ["
               + Uid.createUid(parsedParentId).id()
               + "], while external value is ["
               + parentId
               + "]");
     }
   }
   // we have parent mapping, yet no value was set, ignore it...
   return null;
 }
Exemplo n.º 2
0
 @Override
 public Uid value(Object value) {
   if (value == null) {
     return null;
   }
   return Uid.createUid(value.toString());
 }
 @Override
 public void stringField(FieldInfo fieldInfo, String value) throws IOException {
   if (UidFieldMapper.NAME.equals(fieldInfo.name)) {
     uid = Uid.createUid(value);
   } else {
     addValue(fieldInfo.name, value);
   }
 }
Exemplo n.º 4
0
 @Override
 protected Field parseCreateField(ParseContext context) throws IOException {
   // so, caching uid stream and field is fine
   // since we don't do any mapping parsing without immediate indexing
   // and, when percolating, we don't index the uid
   UidField field = fieldCache.get();
   field.setUid(Uid.createUid(context.stringBuilder(), context.type(), context.id()));
   context.uid(field);
   return field; // version get updated by the engine
 }
 @Override
 public void collect(int doc) throws IOException {
   // the _source is the query
   Document document = reader.document(doc, new UidAndSourceFieldSelector());
   String id = Uid.createUid(document.get(UidFieldMapper.NAME)).id();
   byte[] source = document.getBinaryValue(SourceFieldMapper.NAME);
   try {
     queries.put(id, percolator.parseQuery(id, source, 0, source.length));
   } catch (Exception e) {
     logger.warn("failed to add query [{}]", e, id);
   }
 }
Exemplo n.º 6
0
 public Term term(String type, String id) {
   return term(Uid.createUid(type, id));
 }
Exemplo n.º 7
0
 @Override
 public Uid valueFromString(String value) {
   return Uid.createUid(value);
 }
Exemplo n.º 8
0
 @Override
 public Uid value(Object value) {
   return Uid.createUid(String.valueOf(value));
 }