Class Hit
- All Implemented Interfaces:
com.yahoo.component.provider.Freezable
,com.yahoo.component.provider.ListenableFreezable
,com.yahoo.processing.response.Data
,Cloneable
,Comparable<Hit>
- Direct Known Subclasses:
DefaultErrorHit
,FastHit
,GroupingListHit
,HitGroup
An item in the result of executing a query.
Hits may be of the meta type, meaning that they contain some information about the query or result which does not represent a particular matched item. Meta hits are not counted in the hit count of the result, and should usually never be filtered out.
Some hit sources may produce hits which are not filled. A non-filled
hit may miss some or all of its property values. To fill those,
fill
must be called on the search chain by the searcher
which requires those properties. This mechanism allows initial filtering to be
done of a lightweight version of the hits, which is cheaper if a significant
number of hits are filtered out.
Do not cache this as it holds references to objects that should be garbage collected.
- Author:
- bratseth
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
Hit()
Creates an (invalid) empty hit.protected
Creates a minimal valid hit having relevance 1Creates a minimal valid hit.Creates a minimal valid hit.Creates a hit.Creates a hit.Creates a minimal valid hit having relevance 1Creates a minimal valid hit.Creates a minimal valid hit.Creates a hit.Creates a hit. -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
assignId
(com.yahoo.net.URI id) Assigns a new or changed id to this hit.buildHitField
(String key, boolean forceNoPreTokenize) void
Removes all fields of thisclone()
protected void
close()
Releases the resources held by this, making it irreversibly unusableint
Compares this hit to another hitboolean
Returns true if the argument is a hit having the same id as thisfeatures()
Returns the features computed for this hit.Returns a modifiable iterator over the fields of thisReturns the keys of the fields of this hit as a modifiable view.fields()
Returns the fields of this as a read-only map.void
forEachField
(BiConsumer<String, Object> consumer) Receive a callback on the given object for each field in this hit.void
forEachFieldAsRaw
(Hit.RawUtf8Consumer consumer) Receive a callback on the given object for each field in this hit, where the callback will provide raw utf-8 byte data for strings whose data is already available at this form.Returns the id to display, or null to not display (render) the id.Returns a field value or null if not presentReturns the set of summary classes for which this hit is filled as an unmodifiable set.com.yahoo.net.URI
getId()
Returns the hit idgetQuery()
Returns the query which produced this hit, or null if not knownReturns the relevance of this hitgetSearcherSpecificMetaData
(Searcher searcher) Returns data attached to this hit for this searcher, or null if noneReturns the name of the source creating this hitprotected boolean
protected boolean
Returns whether any fields are set in thisint
hashCode()
Returns the hashCode of this hit: The hashcode of its idboolean
Auxiliary hits are not counted towards the concrete number of hits to satisfy in the users request.boolean
isCached()
Returns whether this hit was added to this result from a cache or notboolean
boolean
Returns whether this hit has been filled with the properties contained in the given summary class.boolean
isMeta()
Returns whether this is a concrete hit, containing content of the requested kind, or a meta hit containing information on the collection of hits, the query, the service and so on.removeField
(String field) Removes a field from thiscom.yahoo.processing.Request
request()
Returns the query which produced this hit as a request, or null if not knownvoid
reserve
(int minSize) Allocate room for the given number of fields to avoid resizing.void
setAuxiliary
(boolean auxiliary) void
setCached
(boolean cached) Sets whether this hit is returned from a cache.Sets the value of a fieldvoid
Tag this hit as fillable.void
Register that this hit has been filled with properties using the given summary class.void
setId
(com.yahoo.net.URI id) Initializes the id of this hit.void
Calls setId(new URI(id))void
setMeta
(boolean meta) final void
Sets the query which produced this.void
setRelevance
(double relevance) Does setRelevance(new Relevance(relevance)void
setRelevance
(Relevance relevance) Sets the relevance of this hitvoid
setSearcherSpecificMetaData
(Searcher searcher, Object data) Attach some data to this hit for this searchervoid
Sets the name of the source creating this hittoString()
types()
Returns the types of this as a modifiable set.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
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.yahoo.component.provider.Freezable
freeze, isFrozen
Methods inherited from interface com.yahoo.component.provider.ListenableFreezable
addFreezeListener
-
Field Details
-
RANKFEATURES_FIELD
The hit field used to store rank features- See Also:
-
SDDOCNAME_FIELD
- See Also:
-
-
Constructor Details
-
Hit
protected Hit()Creates an (invalid) empty hit. Id and relevance must be set before handoff -
Hit
-
Hit
Creates a minimal valid hit having relevance 1- Parameters:
id
- the URI of a hit. This should be unique for this hit (but not for this object instance of course). For hit types refering to resources, this will be the full, valid url of the resource, for self-contained hits it is simply any unique string identification
-
Hit
Creates a minimal valid hit having relevance 1- Parameters:
id
- the URI of a hit. This should be unique for this hit (but not for this object instance of course). For hit types referring to resources, this will be the full, valid url of the resource, for self-contained hits it is simply any unique string identificationquery
- the query having this as a hit
-
Hit
Creates a minimal valid hit.- Parameters:
id
- the URI of a hit. This should be unique for this hit (but not for this object instance of course). For hit types referring to resources, this will be the full, valid url of the resource, for self-contained hits it is simply any unique string identificationrelevance
- a relevance measure, preferably normalized between 0 and 1- Throws:
IllegalArgumentException
- if the given relevance is not between 0 and 1
-
Hit
Creates a minimal valid hit.- Parameters:
id
- the URI of a hit. This should be unique for this hit (but not for this object instance of course). For hit types referring to resources, this will be the full, valid url of the resource, for self-contained hits it is simply any unique string identificationrelevance
- a relevance measure, preferably normalized between 0 and 1query
- the query having this as a hit- Throws:
IllegalArgumentException
- if the given relevance is not between 0 and 1
-
Hit
Creates a minimal valid hit.- Parameters:
id
- the URI of a hit. This should be unique for this hit (but not for this object instance of course). For hit types refering to resources, this will be the full, valid url of the resource, for self-contained hits it is simply any unique string identificationrelevance
- the relevance of this hit- Throws:
IllegalArgumentException
- if the given relevance is not between 0 and 1000
-
Hit
Creates a minimal valid hit.- Parameters:
id
- the URI of a hit. This should be unique for this hit (but not for this object instance of course). For hit types refering to resources, this will be the full, valid url of the resource, for self-contained hits it is simply any unique string identificationrelevance
- the relevance of this hitquery
- the query having this as a hit- Throws:
IllegalArgumentException
- if the given relevance is not between 0 and 1000
-
Hit
Creates a hit.- Parameters:
id
- the URI of a hit. This should be unique for this hit (but not for this object instance of course). For hit types refering to resources, this will be the full, valid url of the resource, for self-contained hits it is simply any unique string identificationrelevance
- a relevance measure, preferably normalized between 0 and 1source
- the name of the source of this hit, or null if no source is being specified
-
Hit
Creates a hit.- Parameters:
id
- the URI of a hit. This should be unique for this hit (but not for this object instance of course). For hit types refering to resources, this will be the full, valid url of the resource, for self-contained hits it is simply any unique string identificationrelevance
- a relevance measure, preferably normalized between 0 and 1source
- the name of the source of this hit, or null if no source is being specifiedquery
- the query having this as a hit
-
Hit
Creates a hit.- Parameters:
id
- the URI of a hit. This should be unique for this hit (but not for this object instance of course). For hit types refering to resources, this will be the full, valid url of the resource, for self-contained hits it is simply any unique string identificationrelevance
- the relevance of this hitsource
- the name of the source of this hit
-
Hit
Creates a hit.- Parameters:
id
- the URI of a hit. This should be unique for this hit (but not for this object instance of course). For hit types refering to resources, this will be the full, valid url of the resource, for self-contained hits it is simply any unique string identificationrelevance
- the relevance of this hitsource
- the name of the source of this hitquery
- the query having this as a hit
-
-
Method Details
-
setId
Calls setId(new URI(id)) -
setId
public void setId(com.yahoo.net.URI id) Initializes the id of this hit.- Throws:
NullPointerException
- if the uri is nullIllegalStateException
- if the uri of this hit is already set
-
assignId
protected final void assignId(com.yahoo.net.URI id) Assigns a new or changed id to this hit. As this is protected, reassigning isn't legal for Hits by default, however, subclasses may allow it using this method. -
getId
public com.yahoo.net.URI getId()Returns the hit id -
getDisplayId
Returns the id to display, or null to not display (render) the id. This is useful to avoid displaying ids when they are not assigned explicitly but are just generated values for internal use. This default implementation returns the field DOCUMENT_ID if set, andgetId()
.toString() otherwise. -
setRelevance
Sets the relevance of this hit -
setRelevance
public void setRelevance(double relevance) Does setRelevance(new Relevance(relevance) -
getRelevance
Returns the relevance of this hit -
setCached
public void setCached(boolean cached) Sets whether this hit is returned from a cache. Default is false -
isCached
public boolean isCached()Returns whether this hit was added to this result from a cache or not -
setFillable
public void setFillable()Tag this hit as fillable. This means that additional properties for this hit may be obtained by fetching document summaries. This also enables tracking of which summary classes have been used for filling so far. Invoking this method multiple times is allowed and will have no addition effect. Note that a fillable hit may not be made unfillable. -
setFilled
Register that this hit has been filled with properties using the given summary class. Note that this method will implicitly tag this hit as fillable if it is currently not.- Parameters:
summaryClass
- summary class used for filling
-
isFillable
public boolean isFillable() -
getFilled
Returns the set of summary classes for which this hit is filled as an unmodifiable set. If this set is 'null', it means that this hit is unfillable, which is equivalent to a hit where all summary classes have already been used for filling, or a hit where further filling will yield no extra information, if you prefer to look at it that way. Note that you might need to overload isFilled if you overload this one. -
isFilled
Returns whether this hit has been filled with the properties contained in the given summary class. Note that this method will also return true if this hit is not fillable. -
setSource
Sets the name of the source creating this hit -
getSource
Returns the name of the source creating this hit -
forEachField
Receive a callback on the given object for each field in this hit. This is more efficient than accessing the fields as a map or iterator. -
forEachFieldAsRaw
Receive a callback on the given object for each field in this hit, where the callback will provide raw utf-8 byte data for strings whose data is already available at this form. This is the most resource efficient way of traversing all the fields of a hit in renderers which produces utf-8. -
fields
Returns the fields of this as a read-only map. This is more costly than fieldIterator() -
fieldIterator
Returns a modifiable iterator over the fields of this -
fieldKeys
Returns the keys of the fields of this hit as a modifiable view. This follows the rules of key sets returned from maps: Key removals are reflected in the map, add and addAll is not supported. -
reserve
public void reserve(int minSize) Allocate room for the given number of fields to avoid resizing. -
setField
Sets the value of a field- Returns:
- the previous value, or null if none
-
getField
Returns a field value or null if not present -
clearFields
public void clearFields()Removes all fields of this -
removeField
Removes a field from this- Returns:
- the removed value of the field, or null if none
-
hasField
-
hasFields
protected boolean hasFields()Returns whether any fields are set in this -
buildHitField
-
types
Returns the types of this as a modifiable set. Modifications to this set are directly reflected in this hit -
isMeta
public boolean isMeta()Returns whether this is a concrete hit, containing content of the requested kind, or a meta hit containing information on the collection of hits, the query, the service and so on. This default implementation return false. -
setMeta
public void setMeta(boolean meta) -
isAuxiliary
public boolean isAuxiliary()Auxiliary hits are not counted towards the concrete number of hits to satisfy in the users request. Any kind of meta hit is auxiliary, but hits containing concrete results can also be auxiliary, for example ads in a service which does not primarily serve ads, or groups in a hierarchical organization.- Returns:
- true if the auxiliary value is true, or if this is a meta hit
-
setAuxiliary
public void setAuxiliary(boolean auxiliary) -
getQuery
Returns the query which produced this hit, or null if not known -
request
public com.yahoo.processing.Request request()Returns the query which produced this hit as a request, or null if not known- Specified by:
request
in interfacecom.yahoo.processing.response.Data
-
setQuery
Sets the query which produced this. This is ignored (except if this is a HitGroup) if a query is already set -
features
Returns the features computed for this hit. This is never null but may be empty. This default implementation always returns empty. -
setSearcherSpecificMetaData
Attach some data to this hit for this searcher -
getSearcherSpecificMetaData
Returns data attached to this hit for this searcher, or null if none -
close
protected void close()Releases the resources held by this, making it irreversibly unusable -
equals
Returns true if the argument is a hit having the same id as this -
hashCode
public int hashCode()Returns the hashCode of this hit: The hashcode of its id -
compareTo
Compares this hit to another hit- Specified by:
compareTo
in interfaceComparable<Hit>
-
clone
- Overrides:
clone
in classcom.yahoo.component.provider.ListenableFreezableClass
-
toString
-