Skip to content

Commit 4249609

Browse files
committed
Fix bitmap aggs for non-distributed mode
1 parent d3bac6b commit 4249609

8 files changed

+113
-36
lines changed

solr/core/src/java/org/apache/solr/search/facet/BitmapFrequencyCounter.java

+17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.ArrayList;
44
import java.util.HashMap;
5+
import java.util.LinkedHashMap;
56
import java.util.List;
67
import java.util.Map;
78

@@ -253,6 +254,22 @@ public void normalize() {
253254
});
254255
}
255256

257+
public Map<Integer, Integer> toFrequencyOfFrequencies() {
258+
Map<Integer, Integer> map = new LinkedHashMap<>();
259+
260+
int[] lowFrequencies = decode();
261+
for (int i = 0; i < lowFrequencies.length; i++) {
262+
int value = lowFrequencies[i];
263+
if (value > 0) {
264+
map.put(i, value);
265+
}
266+
}
267+
268+
overflow.forEach((value, freq) -> map.merge(freq, 1, Integer::sum));
269+
270+
return map;
271+
}
272+
256273
public int[] decode() {
257274
int endIndex = 0;
258275
while (endIndex < bitmaps.length && bitmaps[endIndex] != null) {

solr/core/src/java/org/apache/solr/search/facet/BitmapFrequencyCounter64.java

+17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.ArrayList;
44
import java.util.HashMap;
5+
import java.util.LinkedHashMap;
56
import java.util.List;
67
import java.util.Map;
78

@@ -254,6 +255,22 @@ public void normalize() {
254255
});
255256
}
256257

258+
public Map<Integer, Integer> toFrequencyOfFrequencies() {
259+
Map<Integer, Integer> map = new LinkedHashMap<>();
260+
261+
int[] lowFrequencies = decode();
262+
for (int i = 0; i < lowFrequencies.length; i++) {
263+
int value = lowFrequencies[i];
264+
if (value > 0) {
265+
map.put(i, value);
266+
}
267+
}
268+
269+
overflow.forEach((value, freq) -> map.merge(freq, 1, Integer::sum));
270+
271+
return map;
272+
}
273+
257274
public int[] decode() {
258275
int endIndex = 0;
259276
while (endIndex < bitmaps.length && bitmaps[endIndex] != null) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.apache.solr.search.facet;
2+
3+
import java.util.Collections;
4+
5+
import org.apache.lucene.queries.function.ValueSource;
6+
7+
public class BitmapFrequencyOfFrequenciesSlotAcc extends BitmapFrequencySlotAcc {
8+
public BitmapFrequencyOfFrequenciesSlotAcc(ValueSource values, FacetContext fcontext, int numSlots, int maxFrequency) {
9+
super(values, fcontext, numSlots, maxFrequency);
10+
}
11+
12+
@Override
13+
public Object getFinalValue(BitmapFrequencyCounter result) {
14+
if (result != null) {
15+
result.normalize();
16+
return result.toFrequencyOfFrequencies();
17+
} else {
18+
return Collections.emptyMap();
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.apache.solr.search.facet;
2+
3+
import java.io.IOException;
4+
import java.util.Arrays;
5+
import java.util.Collections;
6+
import java.util.function.IntFunction;
7+
8+
import org.apache.lucene.queries.function.ValueSource;
9+
10+
public class BitmapFrequencyOfFrequenciesSlotAcc64 extends BitmapFrequencySlotAcc64 {
11+
public BitmapFrequencyOfFrequenciesSlotAcc64(ValueSource values, FacetContext fcontext, int numSlots, int maxFrequency) {
12+
super(values, fcontext, numSlots, maxFrequency);
13+
}
14+
15+
@Override
16+
public Object getFinalValue(BitmapFrequencyCounter64 result) {
17+
if (result != null) {
18+
result.normalize();
19+
return result.toFrequencyOfFrequencies();
20+
} else {
21+
return Collections.emptyMap();
22+
}
23+
}
24+
}

solr/core/src/java/org/apache/solr/search/facet/BitmapFrequencySlotAcc.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,26 @@ public int compare(int slotA, int slotB) {
3333

3434
@Override
3535
public Object getValue(int slotNum) {
36-
if (result[slotNum] != null) {
37-
return result[slotNum].serialize();
36+
if (fcontext.isShard()) {
37+
return getShardValue(result[slotNum]);
38+
} else {
39+
return getFinalValue(result[slotNum]);
40+
}
41+
}
42+
43+
public Object getShardValue(BitmapFrequencyCounter result) {
44+
if (result != null) {
45+
return result.serialize();
3846
} else {
3947
return Collections.emptyList();
4048
}
4149
}
4250

51+
public Object getFinalValue(BitmapFrequencyCounter result) {
52+
result.normalize();
53+
return getShardValue(result);
54+
}
55+
4356
@Override
4457
public void reset() {
4558
Arrays.fill(result, null);

solr/core/src/java/org/apache/solr/search/facet/BitmapFrequencySlotAcc64.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,26 @@ public int compare(int slotA, int slotB) {
3333

3434
@Override
3535
public Object getValue(int slotNum) {
36-
if (result[slotNum] != null) {
37-
return result[slotNum].serialize();
36+
if (fcontext.isShard()) {
37+
return getShardValue(result[slotNum]);
38+
} else {
39+
return getFinalValue(result[slotNum]);
40+
}
41+
}
42+
43+
public Object getShardValue(BitmapFrequencyCounter64 result) {
44+
if (result != null) {
45+
return result.serialize();
3846
} else {
3947
return Collections.emptyList();
4048
}
4149
}
4250

51+
public Object getFinalValue(BitmapFrequencyCounter64 result) {
52+
result.normalize();
53+
return getShardValue(result);
54+
}
55+
4356
@Override
4457
public void reset() {
4558
Arrays.fill(result, null);

solr/core/src/java/org/apache/solr/search/facet/FrequencyOfFrequenciesAgg.java

+2-16
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public FrequencyOfFrequenciesAgg(ValueSource vs, Integer size) {
2828

2929
@Override
3030
public SlotAcc createSlotAcc(FacetContext fcontext, int numDocs, int numSlots) {
31-
return new BitmapFrequencySlotAcc(getArg(), fcontext, numSlots, size);
31+
return new BitmapFrequencyOfFrequenciesSlotAcc(getArg(), fcontext, numSlots, size);
3232
}
3333

3434
@Override
@@ -76,22 +76,8 @@ public void finish(Context mcontext) {
7676

7777
@Override
7878
public Object getMergedResult() {
79-
Map<Integer, Integer> map = new LinkedHashMap<>();
80-
8179
result.normalize();
82-
83-
int[] lowFrequencies = result.decode();
84-
for (int i = 0; i < lowFrequencies.length; i++) {
85-
int value = lowFrequencies[i];
86-
if (value > 0) {
87-
map.put(i, value);
88-
}
89-
}
90-
91-
result.getOverflow()
92-
.forEach((value, freq) -> map.merge(freq, 1, Integer::sum));
93-
94-
return map;
80+
return result.toFrequencyOfFrequencies();
9581
}
9682
}
9783
}

solr/core/src/java/org/apache/solr/search/facet/FrequencyOfFrequenciesAgg64.java

+2-16
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public FrequencyOfFrequenciesAgg64(ValueSource vs, Integer size) {
2828

2929
@Override
3030
public SlotAcc createSlotAcc(FacetContext fcontext, int numDocs, int numSlots) {
31-
return new BitmapFrequencySlotAcc64(getArg(), fcontext, numSlots, size);
31+
return new BitmapFrequencyOfFrequenciesSlotAcc64(getArg(), fcontext, numSlots, size);
3232
}
3333

3434
@Override
@@ -76,22 +76,8 @@ public void finish(Context mcontext) {
7676

7777
@Override
7878
public Object getMergedResult() {
79-
Map<Integer, Integer> map = new LinkedHashMap<>();
80-
8179
result.normalize();
82-
83-
int[] lowFrequencies = result.decode();
84-
for (int i = 0; i < lowFrequencies.length; i++) {
85-
int value = lowFrequencies[i];
86-
if (value > 0) {
87-
map.put(i, value);
88-
}
89-
}
90-
91-
result.getOverflow()
92-
.forEach((value, freq) -> map.merge(freq, 1, Integer::sum));
93-
94-
return map;
80+
return result.toFrequencyOfFrequencies();
9581
}
9682
}
9783
}

0 commit comments

Comments
 (0)