All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.elasticsearch.search.profile.query.InternalProfileCollector Maven / Gradle / Ivy

There is a newer version: 8.16.0
Show newest version
/*
 * 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.profile.query;

import org.apache.lucene.sandbox.search.ProfilerCollector;
import org.apache.lucene.search.Collector;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * This class wraps a Lucene Collector and times the execution of:
 * - setScorer()
 * - collect()
 * - doSetNextReader()
 * - needsScores()
 * 

* InternalProfiler facilitates the linking of the Collector graph */ public class InternalProfileCollector extends ProfilerCollector { private final InternalProfileCollector[] children; private final Collector wrappedCollector; public InternalProfileCollector(Collector collector, String reason, InternalProfileCollector... children) { super(collector, reason, Arrays.asList(children)); this.wrappedCollector = collector; this.children = children; } public Collector getWrappedCollector() { return wrappedCollector; } /** * Creates a human-friendly representation of the Collector name. *

* InternalBucket Collectors use the aggregation name in their toString() method, * which makes the profiled output a bit nicer. * * @param c The Collector to derive a name from * @return A (hopefully) prettier name */ @Override protected String deriveCollectorName(Collector c) { String s = c.getClass().getSimpleName(); // MultiCollector which wraps multiple BucketCollectors is generated // via an anonymous class, so this corrects the lack of a name by // asking the enclosingClass if (s.equals("")) { s = c.getClass().getEnclosingClass().getSimpleName(); } // Aggregation collector toString()'s include the user-defined agg name if (getReason().equals(CollectorResult.REASON_AGGREGATION) || getReason().equals(CollectorResult.REASON_AGGREGATION_GLOBAL)) { s += ": [" + c + "]"; } return s; } public CollectorResult getCollectorTree() { List childResults = new ArrayList<>(children.length); for (InternalProfileCollector child : children) { CollectorResult result = child.getCollectorTree(); childResults.add(result); } return new CollectorResult(getName(), getReason(), getTime(), childResults); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy