diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 970fc33c6ef..dccca215632 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -122,6 +122,8 @@ Bug Fixes This is a fix for incomplete optimization made by SOLR-11880 in Solr 7.4 which fixed distributed updates but not distributed search. (shalin) +* SOLR-14291: Handle dotted fields in legacy Analytics Component (Anatolii Siuniaev via Mikhail Khludnev) + Other Changes --------------------- * SOLR-14197: SolrResourceLoader: marked many methods as deprecated, and in some cases rerouted exiting logic to avoid diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OldAnalyticsParams.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OldAnalyticsParams.java index e59e1cc9272..7a688d73f84 100644 --- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OldAnalyticsParams.java +++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OldAnalyticsParams.java @@ -48,14 +48,14 @@ public interface OldAnalyticsParams { public Map queryFacets = new HashMap<>(); } - public static final String FIELD_FACET = "ff|fieldfacet"; - public static final String VALUE_FACET = "vf|valuefacet"; - public static final String LIMIT = "l|limit"; - public static final String OFFSET = "off|offset"; - public static final String SHOW_MISSING = "sm|showmissing"; - public static final String SORT_EXPRESSION ="se|sortexpr|sortexpression"; - public static final String OLAP_SORT_EXPRESSION ="ss|sortstat|sortstatistic"; - public static final String SORT_DIRECTION ="sd|sortdirection"; + public static final String FIELD_FACET = "(?:ff|fieldfacet)"; + public static final String VALUE_FACET = "(?:vf|valuefacet)"; + public static final String LIMIT = "(?:l|limit)"; + public static final String OFFSET = "(?:off|offset)"; + public static final String SHOW_MISSING = "(?:sm|showmissing)"; + public static final String SORT_EXPRESSION ="(?:se|sortexpr|sortexpression)"; + public static final String OLAP_SORT_EXPRESSION ="(?:ss|sortstat|sortstatistic)"; + public static final String SORT_DIRECTION ="(?:sd|sortdirection)"; public static class OldFieldFacet { public String field; @@ -114,13 +114,13 @@ public interface OldAnalyticsParams { } } - public static final String RANGE_FACET = "rf|rangefacet"; - public static final String START = "st|start"; - public static final String END = "e|end"; - public static final String GAP = "g|gap"; - public static final String HARDEND = "he|hardend"; - public static final String INCLUDE_BOUNDARY = "ib|includebound"; - public static final String OTHER_RANGE = "or|otherrange"; + public static final String RANGE_FACET = "(?:rf|rangefacet)"; + public static final String START = "(?:st|start)"; + public static final String END = "(?:e|end)"; + public static final String GAP = "(?:g|gap)"; + public static final String HARDEND = "(?:he|hardend)"; + public static final String INCLUDE_BOUNDARY = "(?:ib|includebound)"; + public static final String OTHER_RANGE = "(?:or|otherrange)"; public static class OldRangeFacet { public String field; @@ -170,8 +170,8 @@ public interface OldAnalyticsParams { public String[] queries; } - public static final String QUERY_FACET = "qf|queryfacet"; - public static final String QUERY = "q|query"; + public static final String QUERY_FACET = "(?:qf|queryfacet)"; + public static final String QUERY = "(?:q|query)"; //Defaults public static final boolean DEFAULT_ABBREVIATE_PREFIX = true; diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OldAnalyticsRequestConverter.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OldAnalyticsRequestConverter.java index 60d0d40d4d7..1714553bf88 100644 --- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OldAnalyticsRequestConverter.java +++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/OldAnalyticsRequestConverter.java @@ -38,9 +38,9 @@ public class OldAnalyticsRequestConverter implements OldAnalyticsParams { private static final Pattern oldFieldFacetPattern = Pattern.compile("^(?:"+OLD_PREFIX+")\\.([^\\.]+)\\.(?:"+FIELD_FACET+")$", Pattern.CASE_INSENSITIVE); private static final Pattern oldFieldFacetParamPattern = - Pattern.compile("^(?:"+OLD_PREFIX+")\\.([^\\.]+)\\.(?:"+FIELD_FACET+")\\.([^\\.]+)\\.("+FieldFacetParamParser.regexParamList+")$", Pattern.CASE_INSENSITIVE); + Pattern.compile("^(?:"+OLD_PREFIX+")\\.([^\\.]+)\\.(?:"+FIELD_FACET+")\\.(.*(?=\\.))\\.("+FieldFacetParamParser.regexParamList+")$", Pattern.CASE_INSENSITIVE); private static final Pattern oldRangeFacetParamPattern = - Pattern.compile("^(?:"+OLD_PREFIX+")\\.([^\\.]+)\\.(?:"+RANGE_FACET+")\\.([^\\.]+)\\.("+RangeFacetParamParser.regexParamList+")$", Pattern.CASE_INSENSITIVE); + Pattern.compile("^(?:"+OLD_PREFIX+")\\.([^\\.]+)\\.(?:"+RANGE_FACET+")\\.(.*(?=\\.))\\.("+RangeFacetParamParser.regexParamList+")$", Pattern.CASE_INSENSITIVE); private static final Pattern oldQueryFacetParamPattern = Pattern.compile("^(?:"+OLD_PREFIX+")\\.([^\\.]+)\\.(?:"+QUERY_FACET+")\\.([^\\.]+)\\.("+QUERY+")$", Pattern.CASE_INSENSITIVE); diff --git a/solr/contrib/analytics/src/test-files/solr/analytics/legacy/facetWithDottedFields.txt b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/facetWithDottedFields.txt new file mode 100644 index 00000000000..162cbbdc19a --- /dev/null +++ b/solr/contrib/analytics/src/test-files/solr/analytics/legacy/facetWithDottedFields.txt @@ -0,0 +1,16 @@ +o.df1.s.mean=mean(long.dotfield) +o.df1.ff=long.dotfield +o.df1.ff.long.dotfield.ss=mean +o.df1.ff.long.dotfield.sd=asc + +o.df2.s.count=count(long.dotfield) +o.df2.rf=long.dotfield +o.df2.rf.long.dotfield.st=5 +o.df2.rf.long.dotfield.end=30 +o.df2.rf.long.dotfield.hardend=True +o.df2.rf.long.dotfield.g=5 +o.df2.rf.long.dotfield.ib=lower +o.df2.rf.long.dotfield.or=all + + + diff --git a/solr/contrib/analytics/src/test-files/solr/collection1/conf/schema-analytics.xml b/solr/contrib/analytics/src/test-files/solr/collection1/conf/schema-analytics.xml index 65704168817..deb282f498b 100644 --- a/solr/contrib/analytics/src/test-files/solr/collection1/conf/schema-analytics.xml +++ b/solr/contrib/analytics/src/test-files/solr/collection1/conf/schema-analytics.xml @@ -62,6 +62,8 @@ + + diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/util/OldAnalyticsRequestConverterUnitTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/util/OldAnalyticsRequestConverterUnitTest.java new file mode 100644 index 00000000000..d7a2b4765b0 --- /dev/null +++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/util/OldAnalyticsRequestConverterUnitTest.java @@ -0,0 +1,64 @@ +/* + * 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.analytics.util; + +import org.apache.solr.analytics.legacy.facet.LegacyAbstractAnalyticsFacetTest; +import org.apache.solr.common.params.SolrParams; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.apache.solr.analytics.AnalyticsRequestParser.AnalyticsExpressionSortRequest; +import static org.apache.solr.analytics.AnalyticsRequestParser.AnalyticsRequest; +import static org.apache.solr.analytics.AnalyticsRequestParser.AnalyticsValueFacetRequest; + +import org.apache.solr.analytics.AnalyticsRequestParser.AnalyticsFacetRequest; +import org.apache.solr.analytics.AnalyticsRequestParser.AnalyticsRangeFacetRequest; + +public class OldAnalyticsRequestConverterUnitTest extends LegacyAbstractAnalyticsFacetTest { + String fileName = "facetWithDottedFields.txt"; + + @BeforeClass + public static void beforeClass() throws Exception { + initCore("solrconfig-analytics.xml", "schema-analytics.xml"); + } + + @Test + public void testConvertFieldFacetWithDottedField() throws Exception { + SolrParams params = request(fileToStringArr(OldAnalyticsRequestConverterUnitTest.class, fileName)).getParams(); + AnalyticsRequest request = OldAnalyticsRequestConverter.convert(params); + final AnalyticsValueFacetRequest analyticsValueFacetRequest = (AnalyticsValueFacetRequest) request.groupings.get("df1").facets.get("long.dotfield"); + assertNotNull("Sort param should be parsed for dotted field", analyticsValueFacetRequest.sort); + final AnalyticsExpressionSortRequest analyticsExpressionSortRequest = (AnalyticsExpressionSortRequest) analyticsValueFacetRequest.sort.criteria.get(0); + assertEquals("Sort param expression should be parsed for dotted field", + "mean", analyticsExpressionSortRequest.expression); + assertEquals("Sort param direction should be parsed for dotted field", + "asc", analyticsExpressionSortRequest.direction); + } + + @Test + public void testConvertRangeFacetWithDottedField() throws Exception { + SolrParams params = request(fileToStringArr(OldAnalyticsRequestConverterUnitTest.class, fileName)).getParams(); + AnalyticsRequest request = OldAnalyticsRequestConverter.convert(params); + + final AnalyticsFacetRequest analyticsFacetRequest = request.groupings.get("df2").facets.get("long.dotfield"); + assertNotNull("Range facet param should be parsed for dotted field", analyticsFacetRequest); + assertEquals("30", ((AnalyticsRangeFacetRequest)analyticsFacetRequest).end); + assertEquals(true, ((AnalyticsRangeFacetRequest)analyticsFacetRequest).hardend); + + } +}