You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by cp...@apache.org on 2017/09/06 09:39:31 UTC
[29/50] lucene-solr:jira/solr-10990: SOLR-10613: add flag to
FunctionQParser to use FieldNameValueSource place holder when encountering a
field name
SOLR-10613: add flag to FunctionQParser to use FieldNameValueSource place holder when encountering a field name
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/33178fb5
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/33178fb5
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/33178fb5
Branch: refs/heads/jira/solr-10990
Commit: 33178fb5ccd43fa0c54d2df3760d3362c2700a28
Parents: 3423ae4
Author: yonik <yo...@apache.org>
Authored: Mon Sep 4 18:58:31 2017 -0400
Committer: yonik <yo...@apache.org>
Committed: Mon Sep 4 18:58:52 2017 -0400
----------------------------------------------------------------------
.../org/apache/solr/search/FunctionQParser.java | 11 +++-
.../apache/solr/search/ValueSourceParser.java | 4 +-
.../org/apache/solr/search/facet/MinMaxAgg.java | 12 +++-
.../search/function/FieldNameValueSource.java | 60 ++++++++++++++++++++
4 files changed, 81 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33178fb5/solr/core/src/java/org/apache/solr/search/FunctionQParser.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/FunctionQParser.java b/solr/core/src/java/org/apache/solr/search/FunctionQParser.java
index 7e6a706..d3a311d 100644
--- a/solr/core/src/java/org/apache/solr/search/FunctionQParser.java
+++ b/solr/core/src/java/org/apache/solr/search/FunctionQParser.java
@@ -25,6 +25,7 @@ import org.apache.solr.common.params.SolrParams;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.facet.AggValueSource;
+import org.apache.solr.search.function.FieldNameValueSource;
import java.util.ArrayList;
import java.util.List;
@@ -33,6 +34,7 @@ public class FunctionQParser extends QParser {
public static final int FLAG_CONSUME_DELIMITER = 0x01; // consume delimiter after parsing arg
public static final int FLAG_IS_AGG = 0x02;
+ public static final int FLAG_USE_FIELDNAME_SOURCE = 0x04; // When a field name is encountered, use the placeholder FieldNameValueSource instead of resolving to a real ValueSource
public static final int FLAG_DEFAULT = FLAG_CONSUME_DELIMITER;
/** @lucene.internal */
@@ -374,8 +376,13 @@ public class FunctionQParser extends QParser {
} else if ("false".equals(id)) {
valueSource = new BoolConstValueSource(false);
} else {
- SchemaField f = req.getSchema().getField(id);
- valueSource = f.getType().getValueSource(f, this);
+ if ((flags & FLAG_USE_FIELDNAME_SOURCE) != 0) {
+ // Don't try to create a ValueSource for the field, just use a placeholder.
+ valueSource = new FieldNameValueSource(id);
+ } else {
+ SchemaField f = req.getSchema().getField(id);
+ valueSource = f.getType().getValueSource(f, this);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33178fb5/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 7d6d162..51048d2 100644
--- a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
+++ b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
@@ -1017,14 +1017,14 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
addParser("agg_min", new ValueSourceParser() {
@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
- return new MinMaxAgg("min", fp.parseValueSource());
+ return new MinMaxAgg("min", fp.parseValueSource(FunctionQParser.FLAG_DEFAULT | FunctionQParser.FLAG_USE_FIELDNAME_SOURCE));
}
});
addParser("agg_max", new ValueSourceParser() {
@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
- return new MinMaxAgg("max", fp.parseValueSource());
+ return new MinMaxAgg("max", fp.parseValueSource(FunctionQParser.FLAG_DEFAULT | FunctionQParser.FLAG_USE_FIELDNAME_SOURCE));
}
});
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33178fb5/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java b/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java
index a6d6b97..9569599 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java
@@ -28,6 +28,7 @@ import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LongValues;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.schema.StrFieldSource;
+import org.apache.solr.search.function.FieldNameValueSource;
public class MinMaxAgg extends SimpleAggValueSource {
final int minmax; // a multiplier to reverse the normal order of compare if this is max instead of min (i.e. max will be -1)
@@ -41,9 +42,16 @@ public class MinMaxAgg extends SimpleAggValueSource {
public SlotAcc createSlotAcc(FacetContext fcontext, int numDocs, int numSlots) throws IOException {
ValueSource vs = getArg();
+ SchemaField sf = null;
+
+ if (vs instanceof FieldNameValueSource) {
+ String field = ((FieldNameValueSource)vs).getFieldName();
+ sf = fcontext.qcontext.searcher().getSchema().getField(field);
+
+ vs = sf.getType().getValueSource(sf, null); // temporary implementation to make existing code work
+ }
+
if (vs instanceof StrFieldSource) {
- String field = ((StrFieldSource) vs).getField();
- SchemaField sf = fcontext.qcontext.searcher().getSchema().getField(field);
if (sf.multiValued() || sf.getType().multiValuedFieldCache()) {
if (sf.hasDocValues()) {
// dv
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33178fb5/solr/core/src/java/org/apache/solr/search/function/FieldNameValueSource.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/function/FieldNameValueSource.java b/solr/core/src/java/org/apache/solr/search/function/FieldNameValueSource.java
new file mode 100644
index 0000000..c122dbb
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/search/function/FieldNameValueSource.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.search.function;
+
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ValueSource;
+
+/** Placeholder value source.
+ * @lucene.internal */
+public class FieldNameValueSource extends ValueSource {
+ private String fieldName;
+
+ public FieldNameValueSource(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ @Override
+ public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+ throw new UnsupportedOperationException("FieldNameValueSource should not be directly used: " + this);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof FieldNameValueSource && fieldName.equals(((FieldNameValueSource)o).getFieldName());
+ }
+
+ @Override
+ public int hashCode() {
+ return fieldName.hashCode();
+ }
+
+ @Override
+ public String description() {
+ return "FIELDNAME(" + fieldName + ")";
+ }
+}