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 | Field and Description |
---|---|
private int |
addNumber
Add number, assigned when adding the hit to a result,
used to order equal relevant hit by add order
|
private boolean |
auxiliary
If this is true, then this hit will not be counted as a concrete hit
|
private boolean |
cached
Says whether this hit is cached
|
private static String |
DOCUMENT_ID |
private Map<String,Object> |
fields
A collection of string keyed object properties.
|
private Set<String> |
filled
The summary classes for which this hit is filled.
|
private com.yahoo.net.URI |
id
The id of this hit
|
private boolean |
meta
Set to true for hits which does not contain content,
but which contains meta information about the query or result
|
private Query |
query
The query which produced this hit.
|
static String |
RANKFEATURES_FIELD
The hit field used to store rank features.
|
private Relevance |
relevance
The relevance of this hit
|
static String |
SDDOCNAME_FIELD |
private Map<Searcher,Object> |
searcherSpecificMetaData
Meta data describing how a given searcher should treat this hit.
|
private String |
source
The name of the source creating this hit
|
private int |
sourceNumber |
private Set<String> |
types
The types of this hit
|
private Map<String,Object> |
unmodifiableFieldMap |
private Set<String> |
unmodifiableFilled |
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)
Deprecated.
do not use
|
HitField |
buildHitField(String key,
boolean forceNoPreTokenize)
Deprecated.
do not use
|
HitField |
buildHitField(String key,
boolean forceNoPreTokenize,
boolean forceStringHandling) |
void |
changeFieldKey(String oldKey,
String newKey)
Changes the key under which a value is found.
|
void |
clearFields()
Removes all fields from this
|
Hit |
clone() |
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()
Fields
|
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.
|
int |
getAddNumber()
Returns the add number, assigned when adding the hit to a Result.
|
String |
getDisplayId()
Returns the id to display, or null to not display (render) the id.
|
Object |
getField(String value)
Returns a field value
|
private Map<String,Object> |
getFieldMap() |
private Map<String,Object> |
getFieldMap(int minSize) |
String |
getFieldXML(String key)
Returns a field of this hit XML escaped and without token
delimiters.
|
Set<String> |
getFilled()
Returns the set of summary classes for which this hit is
filled as an unmodifiable set.
|
protected Set<String> |
getFilledInternal()
For vespa 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)
get meta data describing how a given searcher should treat this hit.
|
String |
getSource()
Returns the name of the source creating this hit
|
int |
getSourceNumber() |
String |
getTypeString()
Returns all types of this hit as a space-separated string
|
String |
getUnboldedField(String key,
boolean escape)
Deprecated.
do not use
|
private Map<String,Object> |
getUnmodifiableFieldMap() |
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() |
void |
reserve(int minSize)
Will preallocate in order to avoid resizing.
|
void |
setAddNumber(int addNumber)
Sets the add number, assigned when adding the hit to a Result,
used to order equal relevant hit by add order
|
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)
For vespa internal use only.
|
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) |
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)
Set meta data describing how a given searcher should treat this hit.
|
void |
setSource(String source)
Sets the name of the source creating this hit
|
void |
setSourceNumber(int number) |
static String |
stripCharacter(char strip,
String toStripFrom) |
String |
toString()
Returns a string describing this hit
|
Set<String> |
types()
Returns the types of this as a modifiable set.
|
addFreezeListener, freeze
private static final String DOCUMENT_ID
private Map<Searcher,Object> searcherSpecificMetaData
private com.yahoo.net.URI id
private Relevance relevance
private boolean cached
private Set<String> filled
private String source
private int addNumber
private int sourceNumber
private Query query
private boolean meta
private boolean auxiliary
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)
relevance
- the relevance of this hitpublic 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 final Map<String,Object> fields()
public void reserve(int minSize)
minSize
- public final Iterator<Map.Entry<String,Object>> fieldIterator()
@Deprecated public HitField buildHitField(String key)
@Deprecated public HitField buildHitField(String key, boolean forceNoPreTokenize)
public HitField buildHitField(String key, boolean forceNoPreTokenize, boolean forceStringHandling)
public Object setField(String key, Object value)
public Set<String> types()
public String getTypeString()
public boolean equals(Object object)
public int hashCode()
public int compareTo(Hit other)
compareTo
in interface Comparable<Hit>
public int getAddNumber()
public void setAddNumber(int addNumber)
public boolean isMeta()
public void setMeta(boolean meta)
public boolean isAuxiliary()
public void setAuxiliary(boolean auxiliary)
public void clearFields()
public Set<String> fieldKeys()
public void changeFieldKey(String oldKey, String newKey)
public String toString()
public Hit clone()
clone
in class com.yahoo.component.provider.ListenableFreezableClass
public int getSourceNumber()
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)
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()
Copyright © 2017. All rights reserved.