Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -102,11 +104,11 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S
}

@Override
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
public ValueFetcher valueFetcher(Function<String, Set<String>> sourcePaths, String format) {
if (format != null) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats.");
}
return new SourceValueFetcher(name(), context) {
return new SourceValueFetcher(name(), sourcePaths.apply(name()), null) {
@Override
protected Float parseSourceValue(Object value) {
return objectToFloat(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.elasticsearch.index.query.SearchExecutionContext;

import java.util.Collections;
import java.util.Set;
import java.util.function.Function;

/**
* This meta field only exists because rank feature fields index everything into a
Expand Down Expand Up @@ -40,7 +42,7 @@ public String typeName() {
}

@Override
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
public ValueFetcher valueFetcher(Function<String, Set<String>> sourcePaths, String format) {
throw new UnsupportedOperationException("Cannot fetch values for internal field [" + typeName() + "].");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -75,8 +77,8 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S
}

@Override
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
return SourceValueFetcher.identity(name(), context, format);
public ValueFetcher valueFetcher(Function<String, Set<String>> sourcePaths, String format) {
return SourceValueFetcher.identity(name(), sourcePaths, format);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;

/** A {@link FieldMapper} for scaled floats. Values are internally multiplied
Expand Down Expand Up @@ -199,11 +201,11 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S
}

@Override
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
public ValueFetcher valueFetcher(Function<String, Set<String>> sourcePaths, String format) {
if (format != null) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats.");
}
return new SourceValueFetcher(name(), context) {
return new SourceValueFetcher(name(), sourcePaths.apply(name()), null) {
@Override
protected Double parseSourceValue(Object value) {
double doubleValue;
Expand Down Expand Up @@ -517,9 +519,9 @@ public int docValueCount() {
}

@Override
public DocValueFetcher.Leaf getLeafValueFetcher(DocValueFormat format) {
public Leaf getLeafValueFetcher(DocValueFormat format) {
SortedNumericDoubleValues values = getDoubleValues();
return new DocValueFetcher.Leaf() {
return new Leaf() {
@Override
public boolean advanceExact(int docId) throws IOException {
return values.advanceExact(docId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;

import static org.elasticsearch.index.mapper.TextFieldMapper.TextFieldType.hasGaps;

Expand Down Expand Up @@ -253,8 +255,8 @@ private ShingleFieldType shingleFieldForPositions(int positions) {
}

@Override
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
return SourceValueFetcher.toString(name(), context, format);
public ValueFetcher valueFetcher(Function<String, Set<String>> sourcePaths, String format) {
return SourceValueFetcher.toString(name(), sourcePaths, format);
}

@Override
Expand Down Expand Up @@ -366,10 +368,10 @@ public Query prefixQuery(String value, MultiTermQuery.RewriteMethod method, bool
}

@Override
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
public ValueFetcher valueFetcher(Function<String, Set<String>> sourcePaths, String format) {
// Because this internal field is modelled as a multi-field, SourceValueFetcher will look up its
// parent field in _source. So we don't need to use the parent field name here.
return SourceValueFetcher.toString(name(), context, format);
return SourceValueFetcher.toString(name(), sourcePaths, format);
}

@Override
Expand Down Expand Up @@ -473,10 +475,10 @@ void setPrefixFieldType(PrefixFieldType prefixFieldType) {
}

@Override
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
public ValueFetcher valueFetcher(Function<String, Set<String>> sourcePaths, String format) {
// Because this internal field is modelled as a multi-field, SourceValueFetcher will look up its
// parent field in _source. So we don't need to use the parent field name here.
return SourceValueFetcher.toString(name(), context, format);
return SourceValueFetcher.toString(name(), sourcePaths, format);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.query.SearchExecutionContext;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;

import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeIntegerValue;

Expand Down Expand Up @@ -81,11 +82,11 @@ static class TokenCountFieldType extends NumberFieldMapper.NumberFieldType {
}

@Override
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
public ValueFetcher valueFetcher(Function<String, Set<String>> sourcePaths, String format) {
if (hasDocValues() == false) {
return (lookup, ignoredFields) -> List.of();
}
return new DocValueFetcher(docValueFormat(format, null), context.getForField(this));
return new DocValueFetcher(docValueFormat(format, null), name());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.io.IOException;
import java.util.Collections;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -54,7 +56,7 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S
}

@Override
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
public ValueFetcher valueFetcher(Function<String, Set<String>> sourcePaths, String format) {
throw new UnsupportedOperationException("Cannot fetch values for metadata field [" + NAME + "].");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
import org.elasticsearch.index.mapper.StringFieldType;
import org.elasticsearch.index.mapper.TextSearchInfo;
import org.elasticsearch.index.mapper.ValueFetcher;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.lookup.SearchLookup;

import java.util.Collections;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -64,7 +65,7 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S
}

@Override
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
public ValueFetcher valueFetcher(Function<String, Set<String>> sourcePaths, String format) {
throw new UnsupportedOperationException("Cannot fetch values for internal field [" + typeName() + "].");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.elasticsearch.index.mapper.StringFieldType;
import org.elasticsearch.index.mapper.TextSearchInfo;
import org.elasticsearch.index.mapper.ValueFetcher;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.lookup.SearchLookup;

Expand All @@ -41,6 +40,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -151,8 +151,8 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S
}

@Override
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
return SourceValueFetcher.identity(name(), context, format);
public ValueFetcher valueFetcher(Function<String, Set<String>> sourcePaths, String format) {
return SourceValueFetcher.identity(name(), sourcePaths, format);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
import org.elasticsearch.index.query.ConstantScoreQueryBuilder;
import org.elasticsearch.index.query.DisMaxQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.index.query.QueryShardException;
import org.elasticsearch.index.query.Rewriteable;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;

import java.io.ByteArrayOutputStream;
Expand All @@ -75,6 +75,8 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;

import static org.elasticsearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder;
Expand Down Expand Up @@ -207,8 +209,8 @@ public Query termQuery(Object value, SearchExecutionContext context) {
}

@Override
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
return SourceValueFetcher.identity(name(), context, format);
public ValueFetcher valueFetcher(Function<String, Set<String>> sourcePaths, String format) {
return SourceValueFetcher.identity(name(), sourcePaths, format);
}

Query percolateQuery(String name, PercolateQuery.QueryStore queryStore, List<BytesReference> documents,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.elasticsearch.search.fetch.subphase.highlight.HighlightPhase;
import org.elasticsearch.search.fetch.subphase.highlight.Highlighter;
import org.elasticsearch.search.fetch.subphase.highlight.SearchHighlightContext;
import org.elasticsearch.search.lookup.ValuesLookup;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -82,9 +83,9 @@ public void process(HitContext hit) throws IOException {
BytesReference document = percolateQuery.getDocuments().get(slot);
HitContext subContext = new HitContext(
new SearchHit(slot, "unknown", Collections.emptyMap(), Collections.emptyMap()),
ValuesLookup.sourceOnly(document),
percolatorLeafReaderContext,
slot);
subContext.sourceLookup().setSource(document);
// force source because MemoryIndex does not store fields
SearchHighlightContext highlight = new SearchHighlightContext(fetchContext.highlight().fields(), true);
FetchSubPhaseProcessor processor = highlightPhase.getProcessor(fetchContext, highlight, query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void testHitsExecute() throws Exception {
LeafReaderContext context = reader.leaves().get(0);
// A match:
{
HitContext hit = new HitContext(new SearchHit(0), context, 0);
HitContext hit = new HitContext(new SearchHit(0), null, context, 0);
PercolateQuery.QueryStore queryStore = ctx -> docId -> new TermQuery(new Term("field", "value"));
MemoryIndex memoryIndex = new MemoryIndex();
memoryIndex.addField("field", "value", new WhitespaceAnalyzer());
Expand All @@ -73,7 +73,7 @@ public void testHitsExecute() throws Exception {

// No match:
{
HitContext hit = new HitContext(new SearchHit(0), context, 0);
HitContext hit = new HitContext(new SearchHit(0), null, context, 0);
PercolateQuery.QueryStore queryStore = ctx -> docId -> new TermQuery(new Term("field", "value"));
MemoryIndex memoryIndex = new MemoryIndex();
memoryIndex.addField("field", "value1", new WhitespaceAnalyzer());
Expand All @@ -93,7 +93,7 @@ public void testHitsExecute() throws Exception {

// No query:
{
HitContext hit = new HitContext(new SearchHit(0), context, 0);
HitContext hit = new HitContext(new SearchHit(0), null, context, 0);
PercolateQuery.QueryStore queryStore = ctx -> docId -> null;
MemoryIndex memoryIndex = new MemoryIndex();
memoryIndex.addField("field", "value", new WhitespaceAnalyzer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;

public class ICUCollationKeywordFieldMapper extends FieldMapper {
Expand Down Expand Up @@ -70,12 +72,12 @@ public String typeName() {
}

@Override
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
public ValueFetcher valueFetcher(Function<String, Set<String>> sourcePaths, String format) {
if (format != null) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats.");
}

return new SourceValueFetcher(name(), context, nullValue) {
return new SourceValueFetcher(name(), sourcePaths.apply(name()), nullValue) {
@Override
protected String parseSourceValue(Object value) {
String keywordValue = value.toString();
Expand Down Expand Up @@ -154,6 +156,11 @@ public String format(BytesRef value) {
return new String(encoded, 0, encodedLength);
}

@Override
public Object formatObject(Object in) {
return format((BytesRef)in);
}

@Override
public BytesRef parseBytesRef(String value) {
char[] encoded = value.toCharArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;

public class Murmur3FieldMapper extends FieldMapper {
Expand Down Expand Up @@ -93,8 +95,8 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S
}

@Override
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
return SourceValueFetcher.toString(name(), context, format);
public ValueFetcher valueFetcher(Function<String, Set<String>> sourcePaths, String format) {
return SourceValueFetcher.toString(name(), sourcePaths, format);
}

@Override
Expand Down
Loading