Class Result

  • All Implemented Interfaces:
    com.yahoo.component.provider.Freezable, com.yahoo.component.provider.ListenableFreezable, java.lang.Cloneable

    public final class Result
    extends com.yahoo.processing.Response
    implements java.lang.Cloneable
    The Result contains all the data produced by executing a Query: Some very limited global information, and a single HitGroup containing hits of the result. The HitGroup may contain Hits, which are the individual result items, as well as further HitGroups, making up a composite structure. This allows the hits of a result to be hierarchically organized. A Hit is polymorphic and may contain any kind of information deemed an approriate partial answer to the Query.
    Author:
    bratseth
    • Constructor Summary

      Constructors 
      Constructor Description
      Result​(Query query)
      Creates a new Result where the top level hit group has id "toplevel"
      Result​(Query query, ErrorMessage errorMessage)
      Create a result containing an error
      Result​(Query query, HitGroup hits)
      Create an empty result.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void analyzeHits()
      Update cached and filled by iterating through the hits of this result
      Result clone()
      Deep clones this result - copies are made of all hits and subgroups of hits, but not of the query referenced by this.
      com.yahoo.processing.response.DataList<?> data()  
      int getConcreteHitCount()
      Returns the total number of concrete hits contained (directly or in subgroups) in this result.
      QueryContext getContext​(boolean create)
      Returns the context of this result - this is equal to getQuery().getContext(create)
      Coverage getCoverage​(boolean create)
      Returns coverage information
      long getDeepHitCount()
      Returns the estimated total number of deep hits, which includes every object which matches the query.
      boolean getDeletionBreaksOrdering()  
      ElapsedTime getElapsedTime()  
      com.yahoo.collections.ListMap<java.lang.String,​java.lang.String> getHeaders​(boolean create)
      Returns the set of "envelope" headers to be returned with this result.
      int getHitCount()
      Returns the number of hit objects available in the top level group of this result.
      HitOrderer getHitOrderer()
      Returns the orderer used by the top level group, or null if the default relevancy order is used
      Query getQuery()
      Returns the query which produced this result
      long getTotalHitCount()
      Returns the estimated total number of concrete hits which would be returned for this query.
      HitGroup hits()
      Returns the top level hit group containing all the hits of this result
      boolean isCached()
      Returns true only if _all_ hits in this result originates from a cache.
      boolean isFilled​(java.lang.String summaryClass)
      Returns whether all hits in this result have been filled with the properties contained in the given summary class.
      void mergeWith​(Result result)
      Merges meta information from a result into this.
      void mergeWithAfterFill​(Result result)
      Merges meta information produced when a Hit already contained in this result has been filled using another result as an intermediary.
      void setCoverage​(Coverage coverage)  
      void setDeepHitCount​(long deepHitCount)
      Sets the estimated total number of deep hits this result is a subset of
      void setDeletionBreaksOrdering​(boolean flag)  
      void setElapsedTime​(ElapsedTime t)  
      void setHitOrderer​(HitOrderer hitOrderer)
      Sets the hit orderer to be used for the top level hit group.
      void setHits​(HitGroup hits)
      Sets the top level hit group containing all the hits of this result
      void setQuery​(Query query)
      Sets a query for this result
      void setTotalHitCount​(long totalHitCount)
      Sets the estimated total number of hits this result is a subset of
      java.lang.String toString()  
      void trace​(java.lang.String name)
      Adds a context message to this query containing the entire content of this result, if tracelevel is 5 or more.
      protected void traceExtraHitProperties​(java.lang.StringBuilder hitBuffer, Hit hit)
      For tracing custom properties of a hit, see trace(String).
      • Methods inherited from class com.yahoo.processing.Response

        mergeWith, recursiveComplete
      • Methods inherited from class com.yahoo.component.provider.ListenableFreezableClass

        addFreezeListener, freeze
      • Methods inherited from class com.yahoo.component.provider.FreezableClass

        ensureNotFrozen, isFrozen
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface com.yahoo.component.provider.Freezable

        isFrozen
    • Constructor Detail

      • Result

        public Result​(Query query)
        Creates a new Result where the top level hit group has id "toplevel"
      • Result

        public Result​(Query query,
                      HitGroup hits)
        Create an empty result. A source creating a result is required to call setTotalHitCount(long) before releasing this result.
        Parameters:
        query - the query which produced this result
        hits - the hit container which this will return from hits()
      • Result

        public Result​(Query query,
                      ErrorMessage errorMessage)
        Create a result containing an error
    • Method Detail

      • mergeWith

        public void mergeWith​(Result result)
        Merges meta information from a result into this. This does not merge hits, but the other information associated with a result. It should always be called when adding hits from a result, but there is no constraints on the order of the calls.
      • mergeWithAfterFill

        public void mergeWithAfterFill​(Result result)
        Merges meta information produced when a Hit already contained in this result has been filled using another result as an intermediary. @see mergeWith(Result) mergeWith.
      • getHitCount

        public int getHitCount()
        Returns the number of hit objects available in the top level group of this result. Note that this number is allowed to be higher than the requested number of hits, because a searcher is allowed to add meta hits as well as the requested number of concrete hits.
      • getConcreteHitCount

        public int getConcreteHitCount()

        Returns the total number of concrete hits contained (directly or in subgroups) in this result. This should equal the requested hits count if the query has that many matches.

      • getTotalHitCount

        public long getTotalHitCount()
        Returns the estimated total number of concrete hits which would be returned for this query.
      • getDeepHitCount

        public long getDeepHitCount()
        Returns the estimated total number of deep hits, which includes every object which matches the query. This is always at least the same as totalHitCount. A lower value will cause hitCount to be returned.
      • setTotalHitCount

        public void setTotalHitCount​(long totalHitCount)
        Sets the estimated total number of hits this result is a subset of
      • setDeepHitCount

        public void setDeepHitCount​(long deepHitCount)
        Sets the estimated total number of deep hits this result is a subset of
      • setElapsedTime

        public void setElapsedTime​(ElapsedTime t)
      • isCached

        public boolean isCached()
        Returns true only if _all_ hits in this result originates from a cache.
      • isFilled

        public boolean isFilled​(java.lang.String summaryClass)
        Returns whether all hits in this result have been filled with the properties contained in the given summary class. Note that this method will also return true if no hits in this result are fillable.
      • getQuery

        public Query getQuery()
        Returns the query which produced this result
      • setQuery

        public void setQuery​(Query query)
        Sets a query for this result
      • setHitOrderer

        public void setHitOrderer​(HitOrderer hitOrderer)

        Sets the hit orderer to be used for the top level hit group.

        Parameters:
        hitOrderer - the new hit orderer, or null to use default relevancy ordering
      • getHitOrderer

        public HitOrderer getHitOrderer()
        Returns the orderer used by the top level group, or null if the default relevancy order is used
      • setDeletionBreaksOrdering

        public void setDeletionBreaksOrdering​(boolean flag)
      • getDeletionBreaksOrdering

        public boolean getDeletionBreaksOrdering()
      • analyzeHits

        public void analyzeHits()
        Update cached and filled by iterating through the hits of this result
      • hits

        public HitGroup hits()
        Returns the top level hit group containing all the hits of this result
      • data

        public com.yahoo.processing.response.DataList<?> data()
        Overrides:
        data in class com.yahoo.processing.Response
      • setHits

        public void setHits​(HitGroup hits)
        Sets the top level hit group containing all the hits of this result
      • clone

        public Result clone()
        Deep clones this result - copies are made of all hits and subgroups of hits, but not of the query referenced by this.
        Overrides:
        clone in class com.yahoo.component.provider.ListenableFreezableClass
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • trace

        public void trace​(java.lang.String name)
        Adds a context message to this query containing the entire content of this result, if tracelevel is 5 or more.
        Parameters:
        name - the name of the searcher instance returning this result
      • traceExtraHitProperties

        protected void traceExtraHitProperties​(java.lang.StringBuilder hitBuffer,
                                               Hit hit)
        For tracing custom properties of a hit, see trace(String). An example of using this is in com.yahoo.prelude.Result.
        Parameters:
        hitBuffer - the render target
        hit - the hit to be analyzed
      • getContext

        public QueryContext getContext​(boolean create)
        Returns the context of this result - this is equal to getQuery().getContext(create)
      • setCoverage

        public void setCoverage​(Coverage coverage)
      • getCoverage

        public Coverage getCoverage​(boolean create)
        Returns coverage information
        Parameters:
        create - if true the coverage information of this result is created if missing
        Returns:
        the coverage information of this, or null if none and create is false
      • getHeaders

        public com.yahoo.collections.ListMap<java.lang.String,​java.lang.String> getHeaders​(boolean create)
        Returns the set of "envelope" headers to be returned with this result. This returns the live map in modifiable form - modify this to change the headers. Or null if none, and it should not be created.

        Used for HTTP headers when the return protocol is HTTP, e.g

        result.getHeaders(true).put("Cache-Control","max-age=120")
        Parameters:
        create - if true, create the header ListMap if it does not exist
        Returns:
        returns the ListMap of current headers, or null if no headers are set and
        create
        is false