Skip to content

Commit

Permalink
iter
Browse files Browse the repository at this point in the history
  • Loading branch information
jimczi committed Dec 2, 2024
1 parent f204cc3 commit d710efc
Show file tree
Hide file tree
Showing 6 changed files with 495 additions and 438 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.join.BitSetProducer;
import org.elasticsearch.index.query.SearchExecutionContext;

import java.util.Map;
import java.util.function.Function;

/**
* An abstract {@link MetadataFieldMapper} used as a placeholder for implementation
* in the inference module. It is required by {@link SourceFieldMapper} to identify
* the field name for removal from _source.
*/
public abstract class InferenceMetadataFieldsMapper extends MetadataFieldMapper {
public static final String NAME = "_inference_fields";
public static final String CONTENT_TYPE = "_inference_fields";
Expand All @@ -39,6 +45,9 @@ public InferenceMetadataFieldType() {
super(NAME, false, false, false, TextSearchInfo.NONE, Map.of());
}

/**
* Returns a {@link ValueFetcher} without requiring the construction of a full {@link SearchExecutionContext}.
*/
public abstract ValueFetcher valueFetcher(
MappingLookup mappingLookup,
Function<Query, BitSetProducer> bitSetCache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
import java.util.List;
import java.util.Map;

/**
* A {@link Highlighter} designed for the {@link SemanticTextFieldMapper}.
* It extracts semantic queries and compares them against each chunk in the document.
* The top-scoring chunks are returned as snippets, sorted by their scores.
*/
public class SemanticTextHighlighter implements Highlighter {
public static final String NAME = "semantic";

Expand All @@ -54,6 +59,7 @@ private record OffsetAndScore(OffsetSourceFieldMapper.OffsetSource offset, float
@Override
public boolean canHighlight(MappedFieldType fieldType) {
if (fieldType instanceof SemanticTextFieldMapper.SemanticTextFieldType semanticTextFieldType) {
// TODO: Handle semantic text field prior to the inference metadata fields version.
return semanticTextFieldType.getIndexVersionCreated().onOrAfter(IndexVersions.INFERENCE_METADATA_FIELDS);
}
return false;
Expand Down
Loading

0 comments on commit d710efc

Please sign in to comment.