Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.search.lookup;
import org.apache.lucene.codecs.StoredFieldsReader;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.CheckedBiConsumer;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.lucene.index.SequentialStoredFieldsLeafReader;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.core.MemoizedSupplier;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.Tuple;
import org.elasticsearch.index.fieldvisitor.FieldsVisitor;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.elasticsearch.xcontent.XContentType;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
public class SourceLookup implements Map {
private SourceProvider sourceProvider;
private int docId = -1;
public SourceLookup(SourceProvider sourceProvider) {
this.sourceProvider = sourceProvider;
}
public XContentType sourceContentType() {
return sourceProvider.sourceContentType();
}
public int docId() {
return docId;
}
/**
* Return the source as a map that will be unchanged when the lookup
* moves to a different document.
*
* Important: This can lose precision on numbers with a decimal point. It
* converts numbers like {@code "n": 1234.567} to a {@code double} which
* only has 52 bits of precision in the mantissa. This will come up most
* frequently when folks write nanosecond precision dates as a decimal
* number.
*/
public Map source() {
return sourceProvider.source();
}
public void setSourceProvider(SourceProvider sourceProvider) {
this.sourceProvider = sourceProvider;
}
public void setSegmentAndDocument(LeafReaderContext context, int docId) {
sourceProvider.setSegmentAndDocument(context, docId);
this.docId = docId;
}
/**
* Internal source representation, might be compressed....
*/
public BytesReference internalSourceRef() {
return sourceProvider.sourceAsBytes();
}
/**
* Checks if the source has been deserialized as a {@link Map} of java objects.
*/
public boolean hasSourceAsMap() {
return sourceProvider.hasSourceAsMap();
}
/**
* Returns the values associated with the path. Those are "low" level values, and it can
* handle path expression where an array/list is navigated within.
*
* This method will:
*
* - not cache source if it's not already parsed
* - will only extract the desired values from the compressed source instead of deserializing the whole object
*
* This is useful when the caller only wants a single value from source and does not care of source is fully parsed and cached
* for later use.
* @param path The path from which to extract the values from source
* @return The list of found values or an empty list if none are found
*/
public List