コード例 #1
0
 @Override
 public void postParse(ParseContext context) throws IOException {
   if (context.id() == null && !context.sourceToParse().flyweight()) {
     throw new MapperParsingException("No id found while parsing the content source");
   }
   // if we did not have the id as part of the sourceToParse, then we need to parse it here
   // it would have been filled in the _id parse phase
   if (context.sourceToParse().id() == null) {
     super.parse(context);
     // since we did not have the uid in the pre phase, we did not add it automatically to the
     // nested docs
     // as they were created we need to make sure we add it to all the nested docs...
     if (context.docs().size() > 1) {
       UidField uidField = (UidField) context.rootDoc().getField(UidFieldMapper.NAME);
       assert uidField != null;
       // we need to go over the docs and add it...
       for (int i = 1; i < context.docs().size(); i++) {
         // we don't need to add it as a full uid field in nested docs, since we don't need
         // versioning
         context
             .docs()
             .get(i)
             .add(new Field(UidFieldMapper.NAME, uidField.uid(), Defaults.NESTED_FIELD_TYPE));
       }
     }
   }
 }
コード例 #2
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
 }
コード例 #3
0
 @Override
 protected Fieldable parseCreateField(ParseContext context) throws IOException {
   if (context.id() == null) {
     throw new MapperParsingException("No id found while parsing the content source");
   }
   context.uid(Uid.createUid(context.stringBuilder(), context.type(), context.id()));
   // 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(context.uid());
   return field; // version get updated by the engine
 }
コード例 #4
0
 private UidField.DocIdAndVersion loadCurrentVersionFromIndex(
     BloomCache bloomCache, Engine.Searcher searcher, Term uid) {
   UnicodeUtil.UTF8Result utf8 = Unicode.fromStringAsUtf8(uid.text());
   for (IndexReader reader : searcher.searcher().subReaders()) {
     BloomFilter filter = bloomCache.filter(reader, UidFieldMapper.NAME, true);
     // we know that its not there...
     if (!filter.isPresent(utf8.result, 0, utf8.length)) {
       continue;
     }
     UidField.DocIdAndVersion docIdAndVersion = UidField.loadDocIdAndVersion(reader, uid);
     // either -2 (its there, but no version associated), or an actual version
     if (docIdAndVersion.docId != -1) {
       return docIdAndVersion;
     }
   }
   return null;
 }