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 ofReductionDataCollectors which will be updated together.The manager assumes a non-distributed request.
MergingReductionCollectionManageris used for distributed requests.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classReductionCollectionManager.ReductionDataCollectionHolds the collection ofReductionDatathat 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 givenReductionDataCollectors.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCollectTarget(ReductionCollectionManager.ReductionDataCollection target)Add aReductionCollectionManager.ReductionDataCollectionto target while collecting the next document.voidaddLastingCollectTarget(ReductionCollectionManager.ReductionDataCollection target)Add aReductionCollectionManager.ReductionDataCollectionto target while collecting documents.voidapply()Apply the values of the collected fields through the expressions' logic to the managed data collectors.voidclearLastingCollectTargets()Clear lasting collection targets.voidcollect(int doc)Collect the values from the usedAnalyticsFields.protected ReductionCollectionManagercreateNewManager(ReductionDataCollector<?>[] reductionDataCollectors, Iterable<AnalyticsField> fields)Create anReductionCollectionManagerto manage the given collectors and fields.voiddoSetNextReader(org.apache.lucene.index.LeafReaderContext context)Set the context of the readers of the usedAnalyticsFields.voidexportData()Export the data from the set IO data collectors to the given shard output stream.Iterable<AnalyticsField>getUsedFields()Get theAnalyticsFields used in the managed expressions.ReductionCollectionManagermerge(Iterable<ReductionCollectionManager> reductionManagers)Merge this collection manager with others.voidmergeData()Merge the data from the given shard input stream into the set IO data collectors.booleanneedsCollection()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.ReductionDataCollectionnewDataCollection()Construct a new data collection holding data for all managed data collectors.ReductionCollectionManager.ReductionDataCollectionnewDataCollectionIO()Create a newReductionCollectionManager.ReductionDataCollectionto merge to or export from.ReductionCollectionManager.ReductionDataCollectionnewDataCollectionTarget()Add a newReductionCollectionManager.ReductionDataCollectionto target while collecting the next document.voidprepareReductionDataIO(ReductionCollectionManager.ReductionDataCollection col)Set the given data collection to be used for either merging or exportingvoidsetData(ReductionCollectionManager.ReductionDataCollection dataCollection)Finalize the reductions with the collected data stored in the parameter.voidsetShardInput(DataInput input)Sets the stream of shard data to merge with.voidsetShardOutput(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 givenReductionDataCollectors.- 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 anReductionCollectionManagerto 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 theAnalyticsFields used in the managed expressions.- Returns:
- the fields used
-
doSetNextReader
public void doSetNextReader(org.apache.lucene.index.LeafReaderContext context) throws IOExceptionSet the context of the readers of the usedAnalyticsFields.- Parameters:
context- the reader context- Throws:
IOException- if an error occurs while setting the fields' context
-
collect
public void collect(int doc) throws IOExceptionCollect the values from the usedAnalyticsFields.- 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.ReductionDataCollectionto 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.ReductionDataCollectionto 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.ReductionDataCollectionto 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, theReductionFunctions that use theseReductionDataCollectors act like regularAnalyticsValueclasses 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 IOExceptionMerge 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 IOExceptionExport 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.ReductionDataCollectionto merge to or export from. Mainly used for creating facet value collectors when merging shard data.- Returns:
- the new data collection created
-
-