SOLR-592: Added ShardParams interface and changed several string literals to references to constants in CommonParams.

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@667923 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Otis Gospodnetic 2008-06-15 03:28:36 +00:00
parent 97da4bab73
commit 96d68357d6
5 changed files with 65 additions and 23 deletions

View File

@ -478,6 +478,10 @@ Other Changes
14. SOLR-518: Changed luke.xsl to use divs w/css for generating histograms 14. SOLR-518: Changed luke.xsl to use divs w/css for generating histograms
instead of SVG (Thomas Peuss via hossman) 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 Build
1. SOLR-411. Changed the names of the Solr JARs to use the defacto standard JAR names based on 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: project-name-version.jar. This yields, for example:

View File

@ -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";
}

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.*; import java.util.*;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.FacetParams; import org.apache.solr.common.params.FacetParams;
import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.ModifiableSolrParams;
@ -115,8 +116,8 @@ public class FacetComponent extends SearchComponent
refine.shards = new String[]{rb.shards[shardNum]}; refine.shards = new String[]{rb.shards[shardNum]};
refine.params = new ModifiableSolrParams(rb.req.getParams()); refine.params = new ModifiableSolrParams(rb.req.getParams());
// don't request any documents // don't request any documents
refine.params.remove("start"); refine.params.remove(CommonParams.START);
refine.params.set("rows","0"); refine.params.set(CommonParams.ROWS,"0");
} }
refine.purpose |= ShardRequest.PURPOSE_REFINE_FACETS; refine.purpose |= ShardRequest.PURPOSE_REFINE_FACETS;

View File

@ -28,6 +28,7 @@ import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams; 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.params.SolrParams;
import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.StrUtils; import org.apache.solr.common.util.StrUtils;
@ -81,7 +82,7 @@ public class QueryComponent extends SearchComponent
rb.setQuery( parser.getQuery() ); rb.setQuery( parser.getQuery() );
rb.setSortSpec( parser.getSort(true) ); 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) { if (fqs!=null && fqs.length!=0) {
List<Query> filters = rb.getFilters(); List<Query> filters = rb.getFilters();
if (filters==null) { if (filters==null) {
@ -100,7 +101,7 @@ public class QueryComponent extends SearchComponent
} }
// TODO: temporary... this should go in a different component. // TODO: temporary... this should go in a different component.
String shards = params.get("shards"); String shards = params.get(ShardParams.SHARDS);
if (shards != null) { if (shards != null) {
List<String> lst = StrUtils.splitSmart(shards, ",", true); List<String> lst = StrUtils.splitSmart(shards, ",", true);
rb.shards = lst.toArray(new String[lst.size()]); 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 // a filter that lists the ids... that would be transparent to
// the request handler, but would be more expensive (and would preserve score // the request handler, but would be more expensive (and would preserve score
// too if desired). // too if desired).
String ids = params.get("ids"); String ids = params.get(ShardParams.IDS);
if (ids != null) { if (ids != null) {
SchemaField idField = req.getSchema().getUniqueKeyField(); SchemaField idField = req.getSchema().getUniqueKeyField();
List<String> idArr = StrUtils.splitSmart(ids, ",", true); List<String> idArr = StrUtils.splitSmart(ids, ",", true);
@ -235,7 +236,7 @@ public class QueryComponent extends SearchComponent
} }
//pre-fetch returned documents //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?) // TODO: this may depend on the highlighter component (or other components?)
SolrPluginUtils.optimizePreFetchDocs(rb.getResults().docList, rb.getQuery(), req, rsp); 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? // TODO: base on current params or original params?
// don't pass through any shards param // 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 // set the start (offset) to 0 for each shard request so we can properly merge
// results from the start. // 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 // 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? // perhaps we shouldn't attempt to parse the query at this level?
// Alternate Idea: instead of specifying all these things at the upper level, // Alternate Idea: instead of specifying all these things at the upper level,
// we could just specify that this is a shard request. // 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 // 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"); sreq.params.set(ResponseBuilder.FIELD_SORT_VALUES,"true");
if (rb.getSortSpec().includesScore()) { 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 { } else {
sreq.params.set("fl", rb.req.getSchema().getUniqueKeyField().getName()); sreq.params.set(CommonParams.FL, rb.req.getSchema().getUniqueKeyField().getName());
} }
rb.addRequest(this, sreq); rb.addRequest(this, sreq);
@ -472,15 +473,15 @@ public class QueryComponent extends SearchComponent
sreq.params.add( rb.req.getParams()); sreq.params.add( rb.req.getParams());
// no need for a sort, we already have order // 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 // we already have the field sort values
sreq.params.remove(ResponseBuilder.FIELD_SORT_VALUES); sreq.params.remove(ResponseBuilder.FIELD_SORT_VALUES);
// make sure that the id is returned for correlation // 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) { if (fl != null) {
sreq.params.set("fl", fl+','+uniqueField.getName()); sreq.params.set(CommonParams.FL, fl+','+uniqueField.getName());
} }
ArrayList<String> ids = new ArrayList<String>(shardDocs.size()); ArrayList<String> ids = new ArrayList<String>(shardDocs.size());
@ -488,7 +489,7 @@ public class QueryComponent extends SearchComponent
// TODO: depending on the type, we may need more tha a simple toString()? // TODO: depending on the type, we may need more tha a simple toString()?
ids.add(shardDoc.id.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); rb.addRequest(this, sreq);
} }

View File

@ -23,6 +23,7 @@ import org.apache.solr.common.util.RTimer;
import org.apache.solr.common.util.SimpleOrderedMap; import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.ShardParams;
import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException;
import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryResponse; import org.apache.solr.request.SolrQueryResponse;
@ -210,15 +211,15 @@ public class SearchHandler extends RequestHandlerBase implements SolrCoreAware
// TODO: map from shard to address[] // TODO: map from shard to address[]
for (String shard : sreq.actualShards) { for (String shard : sreq.actualShards) {
ModifiableSolrParams params = new ModifiableSolrParams(sreq.params); 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("indent");
params.remove("echoParams"); params.remove(CommonParams.HEADER_ECHO_PARAMS);
params.set("isShard", true); // a sub (shard) request params.set(ShardParams.IS_SHARD, true); // a sub (shard) request
String shardHandler = req.getParams().get("shards.qt"); String shardHandler = req.getParams().get(ShardParams.SHARDS_QT);
if (shardHandler == null) { if (shardHandler == null) {
params.remove("qt"); params.remove(CommonParams.QT);
} else { } else {
params.set("qt", shardHandler); params.set(CommonParams.QT, shardHandler);
} }
comm.submit(sreq, shard, params); comm.submit(sreq, shard, params);
} }
@ -355,8 +356,8 @@ class HttpCommComponent {
// String url = "http://" + shard + "/select"; // String url = "http://" + shard + "/select";
String url = "http://" + shard; String url = "http://" + shard;
params.remove("wt"); // use default (or should we explicitly set it?) params.remove(CommonParams.WT); // use default (or should we explicitly set it?)
params.remove("version"); params.remove(CommonParams.VERSION);
SolrServer server = new CommonsHttpSolrServer(url, client); SolrServer server = new CommonsHttpSolrServer(url, client);
// SolrRequest req = new QueryRequest(SolrRequest.METHOD.POST, "/select"); // SolrRequest req = new QueryRequest(SolrRequest.METHOD.POST, "/select");