Skip to content

Commit 28f7a7e

Browse files
committed
Merge branch 'bitmapfrequency' of github.com:mkavanagh/bw-lucene-solr into bitmapfrequency
2 parents 7b07df4 + 2687ce4 commit 28f7a7e

6 files changed

+603
-0
lines changed

solr/core/src/java/org/apache/solr/search/ValueSourceParser.java

+4
Original file line numberDiff line numberDiff line change
@@ -1064,8 +1064,12 @@ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
10641064

10651065
addParser("agg_bitmapfreq", new BitmapFrequencyAgg.Parser());
10661066

1067+
addParser("agg_bitmapfreq64", new BitmapFrequencyAgg.Parser());
1068+
10671069
addParser("agg_bitmapfreqfreq", new FrequencyOfFrequenciesAgg.Parser());
10681070

1071+
addParser("agg_bitmapfreqfreq64", new FrequencyOfFrequenciesAgg.Parser());
1072+
10691073
addParser("agg_termfreqfreq", new TermFrequencyOfFrequenciesAgg.Parser());
10701074

10711075
addParser("childfield", new ChildFieldValueSourceParser());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package org.apache.solr.search.facet;
2+
3+
import org.apache.lucene.queries.function.ValueSource;
4+
import org.apache.solr.common.util.SimpleOrderedMap;
5+
import org.apache.solr.search.FunctionQParser;
6+
import org.apache.solr.search.SyntaxError;
7+
import org.apache.solr.search.ValueSourceParser;
8+
9+
/**
10+
* Calculates the frequency of ordinal values using Roaring Bitmaps.
11+
*
12+
* The response is a map with the following fields:
13+
* - bitmaps: an array of bitmaps, where the frequency of a value x is given by the sum of {@code 2^i} for all values
14+
* of {@code i} where {@code bitmaps[i].contains(x)}
15+
* - overflow: a map of ordinal values to frequencies, for values with {@code frequency >= 2^(bitmaps.length)}
16+
*
17+
* Lacking a coherent definition of magnitude other than the raw count, this aggregate cannot be used for sorting.
18+
*/
19+
public class BitmapFrequencyAgg64 extends SimpleAggValueSource {
20+
private final int size;
21+
22+
public BitmapFrequencyAgg64(ValueSource vs, int size) {
23+
super("bitmapfreq64", vs);
24+
25+
this.size = size;
26+
}
27+
28+
@Override
29+
public SlotAcc createSlotAcc(FacetContext fcontext, int numDocs, int numSlots) {
30+
return new BitmapFrequencySlotAcc64(getArg(), fcontext, numSlots, size);
31+
}
32+
33+
@Override
34+
public FacetMerger createFacetMerger(Object prototype) {
35+
return new Merger(size);
36+
}
37+
38+
public static class Parser extends ValueSourceParser {
39+
@Override
40+
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
41+
ValueSource valueSource = fp.parseValueSource();
42+
43+
int size = 16;
44+
if (fp.hasMoreArguments()) {
45+
size = fp.parseInt();
46+
}
47+
48+
return new BitmapFrequencyAgg64(valueSource, size);
49+
}
50+
}
51+
52+
private static class Merger extends FacetMerger {
53+
private final int size;
54+
private BitmapFrequencyCounter64 result;
55+
56+
public Merger(int size) {
57+
this.size = size;
58+
this.result = new BitmapFrequencyCounter64(size);
59+
}
60+
61+
@Override
62+
public void merge(Object facetResult, Context mcontext) {
63+
if (facetResult instanceof SimpleOrderedMap) {
64+
BitmapFrequencyCounter64 deserialized = new BitmapFrequencyCounter64(size);
65+
deserialized.deserialize((SimpleOrderedMap<Object>) facetResult);
66+
67+
result = result.merge(deserialized);
68+
}
69+
}
70+
71+
@Override
72+
public void finish(Context mcontext) {
73+
// never called
74+
}
75+
76+
@Override
77+
public Object getMergedResult() {
78+
result.normalize();
79+
return result.serialize();
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)