Class Execution.Context

java.lang.Object
com.yahoo.search.searchchain.Execution.Context
Enclosing class:
Execution

public static final class Execution.Context extends Object
The execution context is the search chain's current view of the indexes, search chain registrys, etc. Searcher instances may set values here to change the behavior of the rest of the search chain.

The Context class simply carries a set of objects which define the environment for the search. Important: All objects available through context need to be either truly immutable or support the freeze pattern.

If you are implementing a searcher where you need to create a new Context instance to create an Execution, you should use the context from the execution the searcher was invoked from. You can also copy (Context.shallowCopy()) the incoming context if it is necessary to do more. In other words, a minimal example would be:
new Execution(searchChain, execution.context())

  • Constructor Details

    • Context

      public Context(SearchChainRegistry searchChainRegistry, IndexFacts indexFacts, SchemaInfo schemaInfo, com.yahoo.language.process.SpecialTokenRegistry tokenRegistry, RendererRegistry rendererRegistry, com.yahoo.language.Linguistics linguistics, Executor executor)
      Creates a context from arguments, all of which may be null, though this can be risky. If you are doing this outside a test, it is usually better to do something like execution.context().shallowCopy() instead, and then set the fields you need to change. It is also safe to use the context from the incoming execution directly. In other words, a plug-in writer should practically never construct a Context instance directly.

      This context is never attached to an execution but is used to carry state into another context.

  • Method Details

    • createContextStub

      public static Execution.Context createContextStub()
      Creates a Context instance where everything except the given arguments is empty. This is for unit testing.
    • createContextStub

      public static Execution.Context createContextStub(SearchChainRegistry searchChainRegistry)
      Creates a Context instance where everything except the given arguments is empty. This is for unit testing.
    • createContextStub

      public static Execution.Context createContextStub(IndexFacts indexFacts)
      Creates a Context instance where everything except the given arguments is empty. This is for unit testing.
    • createContextStub

      public static Execution.Context createContextStub(SchemaInfo schemaInfo)
      Creates a Context instance where everything except the given arguments is empty. This is for unit testing.
    • createContextStub

      public static Execution.Context createContextStub(SearchChainRegistry searchChainRegistry, IndexFacts indexFacts)
      Creates a Context instance where everything except the given arguments is empty. This is for unit testing.
    • createContextStub

      public static Execution.Context createContextStub(IndexFacts indexFacts, com.yahoo.language.Linguistics linguistics)
      Creates a Context instance where everything except the given arguments is empty. This is for unit testing.
    • createContextStub

      public static Execution.Context createContextStub(SearchChainRegistry searchChainRegistry, IndexFacts indexFacts, com.yahoo.language.Linguistics linguistics)
    • createContextStub

      public static Execution.Context createContextStub(SearchChainRegistry searchChainRegistry, IndexFacts indexFacts, SchemaInfo schemaInfo, com.yahoo.language.Linguistics linguistics)
      Creates a Context instance where everything except the given arguments is empty. This is for unit testing.
    • populateFrom

      public void populateFrom(Execution.Context sourceContext)
      Populate missing values in this from the given context. Values which are non-null in this will not be overwritten.
      Parameters:
      sourceContext - the context from which to get the parameters
    • equals

      public boolean equals(Execution.Context other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • shallowCopy

      public Execution.Context shallowCopy()
      Standard shallow copy, the new instance will carry the same references as this.
      Returns:
      a new instance which is a shallow copy
    • getIndexFacts

      public IndexFacts getIndexFacts()
      Returns information about the indexes specified by the search definitions used in this system, or null if not know.
    • setIndexFacts

      public void setIndexFacts(IndexFacts indexFacts)
      Use this to override index settings for the searchers below a given searcher, the easiest way to do this is to wrap the incoming IndexFacts instance in a subclass. E.g. execution.context().setIndexFacts(new WrapperClass(execution.context().getIndexFacts())).
      Parameters:
      indexFacts - an instance to override the following searcher's view of the indexes
    • schemaInfo

      public SchemaInfo schemaInfo()
      Returns information about the schemas specified in this application. This is never null.
    • searchChainRegistry

      public SearchChainRegistry searchChainRegistry()
      Returns the search chain registry to use with this execution. This is a snapshot taken at creation of this execution, use Context.shallowCopy() to get a correctly instantiated Context if making a custom Context instance.
    • rendererRegistry

      public RendererRegistry rendererRegistry()
      Returns the template registry to use with this execution. This is a snapshot taken at creation of this execution.
    • getTokenRegistry

      public com.yahoo.language.process.SpecialTokenRegistry getTokenRegistry()
      Returns the current set of special strings for the query tokenizer
    • setTokenRegistry

      public void setTokenRegistry(com.yahoo.language.process.SpecialTokenRegistry tokenRegistry)
      Wrapping the incoming special token registry and then setting the wrapper as the token registry, can be used for changing the set of special tokens used by succeeding searchers. E.g. execution.context().setTokenRegistry(new WrapperClass(execution.context().getTokenRegistry())).
      Parameters:
      tokenRegistry - a new registry for overriding behavior of following searchers
    • setDetailedDiagnostics

      public void setDetailedDiagnostics(boolean breakdown)
    • getDetailedDiagnostics

      public boolean getDetailedDiagnostics()
      The container has some internal diagnostics mechanisms which may be costly, and therefore not active by default. Any general diagnostic mechanism which should not be active be default, may inspect that state here. If breakdown is assumed, a certain percentage of queries will have this set automatically.
      Returns:
      whether components exposing different level of diagnostics should go for the most detailed level
    • getBreakdown

      public boolean getBreakdown()
      If too many queries time out, the search handler will assume the system is in a breakdown state. This state is propagated here.
      Returns:
      whether the system is assumed to be in a breakdown state
    • setBreakdown

      public void setBreakdown(boolean breakdown)
    • getLinguistics

      public com.yahoo.language.Linguistics getLinguistics()
      Returns the Linguistics object assigned to this Context. This object provides access to all the linguistic-related APIs, and comes pre-configured with the Execution given.
    • setLinguistics

      public void setLinguistics(com.yahoo.language.Linguistics linguistics)
    • executor

      public Executor executor()
      Returns the executor that should be used to execute tasks as part of this execution. This is never null but will be an executor that runs a single thread if none is passed to this.