コード例 #1
0
 private Map<String, Object> loadSourceIfNeeded() {
   if (source != null) {
     return source;
   }
   if (sourceAsBytes != null) {
     Tuple<XContentType, Map<String, Object>> tuple = sourceAsMapAndType(sourceAsBytes);
     sourceContentType = tuple.v1();
     source = tuple.v2();
     return source;
   }
   try {
     JustSourceFieldsVisitor sourceFieldVisitor = new JustSourceFieldsVisitor();
     reader.document(docId, sourceFieldVisitor);
     BytesReference source = sourceFieldVisitor.source();
     if (source == null) {
       this.source = ImmutableMap.of();
       this.sourceContentType = null;
     } else {
       Tuple<XContentType, Map<String, Object>> tuple = sourceAsMapAndType(source);
       this.sourceContentType = tuple.v1();
       this.source = tuple.v2();
     }
   } catch (Exception e) {
     throw new ElasticsearchParseException("failed to parse / load source", e);
   }
   return this.source;
 }
コード例 #2
0
 @Override
 protected boolean matchDoc(int doc) {
   if (fieldsVisitorEnabled) {
     fieldsVisitor.reset();
     try {
       reader.document(doc, fieldsVisitor);
     } catch (IOException e) {
       throw Throwables.propagate(e);
     }
   }
   for (LuceneCollectorExpression expression : expressions) {
     expression.setNextDocId(doc);
   }
   Boolean value = condition.value();
   if (value == null) {
     return false;
   }
   return value;
 }
コード例 #3
0
  private List<Document> lookupDocs(Term term, final LoadFieldCallback lfc) throws IOException {
    final List<Document> documents = new ArrayList<Document>();
    final TermFilter tf = new TermFilter(term);
    try {
      for (AtomicReaderContext arc : searcher.getIndexReader().leaves()) {
        AtomicReader ar = arc.reader();
        Bits liveDocs = ar.getLiveDocs();
        DocIdSet docSet = tf.getDocIdSet(arc, liveDocs);
        if (docSet != null) {
          DocIdSetIterator disi = docSet.iterator();
          if (disi != null) {
            int docId;
            while ((docId = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
              DocumentStoredFieldVisitor fv =
                  new DocumentStoredFieldVisitor() {
                    @Override
                    public StoredFieldVisitor.Status needsField(FieldInfo fieldInfo)
                        throws IOException {
                      if (lfc == null || lfc.loadField(fieldInfo.name)) {
                        return StoredFieldVisitor.Status.YES;
                      }
                      return StoredFieldVisitor.Status.NO;
                    }
                  };
              ar.document(docId, fv);
              documents.add(fv.getDocument());
            }
          }
        }
      }
    } catch (IOException io) {
      throw new IndexException(io);
    }

    return documents;
  }