Class Execution.Context

  • Enclosing class:

    public static final class Execution.Context
    extends java.lang.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 Detail

      • Context

        public Context​(SearchChainRegistry searchChainRegistry,
                       IndexFacts indexFacts,
                       SpecialTokenRegistry tokenRegistry,
                       RendererRegistry rendererRegistry,
        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 Detail

      • createContextStub

        public static Execution.Context createContextStub()
        Creates a context stub with no information. This is for unit testing.
      • createContextStub

        public static Execution.Context createContextStub​(IndexFacts indexFacts)
        Create a Context instance where only the index related settings are initialized. This is for unit testing.
      • createContextStub

        public static Execution.Context createContextStub​(SearchChainRegistry searchChainRegistry,
                                                          IndexFacts indexFacts)
        Create a Context instance where only the search chain registry and index facts are initialized. This is for unit testing.
      • createContextStub

        public static Execution.Context createContextStub​(SearchChainRegistry searchChainRegistry,
                                                          IndexFacts indexFacts,
        Create a Context instance where only the search chain registry, index facts and linguistics are initialized. 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.
        sourceContext - the context from which to get the parameters
      • hashCode

        public int hashCode()
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object other)
        equals in class java.lang.Object
      • shallowCopy

        public Execution.Context shallowCopy()
        Standard shallow copy, the new instance will carry the same references as this.
        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())).
        indexFacts - an instance to override the following searcher's view of the indexes.
      • 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 SpecialTokenRegistry getTokenRegistry()
        the current set of special strings for the query tokenizer
      • setTokenRegistry

        public void setTokenRegistry​(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())).
        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.
        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.
        whether the system is assumed to be in a breakdown state
      • setBreakdown

        public void setBreakdown​(boolean breakdown)
      • getLinguistics

        public 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.
        The current Linguistics.
      • setLinguistics

        public void setLinguistics​( linguistics)