Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP backport from master #71

Open
wants to merge 1 commit into
base: bw_branch_8_11_3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* Accumulates stats separated by slot number for the fields with {@link org.apache.lucene.index.DocValues}
*/
public abstract class DocValuesAcc extends SlotAcc {
SchemaField sf;
protected SchemaField sf;

public DocValuesAcc(FacetContext fcontext, SchemaField sf) throws IOException {
super(fcontext);
Expand Down
10 changes: 5 additions & 5 deletions solr/core/src/java/org/apache/solr/search/facet/FacetModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class FacetComponentState {
}

// base class for facet functions that can be used in a sort
abstract static class FacetSortableMerger extends FacetMerger {
public abstract static class FacetSortableMerger extends FacetMerger {
public void prepareSort() {
}

Expand All @@ -370,7 +370,7 @@ public void finish(Context mcontext) {
public abstract int compareTo(FacetSortableMerger other, FacetRequest.SortDirection direction);
}

abstract static class FacetDoubleMerger extends FacetSortableMerger {
public abstract static class FacetDoubleMerger extends FacetSortableMerger {
@Override
public abstract void merge(Object facetResult, Context mcontext);

Expand Down Expand Up @@ -408,7 +408,7 @@ public static int compare(double a, double b, FacetRequest.SortDirection directi
}
}

static class FacetLongMerger extends FacetSortableMerger {
public static class FacetLongMerger extends FacetSortableMerger {
long val;

@Override
Expand All @@ -429,7 +429,7 @@ public int compareTo(FacetSortableMerger other, FacetRequest.SortDirection direc


// base class for facets that create buckets (and can hence have sub-facets)
abstract static class FacetBucketMerger<FacetRequestT extends FacetRequest> extends FacetMerger {
public abstract static class FacetBucketMerger<FacetRequestT extends FacetRequest> extends FacetMerger {
FacetRequestT freq;

public FacetBucketMerger(FacetRequestT freq) {
Expand Down Expand Up @@ -469,7 +469,7 @@ FacetMerger createFacetMerger(String key, Object val) {
}


static class FacetQueryMerger extends FacetBucketMerger<FacetQuery> {
public static class FacetQueryMerger extends FacetBucketMerger<FacetQuery> {
FacetBucket bucket;

public FacetQueryMerger(FacetQuery freq) {
Expand Down
42 changes: 25 additions & 17 deletions solr/core/src/java/org/apache/solr/search/facet/FacetParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import org.apache.solr.common.SolrException;
Expand All @@ -34,7 +35,7 @@

import static org.apache.solr.common.params.CommonParams.SORT;

abstract class FacetParser<FacetRequestT extends FacetRequest> {
public abstract class FacetParser<FacetRequestT extends FacetRequest> {
protected FacetRequestT facet;
protected FacetParser<?> parent;
protected String key;
Expand Down Expand Up @@ -133,23 +134,30 @@ public Object parseFacetOrStat(String key, Object o) throws SyntaxError {
return parseFacetOrStat(key, type, args);
}

public interface ParseHandler {
Object doParse(FacetParser<?> parent, String key, Object args) throws SyntaxError;
}

private static final Map<String, ParseHandler> REGISTERED_TYPES = new ConcurrentHashMap<>();

static {
ParseHandler fieldParser = (p, k, a) -> new FacetFieldParser(p, k).parse(a);
REGISTERED_TYPES.put("field", fieldParser);
REGISTERED_TYPES.put("terms", fieldParser);
REGISTERED_TYPES.put("query", (p, k, a) -> new FacetQueryParser(p, k).parse(a));
REGISTERED_TYPES.put("range", (p, k, a) -> new FacetRangeParser(p, k).parse(a));
REGISTERED_TYPES.put("heatmap", (p, k, a) -> new FacetHeatmap.Parser(p, k).parse(a));
REGISTERED_TYPES.put("func", (p, k, a) -> p.parseStat(k, a));
}

public static void registerParseHandler(String type, ParseHandler parseHandler) {
REGISTERED_TYPES.put(type, parseHandler);
}

public Object parseFacetOrStat(String key, String type, Object args) throws SyntaxError {
// TODO: a place to register all these facet types?

switch (type) {
case "field":
case "terms":
return new FacetFieldParser(this, key).parse(args);
case "query":
return new FacetQueryParser(this, key).parse(args);
case "range":
return new FacetRangeParser(this, key).parse(args);
case "topdocs":
return TopDocsAgg.AggParser.parse(args);
case "heatmap":
return new FacetHeatmap.Parser(this, key).parse(args);
case "func":
return parseStat(key, args);
ParseHandler parseHandler = REGISTERED_TYPES.get(type);
if (parseHandler != null) {
return parseHandler.doParse(this, key, args);
}

throw err("Unknown facet or stat. key=" + key + " type=" + type + " args=" + args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.apache.lucene.util.LongValues;
import org.apache.solr.schema.SchemaField;

class UniqueMultiDvSlotAcc extends UniqueSlotAcc {
public class UniqueMultiDvSlotAcc extends UniqueSlotAcc {
SortedSetDocValues topLevel;
SortedSetDocValues[] subDvs;
OrdinalMap ordMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.SolrIndexSearcher;

class UniqueMultivaluedSlotAcc extends UniqueSlotAcc implements UnInvertedField.Callback {
public class UniqueMultivaluedSlotAcc extends UniqueSlotAcc implements UnInvertedField.Callback {
private UnInvertedField uif;
private UnInvertedField.DocToTerm docToTerm;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.apache.lucene.util.LongValues;
import org.apache.solr.schema.SchemaField;

class UniqueSinglevaluedSlotAcc extends UniqueSlotAcc {
public class UniqueSinglevaluedSlotAcc extends UniqueSlotAcc {
SortedDocValues topLevel;
SortedDocValues[] subDvs;
OrdinalMap ordMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.solr.schema.SchemaField;
import org.apache.solr.util.hll.HLL;

abstract class UniqueSlotAcc extends SlotAcc {
public abstract class UniqueSlotAcc extends SlotAcc {
HLLAgg.HLLFactory factory;
SchemaField field;
FixedBitSet[] arr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.solr.SolrTestCase;
import org.apache.solr.search.facet.FacetContext;
import org.apache.solr.search.facet.FacetMerger;
import org.apache.solr.search.facet.FacetModule;
import org.apache.solr.search.facet.SimpleAggValueSource;
import org.apache.solr.search.facet.SlotAcc;
import org.junit.Test;
Expand Down Expand Up @@ -75,7 +76,8 @@ public Object getValue(int slot) {

@Override
public FacetMerger createFacetMerger(Object prototype) {
return new FacetMerger() {
// check these inner classes can be referenced by name
FacetModule.FacetSortableMerger merger = new FacetModule.FacetDoubleMerger() {
double total = 0.0D;

@Override
Expand All @@ -84,13 +86,11 @@ public void merge(Object facetResult, Context mcontext) {
}

@Override
public void finish(Context mcontext) { }

@Override
public Object getMergedResult() {
public double getDouble() {
return total;
}
};
return merger;
}

@Override
Expand Down
Loading