You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by eh...@apache.org on 2017/04/30 02:57:30 UTC
[1/2] lucene-solr:jira/SOLR-1485: remove my messed up merge
Repository: lucene-solr
Updated Branches:
refs/heads/jira/SOLR-1485 469aca7fc -> 04e760463
remove my messed up merge
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/29bfcc9a
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/29bfcc9a
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/29bfcc9a
Branch: refs/heads/jira/SOLR-1485
Commit: 29bfcc9a2f4efd26ace5dda77dfb5531aaad8e70
Parents: 469aca7
Author: Erik Hatcher <eh...@apache.org>
Authored: Sat Apr 29 22:56:01 2017 -0400
Committer: Erik Hatcher <eh...@apache.org>
Committed: Sat Apr 29 22:56:01 2017 -0400
----------------------------------------------------------------------
.../apache/solr/search/ValueSourceParser.java | 101 ++++++-------------
1 file changed, 33 insertions(+), 68 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/29bfcc9a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
index 6149582..3d96785 100644
--- a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
+++ b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
@@ -34,8 +34,6 @@ import org.apache.lucene.queries.function.docvalues.BoolDocValues;
import org.apache.lucene.queries.function.docvalues.DoubleDocValues;
import org.apache.lucene.queries.function.docvalues.LongDocValues;
import org.apache.lucene.queries.function.valuesource.*;
-import org.apache.lucene.queries.payloads.AveragePayloadFunction;
-import org.apache.lucene.queries.payloads.PayloadFunction;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.SortField;
@@ -60,9 +58,11 @@ import org.apache.solr.search.facet.HLLAgg;
import org.apache.solr.search.facet.MaxAgg;
import org.apache.solr.search.facet.MinAgg;
import org.apache.solr.search.facet.PercentileAgg;
+import org.apache.solr.search.facet.StddevAgg;
import org.apache.solr.search.facet.SumAgg;
import org.apache.solr.search.facet.SumsqAgg;
import org.apache.solr.search.facet.UniqueAgg;
+import org.apache.solr.search.facet.VarianceAgg;
import org.apache.solr.search.function.CollapseScoreFunction;
import org.apache.solr.search.function.OrdFieldSource;
import org.apache.solr.search.function.ReverseOrdFieldSource;
@@ -76,8 +76,6 @@ import org.apache.solr.search.function.distance.StringDistanceFunction;
import org.apache.solr.search.function.distance.VectorDistanceFunction;
import org.apache.solr.search.join.ChildFieldValueSourceParser;
import org.apache.solr.util.DateMathParser;
-import org.apache.solr.util.PayloadDecoder;
-import org.apache.solr.util.PayloadUtils;
import org.apache.solr.util.plugin.NamedListInitializedPlugin;
import org.locationtech.spatial4j.distance.DistanceUtils;
@@ -99,10 +97,10 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
/** standard functions supported by default, filled in static class initialization */
private static final Map<String, ValueSourceParser> standardVSParsers = new HashMap<>();
-
+
/** standard functions supported by default */
public static final Map<String, ValueSourceParser> standardValueSourceParsers
- = Collections.unmodifiableMap(standardVSParsers);
+ = Collections.unmodifiableMap(standardVSParsers);
/** Adds a new parser for the name and returns any existing one that was overridden.
* This is not thread safe.
@@ -272,7 +270,7 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
return new SumFloatFunction(sources.toArray(new ValueSource[sources.size()]));
}
});
- alias("sum","add");
+ alias("sum","add");
addParser("product", new ValueSourceParser() {
@Override
@@ -346,7 +344,7 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
double radius = fp.parseDouble();
//SOLR-2114, make the convert flag required, since the parser doesn't support much in the way of lookahead or the ability to convert a String into a ValueSource
boolean convert = Boolean.parseBoolean(fp.parseArg());
-
+
MultiValueSource pv1;
MultiValueSource pv2;
@@ -362,7 +360,7 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
pv2 = (MultiValueSource) two;
} else {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
- "Input must either be 2 MultiValueSources, or there must be 4 ValueSources");
+ "Input must either be 2 MultiValueSources, or there must be 4 ValueSources");
}
}
@@ -429,7 +427,7 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
FieldType.MultiValueSelector selector = FieldType.MultiValueSelector.lookup(s);
if (null == selector) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
- "Multi-Valued field selector '"+s+"' not supported");
+ "Multi-Valued field selector '"+s+"' not supported");
}
return f.getType().getSingleValueSource(selector, f, fp);
}
@@ -445,7 +443,7 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
SchemaField f = fp.getReq().getSchema().getField(fieldName);
if (! (f.getType() instanceof CurrencyField)) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
- "Currency function input must be the name of a CurrencyField: " + fieldName);
+ "Currency function input must be the name of a CurrencyField: " + fieldName);
}
CurrencyField ft = (CurrencyField) f.getType();
String code = fp.hasMoreArguments() ? fp.parseArg() : null;
@@ -621,7 +619,7 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
});
addParser("ms", new DateValueSourceParser());
-
+
addParser("pi", new ValueSourceParser() {
@Override
public ValueSource parse(FunctionQParser fp) {
@@ -708,47 +706,6 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
}
});
- addParser("payload", new ValueSourceParser() {
- @Override
- public ValueSource parse(FunctionQParser fp) throws SyntaxError {
- // payload(field,value[,default, ['min|max|average|first']])
- // defaults to "average" and 0.0 default value
-
- TInfo tinfo = parseTerm(fp); // would have made this parser a new separate class and registered it, but this handy method is private :/
-
- ValueSource defaultValueSource;
- if (fp.hasMoreArguments()) {
- defaultValueSource = fp.parseValueSource();
- } else {
- defaultValueSource = new ConstValueSource(0.0f);
- }
-
- PayloadFunction payloadFunction = null;
- String func = "average";
- if (fp.hasMoreArguments()) {
- func = fp.parseArg();
- }
- payloadFunction = PayloadUtils.getPayloadFunction(func);
-
- // Support func="first" by payloadFunction=null
- if(payloadFunction == null && !"first".equals(func)) {
- // not "first" (or average, min, or max)
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid payload function: " + func);
- }
-
- FieldType fieldType = fp.getReq().getCore().getLatestSchema().getFieldTypeNoEx(tinfo.field);
- PayloadDecoder decoder = PayloadUtils.getPayloadDecoder(fieldType);
- return new FloatPayloadValueSource(
- tinfo.field,
- tinfo.val,
- tinfo.indexedField,
- tinfo.indexedBytes.get(),
- decoder,
- payloadFunction,
- defaultValueSource);
- }
- });
-
addParser("true", new ValueSourceParser() {
@Override
public ValueSource parse(FunctionQParser fp) {
@@ -977,14 +934,21 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
}
});
- /***
- addParser("agg_stdev", new ValueSourceParser() {
- @Override
- public ValueSource parse(FunctionQParser fp) throws SyntaxError {
- return null;
- }
+ addParser("agg_variance", new ValueSourceParser() {
+ @Override
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
+ return new VarianceAgg(fp.parseValueSource());
+ }
+ });
+
+ addParser("agg_stddev", new ValueSourceParser() {
+ @Override
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
+ return new StddevAgg(fp.parseValueSource());
+ }
});
+ /***
addParser("agg_multistat", new ValueSourceParser() {
@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
@@ -1008,7 +972,7 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
});
addParser("agg_percentile", new PercentileAgg.Parser());
-
+
addParser("childfield", new ChildFieldValueSourceParser());
}
@@ -1033,7 +997,7 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
Query q = ft.getFieldQuery(fp, fp.getReq().getSchema().getFieldOrNull(tinfo.field), tinfo.val);
if (q instanceof TermQuery) {
Term term = ((TermQuery)q).getTerm();
- tinfo.indexedField = term.field(); // when would indexedField != field?
+ tinfo.indexedField = term.field();
indexedVal = term.text();
}
tinfo.indexedBytes.copyChars(indexedVal);
@@ -1069,7 +1033,7 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
mvr.mv1 = (MultiValueSource) sources.get(0);
mvr.mv2 = (MultiValueSource) sources.get(1);
} else if (s1MV ||
- s2MV) {
+ s2MV) {
//if one is a MultiValueSource, than the other one needs to be too.
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Illegal number of sources. There must be an even number of sources");
} else {
@@ -1365,7 +1329,7 @@ abstract class Double2Parser extends NamedParser {
private final ValueSource a;
private final ValueSource b;
- /**
+ /**
* @param a the base.
* @param b the exponent.
*/
@@ -1384,7 +1348,7 @@ abstract class Double2Parser extends NamedParser {
final FunctionValues aVals = a.getValues(context, readerContext);
final FunctionValues bVals = b.getValues(context, readerContext);
return new DoubleDocValues(this) {
- @Override
+ @Override
public double doubleVal(int doc) throws IOException {
return func(doc, aVals, bVals);
}
@@ -1455,7 +1419,7 @@ class BoolConstValueSource extends ConstNumberSource {
return this.constant == other.constant;
}
- @Override
+ @Override
public int getInt() {
return constant ? 1 : 0;
}
@@ -1486,13 +1450,14 @@ class BoolConstValueSource extends ConstNumberSource {
}
}
+
class TestValueSource extends ValueSource {
ValueSource source;
-
+
public TestValueSource(ValueSource source) {
this.source = source;
}
-
+
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
if (context.get(this) == null) {
@@ -1526,4 +1491,4 @@ class TestValueSource extends ValueSource {
public SortField getSortField(boolean reverse) {
return super.getSortField(reverse);
}
-}
+}
\ No newline at end of file
[2/2] lucene-solr:jira/SOLR-1485: add back _only_ payload() function
Posted by eh...@apache.org.
add back _only_ payload() function
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/04e76046
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/04e76046
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/04e76046
Branch: refs/heads/jira/SOLR-1485
Commit: 04e7604639debdee31c39282a08a0f6799c203d0
Parents: 29bfcc9
Author: Erik Hatcher <eh...@apache.org>
Authored: Sat Apr 29 22:57:24 2017 -0400
Committer: Erik Hatcher <eh...@apache.org>
Committed: Sat Apr 29 22:57:24 2017 -0400
----------------------------------------------------------------------
.../apache/solr/search/ValueSourceParser.java | 44 ++++++++++++++++++++
1 file changed, 44 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/04e76046/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
index 3d96785..2f170ef 100644
--- a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
+++ b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
@@ -34,6 +34,7 @@ import org.apache.lucene.queries.function.docvalues.BoolDocValues;
import org.apache.lucene.queries.function.docvalues.DoubleDocValues;
import org.apache.lucene.queries.function.docvalues.LongDocValues;
import org.apache.lucene.queries.function.valuesource.*;
+import org.apache.lucene.queries.payloads.PayloadFunction;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.SortField;
@@ -76,6 +77,8 @@ import org.apache.solr.search.function.distance.StringDistanceFunction;
import org.apache.solr.search.function.distance.VectorDistanceFunction;
import org.apache.solr.search.join.ChildFieldValueSourceParser;
import org.apache.solr.util.DateMathParser;
+import org.apache.solr.util.PayloadDecoder;
+import org.apache.solr.util.PayloadUtils;
import org.apache.solr.util.plugin.NamedListInitializedPlugin;
import org.locationtech.spatial4j.distance.DistanceUtils;
@@ -706,6 +709,47 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
}
});
+ addParser("payload", new ValueSourceParser() {
+ @Override
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
+ // payload(field,value[,default, ['min|max|average|first']])
+ // defaults to "average" and 0.0 default value
+
+ TInfo tinfo = parseTerm(fp); // would have made this parser a new separate class and registered it, but this handy method is private :/
+
+ ValueSource defaultValueSource;
+ if (fp.hasMoreArguments()) {
+ defaultValueSource = fp.parseValueSource();
+ } else {
+ defaultValueSource = new ConstValueSource(0.0f);
+ }
+
+ PayloadFunction payloadFunction = null;
+ String func = "average";
+ if (fp.hasMoreArguments()) {
+ func = fp.parseArg();
+ }
+ payloadFunction = PayloadUtils.getPayloadFunction(func);
+
+ // Support func="first" by payloadFunction=null
+ if(payloadFunction == null && !"first".equals(func)) {
+ // not "first" (or average, min, or max)
+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid payload function: " + func);
+ }
+
+ FieldType fieldType = fp.getReq().getCore().getLatestSchema().getFieldTypeNoEx(tinfo.field);
+ PayloadDecoder decoder = PayloadUtils.getPayloadDecoder(fieldType);
+ return new FloatPayloadValueSource(
+ tinfo.field,
+ tinfo.val,
+ tinfo.indexedField,
+ tinfo.indexedBytes.get(),
+ decoder,
+ payloadFunction,
+ defaultValueSource);
+ }
+ });
+
addParser("true", new ValueSourceParser() {
@Override
public ValueSource parse(FunctionQParser fp) {