public class HitGroup extends Hit implements com.yahoo.processing.response.DataList<Hit>, Cloneable, Iterable<Hit>
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.
Modifier and Type | Field and Description |
---|---|
private com.google.common.util.concurrent.ListenableFuture<com.yahoo.processing.response.DataList<Hit>> |
completedFuture |
private int |
concreteHitCount
The current number of concrete (non-meta) hits in the result
|
private boolean |
deletionBreaksOrdering
Whether or not deletion of hits breaks the sorted ordering
|
private DefaultErrorHit |
errorHit
A direct reference to the errors of this result, or null if there are no errors.
|
private HitOrderer |
hitOrderer
The class used to determine the ordering of the hits of this
|
private com.yahoo.collections.ListenableArrayList<Hit> |
hits |
private boolean |
hitsSorted
Whether or not the hits are sorted
|
private com.yahoo.processing.response.IncomingData<Hit> |
incomingHits |
private int |
notCachedCount
The number of hits not cached at this level, not counting hits in subgroups or
any nested hitgroups themselves
|
private boolean |
orderedHits
Whether the hits should be sorted (again)
|
private int |
subgroupCount
Accounting the number of subgroups to allow some early returns when the number is 0
|
private List<Hit> |
unmodifiableHits |
RANKFEATURES_FIELD, SDDOCNAME_FIELD
Modifier | Constructor and Description |
---|---|
|
HitGroup()
Creates an invalid group of hits.
|
|
HitGroup(String id)
Creates a hit group with max relevancy (1)
|
|
HitGroup(String id,
double relevance)
Creates a hit group
|
|
HitGroup(String id,
Relevance relevance)
Creates a group hit
|
protected |
HitGroup(String id,
Relevance relevance,
com.yahoo.processing.response.IncomingData<Hit> incomingHits)
Creates a group hit
|
Modifier and Type | Method and Description |
---|---|
Hit |
add(Hit hit)
Adds a hit to this group.
|
void |
add(int index,
Hit hit)
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.
|
void |
addAll(List<Hit> hits)
Adds a list of hits to this group, the same
|
void |
addDataListener(Runnable runnable) |
void |
addError(ErrorMessage error)
Adds an error to this result
|
void |
analyze()
Update concreteHitCount, cached and filled by iterating trough the hits of this result.
|
private void |
analyzeHit(Hit hit) |
List<Hit> |
asList()
Returns a read only list view of the hits in this
|
List<Hit> |
asUnorderedHits()
Returns a read only list view of the hits in this which is potentially unsorted.
|
HitGroup |
clone() |
com.google.common.util.concurrent.ListenableFuture<com.yahoo.processing.response.DataList<Hit>> |
complete() |
private DefaultErrorHit |
consumeAnyQueryErrors()
Consumes errors from the query and returns them in a new error 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.
|
Iterator<Hit> |
deepIterator()
Returns an iterator that does depth-first traversal of leaf hits of this group.
|
private void |
ensureSorted()
Called before hit lists or positions are used
|
private Iterable<Hit> |
fillableHits() |
Hit |
get(int index)
Returns the hit at the given (0-base) index in this group of hit
(without searching any subgroups).
|
Hit |
get(String id)
Same as
get(String,int) |
Hit |
get(String id,
int depth) |
Hit |
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.
|
int |
getConcreteSize()
Returns the number of concrete hits contained in this group
and all subgroups.
|
int |
getConcreteSizeShallow()
Returns the number of concrete hits contained in this group,
without counting hits in subgroups.
|
boolean |
getDeletionBreaksOrdering() |
ErrorMessage |
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
|
ErrorHit |
getErrorHit()
Returns the error hit containing all error information, or null if no error has occurred
|
Set<String> |
getFilled()
Returns the set of summary classes for which this hit is
filled as an unmodifiable set.
|
private Set<String> |
getFilledSingle(String summaryName,
Iterator<Hit> hitIterator) |
HitOrderer |
getOrderer()
Returns the orderer used by this group, or null if the default relevancy order is used
|
int |
getSubgroupCount()
Returns the number of HitGroups present immediately in this list of hits.
|
private Set<String> |
getSummaryNamesNextFilledHit(Iterator<Hit> hitIterator) |
private void |
handleNewHit(Hit hit)
Ensures result invariants.
|
private void |
handleRemovedHit(Hit hit) |
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 instance
|
boolean |
isCached()
Returns true if all the hits recursively contained in this
is cached
|
boolean |
isFillable() |
boolean |
isFilled(String summaryClass)
Returns whether all hits in this result have been filled with
the properties contained in the given summary class.
|
Iterator<Hit> |
iterator()
Returns an iterator of the hits in this group.
|
private boolean |
likelyHitsHaveCorrectValueForSortFields() |
private DefaultErrorHit |
merge(DefaultErrorHit first,
DefaultErrorHit second)
Combines two error hits to one.
|
Hit |
remove(int index)
Removes a hit from this group (not considering the hits of any subgroup)
|
Hit |
remove(String uriString)
Removes a hit from this group or any subgroup
|
Hit |
remove(com.yahoo.net.URI uri)
Removes a hit from this group or any subgroup.
|
DefaultErrorHit |
removeErrorHit()
Removes the error hit of this.
|
void |
set(int index,
Hit hit)
Inserts the given hit at the specified index in this group.
|
void |
setDeletionBreaksOrdering(boolean flag) |
void |
setError(ErrorMessage error)
Deprecated.
prefer addError to add some error information.
|
void |
setFillable()
Tag this hit as fillable.
|
void |
setFilled(String summaryClass)
Ignored as this should always be derived from the content hits
|
void |
setId(String id)
Calls setId(new URI(id))
|
void |
setId(com.yahoo.net.URI id)
Assign an id to this hit.
|
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.
|
private ErrorMessage |
toSearchError(com.yahoo.processing.request.ErrorMessage error)
Compatibility
|
void |
trim(int offset,
int numHits)
Remove the first
offset concrete hits in this group,
and hits beyond offset+numHits |
Iterator<Hit> |
unorderedDeepIterator()
Returns an iterator that does depth-first traversal of leaf hits of this group, in a potentially unsorted order.
|
Iterator<Hit> |
unorderedIterator()
Returns an iterator of the hits in this group in a potentially unsorted order.
|
private void |
updateHits()
Must be called before the list of hits, or anything dependent on the list of hits, is removed.
|
assignId, buildHitField, buildHitField, buildHitField, changeFieldKey, clearFields, compareTo, equals, fieldIterator, fieldKeys, fields, getAddNumber, getDisplayId, getField, getFieldXML, getFilledInternal, getId, getQuery, getRelevance, getSearcherSpecificMetaData, getSource, getSourceNumber, getTypeString, getUnboldedField, hashCode, isAuxiliary, isMeta, removeField, request, reserve, setAddNumber, setAuxiliary, setCached, setField, setFilledInternal, setMeta, setQuery, setRelevance, setRelevance, setSearcherSpecificMetaData, setSource, setSourceNumber, stripCharacter, toString, types
addFreezeListener, freeze
finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
private com.yahoo.collections.ListenableArrayList<Hit> hits
private boolean hitsSorted
private boolean deletionBreaksOrdering
private boolean orderedHits
private int concreteHitCount
private transient HitOrderer hitOrderer
private int subgroupCount
private int notCachedCount
private DefaultErrorHit errorHit
private final com.google.common.util.concurrent.ListenableFuture<com.yahoo.processing.response.DataList<Hit>> completedFuture
private final com.yahoo.processing.response.IncomingData<Hit> incomingHits
public HitGroup()
public HitGroup(String id)
id
- the id of this hit - any string, it is convenient to make this unique in the result containing thispublic HitGroup(String id, double relevance)
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 1public HitGroup(String id, Relevance relevance)
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 hitsprotected HitGroup(String id, Relevance relevance, com.yahoo.processing.response.IncomingData<Hit> incomingHits)
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 asynchronouslypublic static HitGroup createAsync(String id)
id
- the id of thisincoming()
where new hits can be added laterpublic void setId(com.yahoo.net.URI id)
public void setOrdered(boolean ordered)
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.public int size()
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.
public int getConcreteSizeShallow()
Returns the number of concrete hits contained in this group, without counting hits in subgroups.
public int getSubgroupCount()
public Hit add(Hit hit)
add
in interface com.yahoo.processing.response.DataList<Hit>
public Hit get(int index)
get
in interface com.yahoo.processing.response.DataList<Hit>
index
- the index into this listIndexOutOfBoundsException
- if there is no hit at the given indexpublic Hit get(String id)
get(String,int)
public Hit get(com.yahoo.net.URI id, int depth)
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.public void set(int index, Hit hit)
public void add(int index, Hit hit)
public Hit remove(String uriString)
uriString
- the uri of the hit to removepublic Hit remove(com.yahoo.net.URI uri)
uri
- the uri of the hit to remove.public Hit remove(int index)
index
- the position of the hit to removeIndexOutOfBoundsException
- if there is no hit at the given position@Deprecated public void setError(ErrorMessage error)
public void addError(ErrorMessage error)
public ErrorHit getErrorHit()
public DefaultErrorHit removeErrorHit()
public ErrorMessage getError()
private DefaultErrorHit merge(DefaultErrorHit first, DefaultErrorHit second)
private void updateHits()
private DefaultErrorHit consumeAnyQueryErrors()
private ErrorMessage toSearchError(com.yahoo.processing.request.ErrorMessage error)
public void trim(int offset, int numHits)
offset
concrete hits in this group,
and hits beyond offset+numHits
public Iterator<Hit> iterator()
This iterator is modifiable - removals will take effect in this group of hits.
public Iterator<Hit> deepIterator()
public Iterator<Hit> unorderedDeepIterator()
deepIterator()
, this method has no side-effect.public List<Hit> asList()
asList
in interface com.yahoo.processing.response.DataList<Hit>
public List<Hit> asUnorderedHits()
public Iterator<Hit> unorderedIterator()
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.
public void sort()
private boolean likelyHitsHaveCorrectValueForSortFields()
public void setOrderer(HitOrderer hitOrderer)
Sets the hit orderer for this group.
hitOrderer
- the new hit orderer, or null to use default relevancy orderingpublic void setSorted(boolean sorted)
public HitOrderer getOrderer()
public void setDeletionBreaksOrdering(boolean flag)
public boolean getDeletionBreaksOrdering()
private void ensureSorted()
public boolean isCached()
public boolean isFilled(String summaryClass)
public void copyOrdering(HitGroup hitGroup)
private void handleNewHit(Hit hit)
private void handleRemovedHit(Hit hit)
private void analyzeHit(Hit hit)
public void analyze()
public void setFillable()
Hit
setFillable
in class Hit
public void setFilled(String summaryClass)
public boolean isFillable()
isFillable
in class Hit
public Set<String> getFilled()
Hit
private Set<String> getSummaryNamesNextFilledHit(Iterator<Hit> hitIterator)
public com.yahoo.processing.response.IncomingData<Hit> incoming()
incoming
in interface com.yahoo.processing.response.DataList<Hit>
public com.google.common.util.concurrent.ListenableFuture<com.yahoo.processing.response.DataList<Hit>> complete()
complete
in interface com.yahoo.processing.response.DataList<Hit>
Copyright © 2017. All rights reserved.