public class Hit extends com.yahoo.component.provider.ListenableFreezableClass implements com.yahoo.processing.response.Data, Comparable<Hit>, Cloneable
A search hit. The identifier of the hit is the uri (the uri is immutable once set). If two hits have the same uri they are equal per definition. Hits are naturally ordered by decreasing relevance. Note that this definition of equals and natural ordering is inconsistent.
Hits may be of the meta type, meaning that they contain some information about the query or result which does not represent a particular piece of matched content. 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.
Modifier and Type | Class and Description |
---|---|
static interface |
Hit.RawUtf8Consumer |
Modifier and Type | Field and Description |
---|---|
static String |
RANKFEATURES_FIELD
The hit field used to store rank features.
|
static String |
SDDOCNAME_FIELD |
Modifier | Constructor and Description |
---|---|
protected |
Hit()
Creates an (invalid) empty hit.
|
|
Hit(String id)
Creates a minimal valid hit having relevance 1000
|
|
Hit(String id,
double relevance)
Creates a minimal valid hit.
|
|
Hit(String id,
double relevance,
Query query)
Creates a minimal valid hit.
|
|
Hit(String id,
double relevance,
String source)
Creates a hit.
|
|
Hit(String id,
double relevance,
String source,
Query query)
Creates a hit.
|
|
Hit(String id,
Query query)
Creates a minimal valid hit having relevance 1
|
|
Hit(String id,
Relevance relevance)
Creates a minimal valid hit.
|
|
Hit(String id,
Relevance relevance,
Query query)
Creates a minimal valid hit.
|
|
Hit(String id,
Relevance relevance,
String source)
Creates a hit.
|
|
Hit(String id,
Relevance relevance,
String source,
Query query)
Creates a hit.
|
Modifier and Type | Method and Description |
---|---|
protected void |
assignId(com.yahoo.net.URI id)
Assigns a new or changed id to this hit.
|
HitField |
buildHitField(String key)
Generate a HitField from a field if the field exists
|
HitField |
buildHitField(String key,
boolean forceNoPreTokenize)
Generate a HitField from a field if the field exists
|
HitField |
buildHitField(String key,
boolean forceNoPreTokenize,
boolean forceStringHandling)
Deprecated.
|
void |
changeFieldKey(String oldKey,
String newKey)
Deprecated.
do not use
|
void |
clearFields()
Removes all fields of this
|
Hit |
clone() |
protected void |
close()
Releases the resources held by this, making it irreversibly unusable
|
int |
compareTo(Hit other)
Compares this hit to another hit
|
boolean |
equals(Object object)
Returns true if the argument is a hit having the same uri as this
|
Iterator<Map.Entry<String,Object>> |
fieldIterator()
Returns a modifiable iterator over the fields of this
|
Set<String> |
fieldKeys()
Returns the keys of the fields of this hit as a modifiable view.
|
Map<String,Object> |
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.
|
int |
getAddNumber()
Deprecated.
do not use
|
String |
getDisplayId()
Returns the id to display, or null to not display (render) the id.
|
Object |
getField(String value)
Returns a field value or null if not present
|
String |
getFieldXML(String key)
Deprecated.
do not use
|
Set<String> |
getFilled()
Returns the set of summary classes for which this hit is
filled as an unmodifiable set.
|
protected Set<String> |
getFilledInternal()
For internal use only.
|
com.yahoo.net.URI |
getId()
Returns the hit id
|
Query |
getQuery()
Returns the query which produced this hit, or null if not known
|
Relevance |
getRelevance()
Returns the relevance of this hit
|
Object |
getSearcherSpecificMetaData(Searcher searcher)
Returns data attached to this hit for this searcher, or null if none
|
String |
getSource()
Returns the name of the source creating this hit
|
int |
getSourceNumber()
Deprecated.
do not use
|
String |
getTypeString()
Deprecated.
do not use
|
String |
getUnboldedField(String key,
boolean escape)
Deprecated.
do not use
|
protected boolean |
hasField(String name) |
protected boolean |
hasFields()
Returns whether any fields are set in this
|
int |
hashCode()
Returns the hashCode of this hit, which is the hashcode of its uri.
|
boolean |
isAuxiliary()
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 not
|
boolean |
isFillable() |
boolean |
isFilled(String summaryClass)
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.
|
Object |
removeField(String field)
Removes a field from this
|
com.yahoo.processing.Request |
request()
Returns the query which produced this hit as a request, or null if not known
|
void |
reserve(int minSize)
Allocate room for the given number of fields to avoid resizing.
|
void |
setAddNumber(int addNumber)
Deprecated.
do not use
|
void |
setAuxiliary(boolean auxiliary) |
void |
setCached(boolean cached)
Sets whether this hit is returned from a cache.
|
Object |
setField(String key,
Object value)
Sets the value of a field
|
void |
setFillable()
Tag this hit as fillable.
|
void |
setFilled(String summaryClass)
Register that this hit has been filled with properties using
the given summary class.
|
protected void |
setFilledInternal(Set<String> filled)
Internal - do not use
|
void |
setId(String id)
Calls setId(new URI(id))
|
void |
setId(com.yahoo.net.URI id)
Initializes the id of this hit.
|
void |
setMeta(boolean meta) |
void |
setQuery(Query query)
Sets the query which produced this.
|
void |
setRelevance(double relevance)
Does setRelevance(new Relevance(relevance)
|
void |
setRelevance(Relevance relevance)
Sets the relevance of this hit
|
void |
setSearcherSpecificMetaData(Searcher searcher,
Object data)
Attach some data to this hit for this searcher
|
void |
setSource(String source)
Sets the name of the source creating this hit
|
void |
setSourceNumber(int number)
Deprecated.
do not use
|
static String |
stripCharacter(char strip,
String toStripFrom)
Deprecated.
do not use
|
String |
toString() |
Set<String> |
types()
Returns the types of this as a modifiable set.
|
addFreezeListener, freeze
public static final String RANKFEATURES_FIELD
public static final String SDDOCNAME_FIELD
protected Hit()
public Hit(String id)
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 identificationpublic Hit(String id, Query query)
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 hitpublic Hit(String id, double relevance)
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 1IllegalArgumentException
- if the given relevance is not between 0 and 1public Hit(String id, double relevance, Query query)
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 hitIllegalArgumentException
- if the given relevance is not between 0 and 1public Hit(String id, Relevance relevance)
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 hitIllegalArgumentException
- if the given relevance is not between 0 and 1000public Hit(String id, Relevance relevance, Query query)
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 hitIllegalArgumentException
- if the given relevance is not between 0 and 1000public Hit(String id, double relevance, String source)
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 specifiedIllegalArgumentException
- if the given relevance is not between 0 and 1000public Hit(String id, double relevance, String source, Query query)
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 hitIllegalArgumentException
- if the given relevance is not between 0 and 1000public Hit(String id, Relevance relevance, String source)
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 hitIllegalArgumentException
- if the given relevance is not between 0 and 1000public Hit(String id, Relevance relevance, String source, Query query)
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 hitIllegalArgumentException
- if the given relevance is not between 0 and 1000public void setId(String id)
public void setId(com.yahoo.net.URI id)
NullPointerException
- if the uri is nullIllegalStateException
- if the uri of this hit is already setprotected final void assignId(com.yahoo.net.URI id)
public com.yahoo.net.URI getId()
public String getDisplayId()
getId()
.toString()public void setRelevance(Relevance relevance)
public void setRelevance(double relevance)
public Relevance getRelevance()
public void setCached(boolean cached)
public boolean isCached()
public void setFillable()
public void setFilled(String summaryClass)
summaryClass
- summary class used for fillingpublic boolean isFillable()
public Set<String> getFilled()
public boolean isFilled(String summaryClass)
public void setSource(String source)
public String getSource()
public void forEachField(BiConsumer<String,Object> consumer)
public void forEachFieldAsRaw(Hit.RawUtf8Consumer consumer)
public Map<String,Object> fields()
public Iterator<Map.Entry<String,Object>> fieldIterator()
public Set<String> fieldKeys()
public void reserve(int minSize)
public Object setField(String key, Object value)
public void clearFields()
public Object removeField(String field)
protected boolean hasField(String name)
protected boolean hasFields()
@Deprecated public void changeFieldKey(String oldKey, String newKey)
public HitField buildHitField(String key)
public HitField buildHitField(String key, boolean forceNoPreTokenize)
@Deprecated public HitField buildHitField(String key, boolean forceNoPreTokenize, boolean forceStringHandling)
public Set<String> types()
@Deprecated public String getTypeString()
@Deprecated public int getAddNumber()
@Deprecated public void setAddNumber(int addNumber)
public boolean isMeta()
public void setMeta(boolean meta)
public boolean isAuxiliary()
public void setAuxiliary(boolean auxiliary)
@Deprecated public int getSourceNumber()
@Deprecated public void setSourceNumber(int number)
public Query getQuery()
public com.yahoo.processing.Request request()
request
in interface com.yahoo.processing.response.Data
public final void setQuery(Query query)
@Deprecated public String getFieldXML(String key)
@Deprecated public String getUnboldedField(String key, boolean escape)
public void setSearcherSpecificMetaData(Searcher searcher, Object data)
public Object getSearcherSpecificMetaData(Searcher searcher)
protected final void setFilledInternal(Set<String> filled)
filled
- the backing setprotected final Set<String> getFilledInternal()
@Deprecated public static String stripCharacter(char strip, String toStripFrom)
protected void close()
public boolean equals(Object object)
public int hashCode()
public int compareTo(Hit other)
compareTo
in interface Comparable<Hit>
public Hit clone()
clone
in class com.yahoo.component.provider.ListenableFreezableClass
Copyright © 2018. All rights reserved.