forked from apache/lucene-solr
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
835 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
solr/core/src/java/org/apache/solr/search/facet/BitmapFrequencyAgg.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.apache.solr.search.facet; | ||
|
||
import org.apache.lucene.queries.function.ValueSource; | ||
import org.apache.solr.common.util.SimpleOrderedMap; | ||
import org.apache.solr.search.FunctionQParser; | ||
import org.apache.solr.search.SyntaxError; | ||
import org.apache.solr.search.ValueSourceParser; | ||
|
||
/** | ||
* Calculates the frequency of ordinal values using Roaring Bitmaps. | ||
* | ||
* The response is a map with the following fields: | ||
* - bitmaps: an array of bitmaps, where the frequency of a value x is given by the sum of {@code 2^i} for all values | ||
* of {@code i} where {@code bitmaps[i].contains(x)} | ||
* - overflow: a bitmap of ordinal values with {@code frequency >= 2^(bitmaps.length)} | ||
* | ||
* Lacking a coherent definition of magnitude other than the raw count, this aggregate cannot be used for sorting. | ||
*/ | ||
public class BitmapFrequencyAgg extends SimpleAggValueSource { | ||
private final int size; | ||
|
||
public BitmapFrequencyAgg(ValueSource vs, int size) { | ||
super("bitmapfreq", vs); | ||
|
||
this.size = size; | ||
} | ||
|
||
@Override | ||
public SlotAcc createSlotAcc(FacetContext fcontext, int numDocs, int numSlots) { | ||
return new BitmapFrequencySlotAcc(getArg(), fcontext, numSlots, size); | ||
} | ||
|
||
@Override | ||
public FacetMerger createFacetMerger(Object prototype) { | ||
return new Merger(size); | ||
} | ||
|
||
public static class Parser extends ValueSourceParser { | ||
@Override | ||
public ValueSource parse(FunctionQParser fp) throws SyntaxError { | ||
ValueSource valueSource = fp.parseValueSource(); | ||
|
||
int size = 16; | ||
if (fp.hasMoreArguments()) { | ||
size = fp.parseInt(); | ||
} | ||
|
||
return new BitmapFrequencyAgg(valueSource, size); | ||
} | ||
} | ||
|
||
private static class Merger extends FacetMerger { | ||
private final int size; | ||
private BitmapFrequencyCounter result; | ||
|
||
public Merger(int size) { | ||
this.size = size; | ||
this.result = new BitmapFrequencyCounter(size); | ||
} | ||
|
||
@Override | ||
public void merge(Object facetResult, Context mcontext) { | ||
if (facetResult instanceof SimpleOrderedMap) { | ||
BitmapFrequencyCounter deserialized = new BitmapFrequencyCounter(size); | ||
deserialized.deserialize((SimpleOrderedMap<Object>) facetResult); | ||
|
||
result = result.merge(deserialized); | ||
} | ||
} | ||
|
||
@Override | ||
public void finish(Context mcontext) { | ||
// never called | ||
} | ||
|
||
@Override | ||
public Object getMergedResult() { | ||
return result.serialize(); | ||
} | ||
} | ||
} |
Oops, something went wrong.