Class Result

java.lang.Object
com.yahoo.component.provider.FreezableClass
com.yahoo.component.provider.ListenableFreezableClass
com.yahoo.processing.Response
com.yahoo.search.Result
All Implemented Interfaces:
com.yahoo.component.provider.Freezable, com.yahoo.component.provider.ListenableFreezable, Cloneable

public final class Result extends com.yahoo.processing.Response implements 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 appropriate partial answer to the Query.

Do not cache this as it holds references to objects that should be garbage collected.

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

    Modifier and Type
    Method
    Description
    void
    Update cached and filled by iterating through the hits of this result
    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<?>
     
    int
    Returns the total number of concrete hits contained (directly or in subgroups) in this result.
    getContext(boolean create)
    Returns the context of this result - this is equal to getQuery().getContext(create)
    getCoverage(boolean create)
    Returns coverage information
    long
    Returns the estimated total number of deep hits, which includes every object which matches the query.
    boolean
     
     
    com.yahoo.collections.ListMap<String,String>
    getHeaders(boolean create)
    Returns the set of "envelope" headers to be returned with this result.
    int
    Returns the number of hit objects available in the top level group of this result.
    Returns the orderer used by the top level group, or null if the default relevancy order is used
    Returns the query which produced this result
    long
    Returns the estimated total number of concrete hits which would be returned for this query.
    Returns the top level hit group containing all the hits of this result
    boolean
    Returns true only if _all_ hits in this result originates from a cache.
    boolean
    isFilled(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
    Merges meta information produced when a Hit already contained in this result has been filled using another result as an intermediary.
    void
     
    void
    setDeepHitCount(long deepHitCount)
    Sets the estimated total number of deep hits this result is a subset of
    void
     
    void
     
    void
    Sets the hit orderer to be used for the top level hit group.
    void
    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
     
    void
    trace(String name)
    Adds a context message to this query containing the entire content of this result, if tracelevel is 5 or more.
    protected void
    For tracing custom properties of a hit, see trace(String).

    Methods inherited from class com.yahoo.processing.Response

    mergeWith, recursiveFuture

    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 Details

    • 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 Details

    • 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
    • getElapsedTime

      public ElapsedTime getElapsedTime()
    • 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(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 String toString()
      Overrides:
      toString in class Object
    • trace

      public void trace(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(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<String,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