diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 69f764bb4e4..896b1435c30 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -556,6 +556,8 @@ Other Changes * SOLR-8566: various initialCapacity tweaks (Fix Versions: trunk 5.5) (Christine Poerschke) +* SOLR-8565: add & use CommonParams.(ROWS|START)_DEFAULT constants (Christine Poerschke) + ================== 5.4.1 ================== Bug Fixes diff --git a/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java b/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java index 5c9d930acda..9040a26887f 100644 --- a/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java @@ -166,8 +166,8 @@ public class MoreLikeThisHandler extends RequestHandlerBase } } - int start = params.getInt(CommonParams.START, 0); - int rows = params.getInt(CommonParams.ROWS, 10); + int start = params.getInt(CommonParams.START, CommonParams.START_DEFAULT); + int rows = params.getInt(CommonParams.ROWS, CommonParams.ROWS_DEFAULT); // Find documents MoreLikeThis - either with a reader or a query // -------------------------------------------------------------------------------- diff --git a/solr/core/src/java/org/apache/solr/search/QParser.java b/solr/core/src/java/org/apache/solr/search/QParser.java index 0df1c84b17d..85bd2f05e1d 100644 --- a/solr/core/src/java/org/apache/solr/search/QParser.java +++ b/solr/core/src/java/org/apache/solr/search/QParser.java @@ -241,8 +241,8 @@ public abstract class QParser { } } - int start = startS != null ? Integer.parseInt(startS) : 0; - int rows = rowsS != null ? Integer.parseInt(rowsS) : 10; + int start = startS != null ? Integer.parseInt(startS) : CommonParams.START_DEFAULT; + int rows = rowsS != null ? Integer.parseInt(rowsS) : CommonParams.ROWS_DEFAULT; SortSpec sort = SortSpecParsing.parseSortSpec(sortStr, req); diff --git a/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java index 8c8cd29f525..046d28b7d36 100644 --- a/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java +++ b/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java @@ -90,8 +90,8 @@ public class ReRankQParserPlugin extends QParserPlugin { double reRankWeight = localParams.getDouble("reRankWeight",2.0d); - int start = params.getInt(CommonParams.START,0); - int rows = params.getInt(CommonParams.ROWS,10); + int start = params.getInt(CommonParams.START,CommonParams.START_DEFAULT); + int rows = params.getInt(CommonParams.ROWS,CommonParams.ROWS_DEFAULT); int length = start+rows; return new ReRankQuery(reRankQuery, reRankDocs, reRankWeight, length); } diff --git a/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java b/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java index 38db7ce123d..b3a563fceba 100644 --- a/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java +++ b/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java @@ -62,9 +62,11 @@ public interface CommonParams { /** zero based offset of matching documents to retrieve */ public static final String START ="start"; + public static final int START_DEFAULT = 0; /** number of documents to return starting at "start" */ public static final String ROWS ="rows"; + public static final int ROWS_DEFAULT = 10; // SOLR-4228 start /** handler value for SolrPing */ diff --git a/solr/solrj/src/java/org/apache/solr/common/params/TermsParams.java b/solr/solrj/src/java/org/apache/solr/common/params/TermsParams.java index 9558efc3a8d..ffb196f7937 100644 --- a/solr/solrj/src/java/org/apache/solr/common/params/TermsParams.java +++ b/solr/solrj/src/java/org/apache/solr/common/params/TermsParams.java @@ -63,7 +63,7 @@ public interface TermsParams { public static final String TERMS_LOWER_INCLUSIVE = TERMS_PREFIX + "lower.incl"; /** - * Optional. The number of results to return. If not specified, looks for {@link org.apache.solr.common.params.CommonParams#ROWS}. If that's not specified, uses 10. + * Optional. The number of results to return. If not specified, looks for {@link org.apache.solr.common.params.CommonParams#ROWS}. If that's not specified, uses {@link org.apache.solr.common.params.CommonParams#ROWS_DEFAULT}. */ public static final String TERMS_LIMIT = TERMS_PREFIX + "limit"; diff --git a/solr/solrj/src/test/org/apache/solr/common/params/CommonParamsTest.java b/solr/solrj/src/test/org/apache/solr/common/params/CommonParamsTest.java new file mode 100755 index 00000000000..70c389488cd --- /dev/null +++ b/solr/solrj/src/test/org/apache/solr/common/params/CommonParamsTest.java @@ -0,0 +1,35 @@ +/* + * 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.common.params; + +import org.apache.lucene.util.LuceneTestCase; + +/** + * Unit test for {@link CommonParams} + * + * This class tests backwards compatibility of CommonParams parameter constants. + * If someone accidentally changes those constants then this test will flag that up. + */ +public class CommonParamsTest extends LuceneTestCase +{ + public void testStart() { assertEquals(CommonParams.START, "start"); } + public void testStartDefault() { assertEquals(CommonParams.START_DEFAULT, 0); } + + public void testRows() { assertEquals(CommonParams.ROWS, "rows"); } + public void testRowsDefault() { assertEquals(CommonParams.ROWS_DEFAULT, 10); } +}