Class ReductionCollectionManager
- java.lang.Object
-
- org.apache.solr.analytics.function.ReductionCollectionManager
-
- Direct Known Subclasses:
MergingReductionCollectionManager
public class ReductionCollectionManager extends Object
The manager of reduction collection. Contains a group ofReductionDataCollector
s which will be updated together.The manager assumes a non-distributed request.
MergingReductionCollectionManager
is used for distributed requests.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ReductionCollectionManager.ReductionDataCollection
Holds the collection ofReductionData
that will be updated together.
-
Field Summary
Fields Modifier and Type Field Description protected ReductionDataCollector<?>[]
reductionDataCollectors
-
Constructor Summary
Constructors Constructor Description ReductionCollectionManager()
ReductionCollectionManager(ReductionDataCollector<?>[] reductionDataCollectors, Iterable<AnalyticsField> fields)
Create a Manager to oversee the givenReductionDataCollector
s.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCollectTarget(ReductionCollectionManager.ReductionDataCollection target)
Add aReductionCollectionManager.ReductionDataCollection
to target while collecting the next document.void
addLastingCollectTarget(ReductionCollectionManager.ReductionDataCollection target)
Add aReductionCollectionManager.ReductionDataCollection
to target while collecting documents.void
apply()
Apply the values of the collected fields through the expressions' logic to the managed data collectors.void
clearLastingCollectTargets()
Clear lasting collection targets.void
collect(int doc)
Collect the values from the usedAnalyticsField
s.protected ReductionCollectionManager
createNewManager(ReductionDataCollector<?>[] reductionDataCollectors, Iterable<AnalyticsField> fields)
Create anReductionCollectionManager
to manage the given collectors and fields.void
doSetNextReader(org.apache.lucene.index.LeafReaderContext context)
Set the context of the readers of the usedAnalyticsField
s.void
exportData()
Export the data from the set IO data collectors to the given shard output stream.Iterable<AnalyticsField>
getUsedFields()
Get theAnalyticsField
s used in the managed expressions.ReductionCollectionManager
merge(Iterable<ReductionCollectionManager> reductionManagers)
Merge this collection manager with others.void
mergeData()
Merge the data from the given shard input stream into the set IO data collectors.boolean
needsCollection()
Return whether or not the manager needs collection done, which is false if no collectors are being managed and true if at least one is.ReductionCollectionManager.ReductionDataCollection
newDataCollection()
Construct a new data collection holding data for all managed data collectors.ReductionCollectionManager.ReductionDataCollection
newDataCollectionIO()
Create a newReductionCollectionManager.ReductionDataCollection
to merge to or export from.ReductionCollectionManager.ReductionDataCollection
newDataCollectionTarget()
Add a newReductionCollectionManager.ReductionDataCollection
to target while collecting the next document.void
prepareReductionDataIO(ReductionCollectionManager.ReductionDataCollection col)
Set the given data collection to be used for either merging or exportingvoid
setData(ReductionCollectionManager.ReductionDataCollection dataCollection)
Finalize the reductions with the collected data stored in the parameter.void
setShardInput(DataInput input)
Sets the stream of shard data to merge with.void
setShardOutput(DataOutput output)
Sets the stream to export shard data to.
-
-
-
Field Detail
-
reductionDataCollectors
protected final ReductionDataCollector<?>[] reductionDataCollectors
-
-
Constructor Detail
-
ReductionCollectionManager
public ReductionCollectionManager()
-
ReductionCollectionManager
public ReductionCollectionManager(ReductionDataCollector<?>[] reductionDataCollectors, Iterable<AnalyticsField> fields)
Create a Manager to oversee the givenReductionDataCollector
s.- Parameters:
reductionDataCollectors
- array of collectors that are collecting over the same set of datafields
- all fields used by the given collectors
-
-
Method Detail
-
needsCollection
public boolean needsCollection()
Return whether or not the manager needs collection done, which is false if no collectors are being managed and true if at least one is.- Returns:
- true if at least one collector is being managed
-
merge
public ReductionCollectionManager merge(Iterable<ReductionCollectionManager> reductionManagers)
Merge this collection manager with others.- Parameters:
reductionManagers
- the collection managers to merge with- Returns:
- a collection manager that manages the union of data collectors from this class and the given managers
-
createNewManager
protected ReductionCollectionManager createNewManager(ReductionDataCollector<?>[] reductionDataCollectors, Iterable<AnalyticsField> fields)
Create anReductionCollectionManager
to manage the given collectors and fields.- Parameters:
reductionDataCollectors
- Reduction collectorsfields
- fields used by the reductions- Returns:
- a collection manager
-
getUsedFields
public Iterable<AnalyticsField> getUsedFields()
Get theAnalyticsField
s used in the managed expressions.- Returns:
- the fields used
-
doSetNextReader
public void doSetNextReader(org.apache.lucene.index.LeafReaderContext context) throws IOException
Set the context of the readers of the usedAnalyticsField
s.- Parameters:
context
- the reader context- Throws:
IOException
- if an error occurs while setting the fields' context
-
collect
public void collect(int doc) throws IOException
Collect the values from the usedAnalyticsField
s.- Parameters:
doc
- the document to collect values for- Throws:
IOException
- if an error occurs during field collection
-
addLastingCollectTarget
public void addLastingCollectTarget(ReductionCollectionManager.ReductionDataCollection target)
Add aReductionCollectionManager.ReductionDataCollection
to target while collecting documents. This target is valid until the lasting targets are cleared.- Parameters:
target
- data collection to add document data too
-
clearLastingCollectTargets
public void clearLastingCollectTargets()
Clear lasting collection targets.
-
newDataCollectionTarget
public ReductionCollectionManager.ReductionDataCollection newDataCollectionTarget()
Add a newReductionCollectionManager.ReductionDataCollection
to target while collecting the next document. This target is only valid for the nextapply()
call.- Returns:
- the new data collection being targeted
-
addCollectTarget
public void addCollectTarget(ReductionCollectionManager.ReductionDataCollection target)
Add aReductionCollectionManager.ReductionDataCollection
to target while collecting the next document. This target is only valid for the nextapply()
call.- Parameters:
target
- data collection to add document data too
-
apply
public void apply()
Apply the values of the collected fields through the expressions' logic to the managed data collectors. This is called aftercollect(int)
has been called and the collection targets have been added.
-
setData
public void setData(ReductionCollectionManager.ReductionDataCollection dataCollection)
Finalize the reductions with the collected data stored in the parameter. Once the data is finalized, theReductionFunction
s that use theseReductionDataCollector
s act like regularAnalyticsValue
classes that can be accessed through theirget<value-type>
methods.- Parameters:
dataCollection
- the collection of reduction data to compute results for
-
newDataCollection
public ReductionCollectionManager.ReductionDataCollection newDataCollection()
Construct a new data collection holding data for all managed data collectors.- Returns:
- a new data collection
-
setShardInput
public void setShardInput(DataInput input)
Sets the stream of shard data to merge with.- Parameters:
input
- the stream of shard data
-
mergeData
public void mergeData() throws IOException
Merge the data from the given shard input stream into the set IO data collectors. Should always be called aftersetShardInput(DataInput)
and eitherprepareReductionDataIO(ReductionDataCollection)
ornewDataCollectionIO()
have been called.- Throws:
IOException
- if an error occurs while reading the shard data
-
setShardOutput
public void setShardOutput(DataOutput output)
Sets the stream to export shard data to.- Parameters:
output
- the stream of shard data
-
exportData
public void exportData() throws IOException
Export the data from the set IO data collectors to the given shard output stream. Should always be called aftersetShardOutput(DataOutput)
andprepareReductionDataIO(ReductionDataCollection)
.- Throws:
IOException
- if an error occurs while writing the shard data
-
prepareReductionDataIO
public void prepareReductionDataIO(ReductionCollectionManager.ReductionDataCollection col)
Set the given data collection to be used for either merging or exporting- Parameters:
col
- collection to export from or merge to
-
newDataCollectionIO
public ReductionCollectionManager.ReductionDataCollection newDataCollectionIO()
Create a newReductionCollectionManager.ReductionDataCollection
to merge to or export from. Mainly used for creating facet value collectors when merging shard data.- Returns:
- the new data collection created
-
-