Class Execution


  • public class Execution
    extends com.yahoo.processing.execution.Execution

    An execution of a search chain. This keeps track of the call state for an execution (in the calling thread) of the searchers of a search chain.

    To execute a search chain, simply do

         Result result = new Execution(mySearchChain, execution.context()).search(query)
     

    See also AsyncExecution, which performs an execution in a separate thread than the caller.

    Execution instances should not be reused for multiple separate executions.

    Author:
    bratseth
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Execution.Context
      The execution context is the search chain's current view of the indexes, search chain registrys, etc.
      • Nested classes/interfaces inherited from class com.yahoo.processing.execution.Execution

        com.yahoo.processing.execution.Execution.Environment<COMPONENT extends com.yahoo.processing.Processor>, com.yahoo.processing.execution.Execution.Trace
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ATTRIBUTEPREFETCH  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Execution.Context context()
      Returns the context of this execution, which contains various objects which are looked up through a memory barrier at the point this is created and which is guaranteed to be frozen during the execution of this query.
      protected com.yahoo.processing.Response defaultResponse​(com.yahoo.processing.Request request)
      The default response returned from this kind of execution when there are not further processors - an empty Result
      void fill​(Result result)
      Fill hit properties with data using the default summary class, possibly overridden with the 'summary' request parameter.
      void fill​(Result result, java.lang.String summaryClass)
      Calls fill on the next searcher in this chain.
      void fillAttributes​(Result result)
      Fill hit properties with values from all in-memory attributes.
      protected void nextProcessor()  
      protected void onInvoking​(com.yahoo.processing.Request request, com.yahoo.processing.Processor processor)  
      protected void onReturning​(com.yahoo.processing.Request request, com.yahoo.processing.Processor processor, com.yahoo.processing.Response response)  
      Pong ping​(Ping ping)
      Calls ping on the next search in this chain.
      protected void previousProcessor()  
      com.yahoo.processing.Response process​(com.yahoo.processing.Request request)
      Does return search(((Query)request)
      Result search​(Query query)
      Calls search on the next searcher in this chain.
      SearchChainRegistry searchChainRegistry()
      Returns the search chain registry to use with this execution.
      TimeTracker timer()  
      • Methods inherited from class com.yahoo.processing.execution.Execution

        chain, createRoot, createRoot, environment, next, nextIndex, toString, trace
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • ATTRIBUTEPREFETCH

        public static final java.lang.String ATTRIBUTEPREFETCH
        See Also:
        Constant Field Values
    • Constructor Detail

      • Execution

        public Execution​(Execution execution)

        Creates an execution from another. This execution will start at the current next searcher in the given execution, rather than at the start.

        The relevant state of the given execution is copied before this method returns - the argument execution can then be reused for any other purpose.

      • Execution

        public Execution​(Execution.Context context)
        Creates an which executes nothing
      • Execution

        public Execution​(com.yahoo.component.chain.Chain<? extends Searcher> searchChain,
                         Execution.Context context)
        The usually best way of creating a new execution for a search chain. This is the one suitable for a production environment. It is safe to use the incoming context from the search directly:
         public Result search(Query query, Execution execution) {
             SearchChain searchChain = fancyChainSelectionRoutine(query);
             if (searchChain != null) {
                 return new Execution(searchChain, execution.context());
             else {
                 return execution.search(query);
             }
         }
         
        Parameters:
        searchChain - the search chain to execute
        context - the execution context from which this is populated (the given context is not changed nor retained by this), or null to not populate from a context
        Throws:
        java.lang.IllegalArgumentException - if searchChain is null
    • Method Detail

      • process

        public final com.yahoo.processing.Response process​(com.yahoo.processing.Request request)
        Does return search(((Query)request)
        Overrides:
        process in class com.yahoo.processing.execution.Execution
      • search

        public Result search​(Query query)
        Calls search on the next searcher in this chain. If there is no next, an empty result is returned.
      • onInvoking

        protected void onInvoking​(com.yahoo.processing.Request request,
                                  com.yahoo.processing.Processor processor)
        Overrides:
        onInvoking in class com.yahoo.processing.execution.Execution
      • defaultResponse

        protected com.yahoo.processing.Response defaultResponse​(com.yahoo.processing.Request request)
        The default response returned from this kind of execution when there are not further processors - an empty Result
        Overrides:
        defaultResponse in class com.yahoo.processing.execution.Execution
      • fillAttributes

        public void fillAttributes​(Result result)
        Fill hit properties with values from all in-memory attributes. This can be done with good performance on many more hits than those for which fill is called with the final summary class, so if filtering can be done using only in-memory attribute data, this method should be preferred over fill(com.yahoo.search.Result) to get that data for filtering.

        Calling this on already filled results has no cost.

        Parameters:
        result - the result to fill
      • fill

        public void fill​(Result result)
        Fill hit properties with data using the default summary class, possibly overridden with the 'summary' request parameter.

        Fill must be called before any property (accessed by getProperty/getField) is accessed on the hit. It should be done as late as possible for performance reasons.

        Calling this on already filled results has no cost.

        Parameters:
        result - the result to fill
      • fill

        public void fill​(Result result,
                         java.lang.String summaryClass)
        Calls fill on the next searcher in this chain. If there is no next, nothing is done.
      • ping

        public Pong ping​(Ping ping)
        Calls ping on the next search in this chain. If there is no next, a Pong is created and returned.
      • onReturning

        protected void onReturning​(com.yahoo.processing.Request request,
                                   com.yahoo.processing.Processor processor,
                                   com.yahoo.processing.Response response)
        Overrides:
        onReturning in class com.yahoo.processing.execution.Execution
      • previousProcessor

        protected void previousProcessor()
        Overrides:
        previousProcessor in class com.yahoo.processing.execution.Execution
      • nextProcessor

        protected void nextProcessor()
        Overrides:
        nextProcessor in class com.yahoo.processing.execution.Execution
      • searchChainRegistry

        public SearchChainRegistry searchChainRegistry()
        Returns the search chain registry to use with this execution. This is a snapshot taken at creation of this execution if available.
      • context

        public Execution.Context context()
        Returns the context of this execution, which contains various objects which are looked up through a memory barrier at the point this is created and which is guaranteed to be frozen during the execution of this query.

        Note that the context itself can be changed. Such changes will be visible to downstream searchers, but not after returning from the modifying searcher. In other words, a change in the context will not be visible to the preceding searchers when the result is returned from the searcher which modified the context.

      • timer

        public TimeTracker timer()
        Returns:
        the TimeTracker instance associated with this Execution