Author: otis
Date: Sat Jun 14 20:28:36 2008
New Revision: 667923

URL: http://svn.apache.org/viewvc?rev=667923&view=rev
Log:
SOLR-592: Added ShardParams interface and changed several string literals to 
references to constants in CommonParams.


Added:
    lucene/solr/trunk/src/java/org/apache/solr/common/params/ShardParams.java
Modified:
    lucene/solr/trunk/CHANGES.txt
    
lucene/solr/trunk/src/java/org/apache/solr/handler/component/FacetComponent.java
    
lucene/solr/trunk/src/java/org/apache/solr/handler/component/QueryComponent.java
    
lucene/solr/trunk/src/java/org/apache/solr/handler/component/SearchHandler.java

Modified: lucene/solr/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=667923&r1=667922&r2=667923&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Sat Jun 14 20:28:36 2008
@@ -478,6 +478,10 @@
 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:

Added: lucene/solr/trunk/src/java/org/apache/solr/common/params/ShardParams.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/common/params/ShardParams.java?rev=667923&view=auto
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/common/params/ShardParams.java 
(added)
+++ lucene/solr/trunk/src/java/org/apache/solr/common/params/ShardParams.java 
Sat Jun 14 20:28:36 2008
@@ -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";
+}

Modified: 
lucene/solr/trunk/src/java/org/apache/solr/handler/component/FacetComponent.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/component/FacetComponent.java?rev=667923&r1=667922&r2=667923&view=diff
==============================================================================
--- 
lucene/solr/trunk/src/java/org/apache/solr/handler/component/FacetComponent.java
 (original)
+++ 
lucene/solr/trunk/src/java/org/apache/solr/handler/component/FacetComponent.java
 Sat Jun 14 20:28:36 2008
@@ -21,6 +21,7 @@
 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 @@
           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;

Modified: 
lucene/solr/trunk/src/java/org/apache/solr/handler/component/QueryComponent.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/component/QueryComponent.java?rev=667923&r1=667922&r2=667923&view=diff
==============================================================================
--- 
lucene/solr/trunk/src/java/org/apache/solr/handler/component/QueryComponent.java
 (original)
+++ 
lucene/solr/trunk/src/java/org/apache/solr/handler/component/QueryComponent.java
 Sat Jun 14 20:28:36 2008
@@ -28,6 +28,7 @@
 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 @@
       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<Query> filters = rb.getFilters();
         if (filters==null) {
@@ -100,7 +101,7 @@
     }
 
     // TODO: temporary... this should go in a different component.
-    String shards = params.get("shards");
+    String shards = params.get(ShardParams.SHARDS);
     if (shards != null) {
       List<String> lst = StrUtils.splitSmart(shards, ",", true);
       rb.shards = lst.toArray(new String[lst.size()]);
@@ -122,7 +123,7 @@
     // 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<String> idArr = StrUtils.splitSmart(ids, ",", true);
@@ -235,7 +236,7 @@
     }
 
     //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 @@
     // 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 @@
     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 @@
       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<String> ids = new ArrayList<String>(shardDocs.size());
@@ -488,7 +489,7 @@
         // 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);
     }

Modified: 
lucene/solr/trunk/src/java/org/apache/solr/handler/component/SearchHandler.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/component/SearchHandler.java?rev=667923&r1=667922&r2=667923&view=diff
==============================================================================
--- 
lucene/solr/trunk/src/java/org/apache/solr/handler/component/SearchHandler.java 
(original)
+++ 
lucene/solr/trunk/src/java/org/apache/solr/handler/component/SearchHandler.java 
Sat Jun 14 20:28:36 2008
@@ -23,6 +23,7 @@
 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 @@
             // 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 @@
           // 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");


Reply via email to