diff --git a/CHANGES.txt b/CHANGES.txt index b9a73c4aac6..f11ff89c9f7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -478,6 +478,10 @@ Other Changes 14. SOLR-518: Changed luke.xsl to use divs w/css for generating histograms instead of SVG (Thomas Peuss via hossman) +15. SOLR-592: Added ShardParams interface and changed several string literals + to references to constants in CommonParams. + (Lars Kotthoff via Otis Gospodnetic) + Build 1. SOLR-411. Changed the names of the Solr JARs to use the defacto standard JAR names based on project-name-version.jar. This yields, for example: diff --git a/src/java/org/apache/solr/common/params/ShardParams.java b/src/java/org/apache/solr/common/params/ShardParams.java new file mode 100644 index 00000000000..e929c0c98a9 --- /dev/null +++ b/src/java/org/apache/solr/common/params/ShardParams.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; + +/** + * Parameters used for distributed search. + */ +public interface ShardParams { + /** the shards to use (distributed configuration) */ + public static final String SHARDS = "shards"; + + /** IDs of the shard documents */ + public static final String IDS = "ids"; + + /** whether the request goes to a shard */ + public static final String IS_SHARD = "isShard"; + + /** query type for shard requests */ + public static final String SHARDS_QT = "shards.qt"; +} diff --git a/src/java/org/apache/solr/handler/component/FacetComponent.java b/src/java/org/apache/solr/handler/component/FacetComponent.java index fb672361dcd..4afadbfce16 100644 --- a/src/java/org/apache/solr/handler/component/FacetComponent.java +++ b/src/java/org/apache/solr/handler/component/FacetComponent.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.net.URL; import java.util.*; +import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.FacetParams; import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.params.ModifiableSolrParams; @@ -115,8 +116,8 @@ public class FacetComponent extends SearchComponent refine.shards = new String[]{rb.shards[shardNum]}; refine.params = new ModifiableSolrParams(rb.req.getParams()); // don't request any documents - refine.params.remove("start"); - refine.params.set("rows","0"); + refine.params.remove(CommonParams.START); + refine.params.set(CommonParams.ROWS,"0"); } refine.purpose |= ShardRequest.PURPOSE_REFINE_FACETS; diff --git a/src/java/org/apache/solr/handler/component/QueryComponent.java b/src/java/org/apache/solr/handler/component/QueryComponent.java index f1fe181d816..74aaac2d656 100644 --- a/src/java/org/apache/solr/handler/component/QueryComponent.java +++ b/src/java/org/apache/solr/handler/component/QueryComponent.java @@ -28,6 +28,7 @@ import org.apache.solr.common.SolrDocumentList; import org.apache.solr.common.SolrException; import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.ModifiableSolrParams; +import org.apache.solr.common.params.ShardParams; import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.StrUtils; @@ -81,7 +82,7 @@ public class QueryComponent extends SearchComponent rb.setQuery( parser.getQuery() ); rb.setSortSpec( parser.getSort(true) ); - String[] fqs = req.getParams().getParams(org.apache.solr.common.params.CommonParams.FQ); + String[] fqs = req.getParams().getParams(CommonParams.FQ); if (fqs!=null && fqs.length!=0) { List filters = rb.getFilters(); if (filters==null) { @@ -100,7 +101,7 @@ public class QueryComponent extends SearchComponent } // TODO: temporary... this should go in a different component. - String shards = params.get("shards"); + String shards = params.get(ShardParams.SHARDS); if (shards != null) { List lst = StrUtils.splitSmart(shards, ",", true); rb.shards = lst.toArray(new String[lst.size()]); @@ -122,7 +123,7 @@ public class QueryComponent extends SearchComponent // a filter that lists the ids... that would be transparent to // the request handler, but would be more expensive (and would preserve score // too if desired). - String ids = params.get("ids"); + String ids = params.get(ShardParams.IDS); if (ids != null) { SchemaField idField = req.getSchema().getUniqueKeyField(); List idArr = StrUtils.splitSmart(ids, ",", true); @@ -235,7 +236,7 @@ public class QueryComponent extends SearchComponent } //pre-fetch returned documents - if (!req.getParams().getBool("isShard",false) && rb.getResults().docList != null && rb.getResults().docList.size()<=50) { + if (!req.getParams().getBool(ShardParams.IS_SHARD,false) && rb.getResults().docList != null && rb.getResults().docList.size()<=50) { // TODO: this may depend on the highlighter component (or other components?) SolrPluginUtils.optimizePreFetchDocs(rb.getResults().docList, rb.getQuery(), req, rsp); } @@ -305,17 +306,17 @@ public class QueryComponent extends SearchComponent // TODO: base on current params or original params? // don't pass through any shards param - sreq.params.remove("shards"); + sreq.params.remove(ShardParams.SHARDS); // set the start (offset) to 0 for each shard request so we can properly merge // results from the start. - sreq.params.set("start","0"); + sreq.params.set(CommonParams.START, "0"); // TODO: should we even use the SortSpec? That's obtained from the QParser, and // perhaps we shouldn't attempt to parse the query at this level? // Alternate Idea: instead of specifying all these things at the upper level, // we could just specify that this is a shard request. - sreq.params.set("rows", rb.getSortSpec().getOffset() + rb.getSortSpec().getCount()); + sreq.params.set(CommonParams.ROWS, rb.getSortSpec().getOffset() + rb.getSortSpec().getCount()); // in this first phase, request only the unique key field @@ -323,9 +324,9 @@ public class QueryComponent extends SearchComponent sreq.params.set(ResponseBuilder.FIELD_SORT_VALUES,"true"); if (rb.getSortSpec().includesScore()) { - sreq.params.set("fl", rb.req.getSchema().getUniqueKeyField().getName() + ",score"); + sreq.params.set(CommonParams.FL, rb.req.getSchema().getUniqueKeyField().getName() + ",score"); } else { - sreq.params.set("fl", rb.req.getSchema().getUniqueKeyField().getName()); + sreq.params.set(CommonParams.FL, rb.req.getSchema().getUniqueKeyField().getName()); } rb.addRequest(this, sreq); @@ -472,15 +473,15 @@ public class QueryComponent extends SearchComponent sreq.params.add( rb.req.getParams()); // no need for a sort, we already have order - sreq.params.remove("sort"); + sreq.params.remove(CommonParams.SORT); // we already have the field sort values sreq.params.remove(ResponseBuilder.FIELD_SORT_VALUES); // make sure that the id is returned for correlation - String fl = sreq.params.get("fl"); + String fl = sreq.params.get(CommonParams.FL); if (fl != null) { - sreq.params.set("fl", fl+','+uniqueField.getName()); + sreq.params.set(CommonParams.FL, fl+','+uniqueField.getName()); } ArrayList ids = new ArrayList(shardDocs.size()); @@ -488,7 +489,7 @@ public class QueryComponent extends SearchComponent // TODO: depending on the type, we may need more tha a simple toString()? ids.add(shardDoc.id.toString()); } - sreq.params.add("ids", StrUtils.join(ids, ',')); + sreq.params.add(ShardParams.IDS, StrUtils.join(ids, ',')); rb.addRequest(this, sreq); } diff --git a/src/java/org/apache/solr/handler/component/SearchHandler.java b/src/java/org/apache/solr/handler/component/SearchHandler.java index f98d52f43f2..710e7a4e8bb 100644 --- a/src/java/org/apache/solr/handler/component/SearchHandler.java +++ b/src/java/org/apache/solr/handler/component/SearchHandler.java @@ -23,6 +23,7 @@ import org.apache.solr.common.util.RTimer; import org.apache.solr.common.util.SimpleOrderedMap; import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.ModifiableSolrParams; +import org.apache.solr.common.params.ShardParams; import org.apache.solr.common.SolrException; import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrQueryResponse; @@ -210,15 +211,15 @@ public class SearchHandler extends RequestHandlerBase implements SolrCoreAware // TODO: map from shard to address[] for (String shard : sreq.actualShards) { ModifiableSolrParams params = new ModifiableSolrParams(sreq.params); - params.remove("shards"); // not a top-level request + params.remove(ShardParams.SHARDS); // not a top-level request params.remove("indent"); - params.remove("echoParams"); - params.set("isShard", true); // a sub (shard) request - String shardHandler = req.getParams().get("shards.qt"); + params.remove(CommonParams.HEADER_ECHO_PARAMS); + params.set(ShardParams.IS_SHARD, true); // a sub (shard) request + String shardHandler = req.getParams().get(ShardParams.SHARDS_QT); if (shardHandler == null) { - params.remove("qt"); + params.remove(CommonParams.QT); } else { - params.set("qt", shardHandler); + params.set(CommonParams.QT, shardHandler); } comm.submit(sreq, shard, params); } @@ -355,8 +356,8 @@ class HttpCommComponent { // String url = "http://" + shard + "/select"; String url = "http://" + shard; - params.remove("wt"); // use default (or should we explicitly set it?) - params.remove("version"); + params.remove(CommonParams.WT); // use default (or should we explicitly set it?) + params.remove(CommonParams.VERSION); SolrServer server = new CommonsHttpSolrServer(url, client); // SolrRequest req = new QueryRequest(SolrRequest.METHOD.POST, "/select");