don't use cache for ordinals for small max ord

This commit is contained in:
Shay Banon 2013-03-07 08:45:01 -08:00
parent 59ea426bf2
commit c298c19177
2 changed files with 20 additions and 7 deletions

View File

@ -53,10 +53,13 @@ import java.util.regex.Pattern;
*/
public class TermsFacetParser extends AbstractComponent implements FacetParser {
private final int ordinalsCacheAbove;
@Inject
public TermsFacetParser(Settings settings) {
super(settings);
InternalTermsFacet.registerStreams();
this.ordinalsCacheAbove = componentSettings.getAsInt("ordinals_cache_above", 10000); // above 40k we want to cache
}
@Override
@ -176,7 +179,7 @@ public class TermsFacetParser extends AbstractComponent implements FacetParser {
if (script != null || "map".equals(executionHint)) {
return new TermsStringFacetExecutor(indexFieldData, size, comparatorType, allTerms, context, excluded, pattern, searchScript);
} else if (indexFieldData instanceof IndexFieldData.WithOrdinals) {
return new TermsStringOrdinalsFacetExecutor((IndexFieldData.WithOrdinals) indexFieldData, size, comparatorType, allTerms, context, excluded, pattern);
return new TermsStringOrdinalsFacetExecutor((IndexFieldData.WithOrdinals) indexFieldData, size, comparatorType, allTerms, context, excluded, pattern, ordinalsCacheAbove);
} else {
return new TermsStringFacetExecutor(indexFieldData, size, comparatorType, allTerms, context, excluded, pattern, searchScript);
}

View File

@ -54,17 +54,19 @@ public class TermsStringOrdinalsFacetExecutor extends FacetExecutor {
private final int minCount;
private final ImmutableSet<BytesRef> excluded;
private final Matcher matcher;
final int ordinalsCacheAbove;
final List<ReaderAggregator> aggregators;
long missing;
long total;
public TermsStringOrdinalsFacetExecutor(IndexFieldData.WithOrdinals indexFieldData, int size, TermsFacet.ComparatorType comparatorType, boolean allTerms, SearchContext context,
ImmutableSet<BytesRef> excluded, Pattern pattern) {
ImmutableSet<BytesRef> excluded, Pattern pattern, int ordinalsCacheAbove) {
this.indexFieldData = indexFieldData;
this.size = size;
this.comparatorType = comparatorType;
this.numberOfShards = context.numberOfShards();
this.ordinalsCacheAbove = ordinalsCacheAbove;
if (excluded == null || excluded.isEmpty()) {
this.excluded = null;
@ -136,7 +138,9 @@ public class TermsStringOrdinalsFacetExecutor extends FacetExecutor {
}
for (ReaderAggregator aggregator : aggregators) {
CacheRecycler.pushIntArray(aggregator.counts);
if (aggregator.counts.length > ordinalsCacheAbove) {
CacheRecycler.pushIntArray(aggregator.counts);
}
}
return new InternalStringTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing, total);
@ -174,7 +178,9 @@ public class TermsStringOrdinalsFacetExecutor extends FacetExecutor {
for (ReaderAggregator aggregator : aggregators) {
CacheRecycler.pushIntArray(aggregator.counts);
if (aggregator.counts.length > ordinalsCacheAbove) {
CacheRecycler.pushIntArray(aggregator.counts);
}
}
return new InternalStringTermsFacet(facetName, comparatorType, size, ordered, missing, total);
@ -197,7 +203,7 @@ public class TermsStringOrdinalsFacetExecutor extends FacetExecutor {
}
}
values = indexFieldData.load(context).getBytesValues();
current = new ReaderAggregator(values);
current = new ReaderAggregator(values, ordinalsCacheAbove);
}
@Override
@ -231,11 +237,15 @@ public class TermsStringOrdinalsFacetExecutor extends FacetExecutor {
int total;
private final int maxOrd;
public ReaderAggregator(BytesValues.WithOrdinals values) {
public ReaderAggregator(BytesValues.WithOrdinals values, int ordinalsCacheLimit) {
this.values = values;
this.maxOrd = values.ordinals().getMaxOrd();
this.counts = CacheRecycler.popIntArray(maxOrd);
if (maxOrd > ordinalsCacheLimit) {
this.counts = CacheRecycler.popIntArray(maxOrd);
} else {
this.counts = new int[maxOrd];
}
}
@Override