Class HitGroup
- All Implemented Interfaces:
com.yahoo.component.provider.Freezable
,com.yahoo.component.provider.ListenableFreezable
,com.yahoo.processing.response.Data
,com.yahoo.processing.response.DataList<Hit>
,Cloneable
,Comparable<Hit>
,Iterable<Hit>
- Direct Known Subclasses:
AbstractList
,Group
,SectionHitGroup
A group of ordered hits. Since hitGroup is itself a kind of Hit, this can compose hierarchies of grouped hits.
Group hits has a relevancy just as other hits - they can be ordered between each other and in comparison to other hits.
Note that a group is by default a meta hit, but it can also contain its own content in addition to subgroup content, in which case it should be set to non-meta.
- Author:
- bratseth
-
Nested Class Summary
Nested classes/interfaces inherited from class com.yahoo.search.result.Hit
Hit.RawUtf8Consumer
-
Field Summary
Fields inherited from class com.yahoo.search.result.Hit
RANKFEATURES_FIELD, SDDOCNAME_FIELD
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a hit to this group in the specified index, all existing hits on this index and higher will have their index increased by one.Adds a hit to this group.void
Adds a list of hits to this group, the same as calling add for each item in the list.void
addDataListener
(Runnable runnable) void
addError
(ErrorMessage error) Adds an error to this resultvoid
addErrorsFrom
(HitGroup other) merge any errors from the other HitGroup into thisvoid
analyze()
Update concreteHitCount, cached and filled by iterating trough the hits of this result.asList()
Returns a read only list view of the hits in thisReturns a read only list view of the hits in this which is potentially unsorted.clone()
void
close()
Releases the resources held by this, making it irreversibly unusableCompletableFuture<com.yahoo.processing.response.DataList<Hit>>
void
copyOrdering
(HitGroup hitGroup) Sets sorting information to be the same as for the provided hitGroup.static HitGroup
createAsync
(String id) Creates a HitGroup which contains data which arrives in the future.Returns an iterator that does depth-first traversal of leaf hits of this group.void
ensureCapacity
(int minCapacity) get
(int index) Returns the hit at the given (0-base) index in this group of hit (without searching any subgroups).get
(com.yahoo.net.URI id, int depth) Returns the hit with the given id, or null if there is no hit with this id in this group or any subgroup.Same asget(String,int)
int
Returns the number of concrete hits contained in this group and all subgroups.int
Returns the number of concrete hits contained in this group, without counting hits in subgroups.boolean
getError()
Returns the first error in this result, or null if no searcher has produced an error AND the query doesn't contain an errorReturns the error hit containing all error information, or null if no error has occurredReturns the set of summaries for which all concrete hits recursively below this is filled.Returns the orderer used by this group, or null if the default relevancy order is usedint
Returns the number of HitGroups present immediately in this list of hits.com.yahoo.processing.response.IncomingData<Hit>
incoming()
Returns the incoming hit buffer to which new hits can be added to this asynchronous, if supported by the instanceboolean
isCached()
Returns true if all the hits recursively contained in this is cachedboolean
boolean
Returns whether all hits in this result have been filled with the properties contained in the given summary class.iterator()
Returns an iterator of the hits in this group.remove
(int index) Removes a hit from this group (not considering the hits of any subgroup)remove
(com.yahoo.net.URI uri) Removes a hit from this group or any subgroup.Removes a hit from this group or any subgroupRemoves the error hit of this.void
Inserts the given hit at the specified index in this group.void
setDeletionBreaksOrdering
(boolean flag) void
Tag this hit as fillable.void
Ignored as this should always be derived from the content hitsvoid
setId
(com.yahoo.net.URI id) Assign an id to this hit.void
Calls setId(new URI(id))void
setOrdered
(boolean ordered) Turn off internal resorting of hits.void
setOrderer
(HitOrderer hitOrderer) Sets the hit orderer for this group.void
setSorted
(boolean sorted) Explicitly set whether the hits in this group are correctly sorted at this moment.int
size()
Returns the number of hits available immediately in this group (counting a subgroup as one hit).void
sort()
Force hit sorting now.void
trim
(int offset, int numHits) Remove the firstoffset
concrete hits in this group, and hits beyondoffset+numHits
Returns an iterator that does depth-first traversal of leaf hits of this group, in a potentially unsorted order.Returns an iterator of the hits in this group in a potentially unsorted order.Methods inherited from class com.yahoo.search.result.Hit
assignId, buildHitField, clearFields, compareTo, equals, features, fieldIterator, fieldKeys, fields, forEachField, forEachFieldAsRaw, getDisplayId, getField, getId, getQuery, getRelevance, getSearcherSpecificMetaData, getSource, hasField, hasFields, hashCode, isAuxiliary, isMeta, removeField, request, reserve, setAuxiliary, setCached, setField, setMeta, setQuery, setRelevance, setRelevance, setSearcherSpecificMetaData, setSource, toString, types
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.processing.response.Data
request
Methods inherited from interface com.yahoo.component.provider.Freezable
freeze, isFrozen
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface com.yahoo.component.provider.ListenableFreezable
addFreezeListener
-
Constructor Details
-
HitGroup
public HitGroup()Creates an invalid group of hits. Id must be set before handoff. -
HitGroup
Creates a hit group with max relevancy (1)- Parameters:
id
- the id of this hit - any string, it is convenient to make this unique in the result containing this
-
HitGroup
Creates a hit group- Parameters:
id
- the id of this hit - any string, it is convenient to make this unique in the result containing thisrelevance
- the relevance of this group of hits, preferably a number between 0 and 1
-
HitGroup
Creates a group hit- Parameters:
id
- the id of this hit - any string, it is convenient to make this unique in the result containing thisrelevance
- the relevancy of this group of hits
-
HitGroup
protected HitGroup(String id, Relevance relevance, com.yahoo.processing.response.IncomingData<Hit> incomingHits) Creates a group hit- Parameters:
id
- the id of this hit - any string, it is convenient to make this unique in the result containing thisrelevance
- the relevancy of this group of hitsincomingHits
- the incoming buffer to which new hits can be added asynchronously
-
-
Method Details
-
createAsync
Creates a HitGroup which contains data which arrives in the future.- Parameters:
id
- the id of this- Returns:
- a HitGroup which is incomplete and which has an
incoming()
where new hits can be added later
-
setId
Calls setId(new URI(id)) -
setId
public void setId(com.yahoo.net.URI id) Assign an id to this hit. For HitGroups, this is a legal call also when an id is already set, i.e hit groups allows their ids to be reassigned. This is to allow hit groups to be inserted in new structures with an id reflecting their role/placement in the structure. -
setOrdered
public void setOrdered(boolean ordered) Turn off internal resorting of hits.- Parameters:
ordered
- set to true to tell this group that the hits set in it is already correctly ordered and should never be resorted. Set to false to use the default lazy resorting by hit ordering.
-
size
public int size()Returns the number of hits available immediately in this group (counting a subgroup as one hit). -
ensureCapacity
public void ensureCapacity(int minCapacity) -
getConcreteSize
public int getConcreteSize()Returns the number of concrete hits contained in this group and all subgroups. This should equal the requested hits count if the query has that many matches.
-
getConcreteSizeShallow
public int getConcreteSizeShallow()Returns the number of concrete hits contained in this group, without counting hits in subgroups.
-
getSubgroupCount
public int getSubgroupCount()Returns the number of HitGroups present immediately in this list of hits. -
add
Adds a hit to this group. If the given hit is an ErrorHit and this group already have an error hit, the errors in the given hit are merged into the errors of this.- Specified by:
add
in interfacecom.yahoo.processing.response.DataList<Hit>
- Returns:
- the resulting hit - this is usually the input hit, but if an error hit was added, and there was already an error hit present, that hit, containing the merged information is returned
-
addAll
Adds a list of hits to this group, the same as calling add for each item in the list. -
get
Returns the hit at the given (0-base) index in this group of hit (without searching any subgroups).- Specified by:
get
in interfacecom.yahoo.processing.response.DataList<Hit>
- Parameters:
index
- the index into this list- Throws:
IndexOutOfBoundsException
- if there is no hit at the given index
-
get
Same asget(String,int)
-
get
-
get
Returns the hit with the given id, or null if there is no hit with this id in this group or any subgroup. This method is o(min(number of nested hits in this result, depth)).- Parameters:
id
- the id of the hit to return from this or any nested groupdepth
- the max depth to recurse into nested groups: -1: Recurse infinitely deep, 0: Only look at hits in the list of this group, 1: Look at hits in this group, and the hits of any immediate nested HitGroups, etc.- Returns:
- the hit, or null if not found
-
set
Inserts the given hit at the specified index in this group. -
add
Adds a hit to this group in the specified index, all existing hits on this index and higher will have their index increased by one. Note: If the group was sorted, it will still be considered sorted after this call. -
remove
Removes a hit from this group or any subgroup- Parameters:
uriString
- the uri of the hit to remove- Returns:
- the hit to remove, or null if the hit was not present
-
remove
Removes a hit from this group or any subgroup.- Parameters:
uri
- the uri of the hit to remove.- Returns:
- the hit removed, or null if not found.
-
remove
Removes a hit from this group (not considering the hits of any subgroup)- Parameters:
index
- the position of the hit to remove- Returns:
- the hit removed
- Throws:
IndexOutOfBoundsException
- if there is no hit at the given position
-
addError
Adds an error to this result -
addErrorsFrom
merge any errors from the other HitGroup into this -
getErrorHit
Returns the error hit containing all error information, or null if no error has occurred -
removeErrorHit
Removes the error hit of this. This removes all error messages of this and the query producing it.- Returns:
- the error hit which was removed, or null if there were no errors
-
getError
Returns the first error in this result, or null if no searcher has produced an error AND the query doesn't contain an error -
trim
public void trim(int offset, int numHits) Remove the firstoffset
concrete hits in this group, and hits beyondoffset+numHits
-
iterator
Returns an iterator of the hits in this group.This iterator is modifiable - removals will take effect in this group of hits.
-
deepIterator
Returns an iterator that does depth-first traversal of leaf hits of this group. Calling this method has the side-effect of sorting the internal list of hits.- Returns:
- A modifiable iterator.
-
unorderedDeepIterator
Returns an iterator that does depth-first traversal of leaf hits of this group, in a potentially unsorted order. As opposed todeepIterator()
, this method has no side-effect.- Returns:
- A modifiable iterator.
-
asList
Returns a read only list view of the hits in this- Specified by:
asList
in interfacecom.yahoo.processing.response.DataList<Hit>
-
asUnorderedHits
Returns a read only list view of the hits in this which is potentially unsorted. Using this over getHits is potentially faster when a sorted view is not needed. -
unorderedIterator
Returns an iterator of the hits in this group in a potentially unsorted order.Using this over getPreludeHitIterator is potentially faster when a sorted view is not needed.
This iterator is modifiable - removals will take effect in this group of hits.
-
sort
public void sort()Force hit sorting now. This is not normally useful because a group will stay sorted automatically, but it is in the case where the hits have changed their internal state in a way that should change ordering -
setOrderer
Sets the hit orderer for this group.- Parameters:
hitOrderer
- the new hit orderer, or null to use default relevancy ordering
-
setSorted
public void setSorted(boolean sorted) Explicitly set whether the hits in this group are correctly sorted at this moment. If the contained hits are modified directly in a way that may break ordering, you should call setSorted(false). -
getOrderer
Returns the orderer used by this group, or null if the default relevancy order is used -
setDeletionBreaksOrdering
public void setDeletionBreaksOrdering(boolean flag) -
getDeletionBreaksOrdering
public boolean getDeletionBreaksOrdering() -
isCached
public boolean isCached()Returns true if all the hits recursively contained in this is cached -
isFilled
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. -
copyOrdering
Sets sorting information to be the same as for the provided hitGroup. The contained hits should already be sorted in the order specified by the hitGroup given as argument. -
analyze
public void analyze()Update concreteHitCount, cached and filled by iterating trough the hits of this result. Recursively also update all subgroups. -
clone
-
setFillable
public void setFillable()Description copied from class:Hit
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.- Overrides:
setFillable
in classHit
-
setFilled
Ignored as this should always be derived from the content hits -
isFillable
public boolean isFillable()- Overrides:
isFillable
in classHit
-
getFilled
Returns the set of summaries for which all concrete hits recursively below this is filled. -
incoming
Returns the incoming hit buffer to which new hits can be added to this asynchronous, if supported by the instance- Specified by:
incoming
in interfacecom.yahoo.processing.response.DataList<Hit>
-
completeFuture
- Specified by:
completeFuture
in interfacecom.yahoo.processing.response.DataList<Hit>
-
addDataListener
- Specified by:
addDataListener
in interfacecom.yahoo.processing.response.DataList<Hit>
-
close
public void close()Description copied from class:Hit
Releases the resources held by this, making it irreversibly unusable
-