@Override protected Field[] getFields(IndexReader reader, int docId, String fieldName) throws IOException { // we know its low level reader, and matching docId, since that's how we call the highlighter with SourceLookup sourceLookup = searchContext.lookup().source(); sourceLookup.setSegmentAndDocument((LeafReaderContext) reader.getContext(), docId); List<Object> values = sourceLookup.extractRawValues(fieldType.name()); Field[] fields = new Field[values.size()]; for (int i = 0; i < values.size(); i++) { fields[i] = new Field(fieldType.name(), values.get(i).toString(), TextField.TYPE_NOT_STORED); } return fields; }
public FilterScript(Map<String, Object> params, SearchLookup lookup, LeafReaderContext leafContext) { this.params = params; this.leafLookup = lookup.getLeafSearchLookup(leafContext); }
public SearchLookup lookup() { if (lookup == null) { lookup = new SearchLookup(getMapperService(), mappedFieldType -> indexFieldDataService.apply(mappedFieldType, fullyQualifiedIndex.getName()), types); } return lookup; }
searchLookup = new SearchLookup(mapperService, null, new String[]{type}); LeafSearchLookup leafSearchLookup = searchLookup.getLeafSearchLookup(docIdAndVersion.context); searchLookup.source().setSource(source); leafSearchLookup.setDocument(docIdAndVersion.docId); List<Object> values = searchLookup.source().extractRawValues(field); if (!values.isEmpty()) { for (int i = 0; i < values.size(); i++) {
searchLookup = new SearchLookup(mapperService, null, new String[]{type}); searchLookup.source().setSource(source.source); List<Object> values = searchLookup.source().extractRawValues(field); if (!values.isEmpty()) { for (int i = 0; i < values.size(); i++) {
public static String findTermInDoc(int termHash, int docId, String indexFieldName, Analyzer fieldIndexAnalyzer, SearchContext context) { int readerIndex = context.searcher().readerIndex(docId); IndexReader subReader = context.searcher().subReaders()[readerIndex]; int subDoc = docId - context.searcher().docStarts()[readerIndex]; context.lookup().setNextReader(subReader); context.lookup().setNextDocId(subDoc); String candidate; Object value = context.lookup().source().extractValue(indexFieldName); if (value instanceof ArrayList<?>) { for (Object v : (ArrayList<?>) value) { if (v == null) continue; candidate = analyzeStringForTerm(v.toString(), termHash, indexFieldName, fieldIndexAnalyzer); if (candidate != null) { return candidate; } } } else if (value != null) { candidate = analyzeStringForTerm(value.toString(), termHash, indexFieldName, fieldIndexAnalyzer); if (candidate != null) { return candidate; } } throw new ElasticSearchIllegalStateException( "Failed to find hash code " + termHash + " in an array of docId " + docId + ". You can only use stored fields or when you store the original document under _source"); }
@Override public void setNextDocId(int doc) { lookup.setNextDocId(doc); }
@Override public void setNextReader(AtomicReaderContext context) { lookup.setNextReader(context); }
@Override protected Field[] getFields(IndexReader reader, int docId, String fieldName) throws IOException { // we know its low level reader, and matching docId, since that's how we call the highlighter with SourceLookup sourceLookup = searchContext.lookup().source(); sourceLookup.setSegmentAndDocument((LeafReaderContext) reader.getContext(), docId); List<Object> values = sourceLookup.extractRawValues(fieldType.name()); if (values.isEmpty()) { return EMPTY_FIELDS; } Field[] fields = new Field[values.size()]; for (int i = 0; i < values.size(); i++) { fields[i] = new Field(fieldType.name(), values.get(i).toString(), TextField.TYPE_NOT_STORED); } return fields; }
public SearchScript(Map<String, Object> params, SearchLookup lookup, LeafReaderContext leafContext) { this.params = params; // TODO: remove leniency when painless does not implement SearchScript for executable script cases this.leafLookup = leafContext == null ? null : lookup.getLeafSearchLookup(leafContext); }
public SearchLookup lookup() { if (lookup == null) { lookup = new SearchLookup(getMapperService(), indexFieldDataService, types); } return lookup; }
SourceLookup sourceLookup = context.lookup().source(); sourceLookup.setSegmentAndDocument(ctx, doc); BytesRefHash inDocTerms = new BytesRefHash(256, context.bigArrays());
public TermsSetQueryScript(Map<String, Object> params, SearchLookup lookup, LeafReaderContext leafContext) { this.params = new ParameterMap(params, DEPRECATIONS); this.leafLookup = lookup.getLeafSearchLookup(leafContext); }
public SearchLookup lookup() { if (lookup == null) { lookup = new SearchLookup(getMapperService(), mappedFieldType -> indexFieldDataService.apply(mappedFieldType, fullyQualifiedIndex.getName()), types); } return lookup; }
/** * Load field values for highlighting. */ public static List<Object> loadFieldValues(SearchContextHighlight.Field field, MappedFieldType fieldType, SearchContext searchContext, FetchSubPhase.HitContext hitContext) throws IOException { //percolator needs to always load from source, thus it sets the global force source to true boolean forceSource = searchContext.highlight().forceSource(field); List<Object> textsToHighlight; if (!forceSource && fieldType.stored()) { CustomFieldsVisitor fieldVisitor = new CustomFieldsVisitor(singleton(fieldType.name()), false); hitContext.reader().document(hitContext.docId(), fieldVisitor); textsToHighlight = fieldVisitor.fields().get(fieldType.name()); if (textsToHighlight == null) { // Can happen if the document doesn't have the field to highlight textsToHighlight = Collections.emptyList(); } } else { SourceLookup sourceLookup = searchContext.lookup().source(); sourceLookup.setSegmentAndDocument(hitContext.readerContext(), hitContext.docId()); textsToHighlight = sourceLookup.extractRawValues(fieldType.name()); } assert textsToHighlight != null; return textsToHighlight; }
public MapScript(Map<String, Object> params, Object state, SearchLookup lookup, LeafReaderContext leafContext) { this.state = state; this.leafLookup = leafContext == null ? null : lookup.getLeafSearchLookup(leafContext); if (leafLookup != null) { params = new HashMap<>(params); // copy params so we aren't modifying input params.putAll(leafLookup.asMap()); // add lookup vars params = new ParameterMap(params, DEPRECATIONS); // wrap with deprecations } this.params = params; }
public SearchLookup lookup() { if (lookup == null) { lookup = new SearchLookup(getMapperService(), mappedFieldType -> indexFieldDataService.apply(mappedFieldType, fullyQualifiedIndex.getName()), types); } return lookup; }
public ScoreScript(Map<String, Object> params, SearchLookup lookup, LeafReaderContext leafContext) { // null check needed b/c of expression engine subclass if (lookup == null) { assert params == null; assert leafContext == null; this.params = null; this.leafLookup = null; } else { this.leafLookup = lookup.getLeafSearchLookup(leafContext); params = new HashMap<>(params); params.putAll(leafLookup.asMap()); this.params = new ParameterMap(params, DEPRECATIONS); } }
@Override public SearchLookup lookup() { if (searchLookup == null) { searchLookup = new SearchLookup(mapperService(), fieldData(), types); } return searchLookup; }