Class CountFacetRecorder
- java.lang.Object
-
- org.apache.lucene.sandbox.facet.recorders.CountFacetRecorder
-
- All Implemented Interfaces:
FacetRecorder
public final class CountFacetRecorder extends Object implements FacetRecorder
FacetRecorderto count facets.TODO: add an option to keep counts in an array, to improve performance for facets with small number of ordinals e.g. range facets. Options: -
LeafFacetCuttercan informLeafFacetRecorderabout expected number of facet ordinals (FacetFieldCollectorcan orchestrate that). If expeted facet ord number is below some threshold - use array instead of a map? - first 100/1k counts in array, the rest - in a map; the limit can also be provided in a constructor? It is similar to what LongValuesFacetCounts does today.TODO: We can also consider collecting 2 (3, 4, ..., can be parametrizes) slices to a single sync map which can reduce thread contention compared to single sync map for all slices; at the same time there will be less work for reduce method. So far reduce wasn't a bottleneck for us, but it is definitely not free.
TODO: If we come back to some for of synchronized count maps, we should be more careful what we acquire locks for - we used to lock addTo method itself, but it could be faster if we only synchronized after computing the key's hash; or we can lock the entire map only if we need to insert key, and lock single key otherwise?
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
-
Constructor Summary
Constructors Constructor Description CountFacetRecorder()Create.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(int ordinal)Check if any data was recorded for provided facet ordinal.intgetCount(int ord)Get count for provided ordinal.LeafFacetRecordergetLeafRecorder(LeafReaderContext context)Get leaf recorder.booleanisEmpty()True if there are no recordsOrdinalIteratorrecordedOrds()Return next collected ordinal, orOrdinalIterator.NO_MORE_ORDSvoidreduce(FacetCutter facetCutter)Reduce leaf recorder results into this recorder.
-
-
-
Method Detail
-
getCount
public int getCount(int ord)
Get count for provided ordinal.
-
getLeafRecorder
public LeafFacetRecorder getLeafRecorder(LeafReaderContext context)
Description copied from interface:FacetRecorderGet leaf recorder.- Specified by:
getLeafRecorderin interfaceFacetRecorder
-
recordedOrds
public OrdinalIterator recordedOrds()
Description copied from interface:FacetRecorderReturn next collected ordinal, orOrdinalIterator.NO_MORE_ORDS- Specified by:
recordedOrdsin interfaceFacetRecorder
-
isEmpty
public boolean isEmpty()
Description copied from interface:FacetRecorderTrue if there are no records- Specified by:
isEmptyin interfaceFacetRecorder
-
reduce
public void reduce(FacetCutter facetCutter) throws IOException
Description copied from interface:FacetRecorderReduce leaf recorder results into this recorder. IfFacetCutter.getOrdinalsToRollup()result is not null, it also rolls up values.After this method is called, it's illegal to add values to recorder, i.e. calling
FacetRecorder.getLeafRecorder(org.apache.lucene.index.LeafReaderContext)orLeafFacetRecorder.record(int, int)on its leaf recorders.- Specified by:
reducein interfaceFacetRecorder- Throws:
IOException
-
contains
public boolean contains(int ordinal)
Description copied from interface:FacetRecorderCheck if any data was recorded for provided facet ordinal.- Specified by:
containsin interfaceFacetRecorder
-
-