lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r1032446 - in /lucene/dev/trunk/solr: ./ contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/ src/common/org/apache/solr/common/util/
Date Mon, 08 Nov 2010 02:29:24 GMT
Author: koji
Date: Mon Nov  8 02:29:24 2010
New Revision: 1032446

URL: http://svn.apache.org/viewvc?rev=1032446&view=rev
Log:
SOLR-2221: DIH: use StrUtils.parseBool() to get values of boolean options

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImportHandler.java
    lucene/dev/trunk/solr/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImporter.java
    lucene/dev/trunk/solr/src/common/org/apache/solr/common/util/StrUtils.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1032446&r1=1032445&r2=1032446&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Mon Nov  8 02:29:24 2010
@@ -545,6 +545,10 @@ Bug Fixes
   (Drew Farris via koji)
 
 * SOLR-1973: Empty fields in XML update messages confuse DataImportHandler. (koji)
+
+* SOLR-2221: Use StrUtils.parseBool() to get values of boolean options in DIH.
+  true/on/yes (for TRUE) and false/off/no (for FALSE) can be used for sub-options
+  (debug, verbose, synchronous, commit, clean, optimize) for full/delta-import commands.
(koji)
   
 Other Changes
 ----------------------

Modified: lucene/dev/trunk/solr/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImportHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImportHandler.java?rev=1032446&r1=1032445&r2=1032446&view=diff
==============================================================================
--- lucene/dev/trunk/solr/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImportHandler.java
(original)
+++ lucene/dev/trunk/solr/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImportHandler.java
Mon Nov  8 02:29:24 2010
@@ -26,6 +26,7 @@ import org.apache.solr.common.params.Upd
 import org.apache.solr.common.util.ContentStreamBase;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.ContentStream;
+import org.apache.solr.common.util.StrUtils;
 import org.apache.solr.core.SolrConfig;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.core.SolrResourceLoader;
@@ -101,9 +102,7 @@ public class DataImportHandler extends R
           myName = myName.replaceAll("/","_") ;
         }
       }
-      String debug = (String) initArgs.get(ENABLE_DEBUG);
-      if (debug != null && "no".equals(debug))
-        debugEnabled = false;
+      debugEnabled = StrUtils.parseBool((String)initArgs.get(ENABLE_DEBUG), true);
       NamedList defaults = (NamedList) initArgs.get("defaults");
       if (defaults != null) {
         String configLoc = (String) defaults.get("config");

Modified: lucene/dev/trunk/solr/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImporter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImporter.java?rev=1032446&r1=1032445&r2=1032446&view=diff
==============================================================================
--- lucene/dev/trunk/solr/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImporter.java
(original)
+++ lucene/dev/trunk/solr/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImporter.java
Mon Nov  8 02:29:24 2010
@@ -22,6 +22,7 @@ import org.apache.solr.core.SolrCore;
 import org.apache.solr.schema.IndexSchema;
 import org.apache.solr.schema.SchemaField;
 import org.apache.solr.common.util.ContentStream;
+import org.apache.solr.common.util.StrUtils;
 
 import static org.apache.solr.handler.dataimport.DataImportHandlerException.wrapAndThrow;
 import static org.apache.solr.handler.dataimport.DataImportHandlerException.SEVERE;
@@ -498,29 +499,28 @@ public class DataImporter {
       if (requestParams.containsKey("command"))
         command = (String) requestParams.get("command");
 
-      if ("on".equals(requestParams.get("debug"))) {
+      if (StrUtils.parseBool((String)requestParams.get("debug"),false)) {
         debug = true;
         rows = 10;
         // Set default values suitable for debug mode
         commit = false;
         clean = false;
-        verbose = "true".equals(requestParams.get("verbose"))
-                || "on".equals(requestParams.get("verbose"));
+        verbose = StrUtils.parseBool((String)requestParams.get("verbose"),false);
       }
-      syncMode = "true".equals(requestParams.get("synchronous"));
+      syncMode = StrUtils.parseBool((String)requestParams.get("synchronous"),false);
       if (DELTA_IMPORT_CMD.equals(command) || IMPORT_CMD.equals(command)) {
         clean = false;
       }
       if (requestParams.containsKey("commit"))
-        commit = Boolean.parseBoolean((String) requestParams.get("commit"));
+        commit = StrUtils.parseBool((String) requestParams.get("commit"),true);
       if (requestParams.containsKey("start"))
         start = Integer.parseInt((String) requestParams.get("start"));
       if (requestParams.containsKey("rows"))
         rows = Integer.parseInt((String) requestParams.get("rows"));
       if (requestParams.containsKey("clean"))
-        clean = Boolean.parseBoolean((String) requestParams.get("clean"));
+        clean = StrUtils.parseBool((String) requestParams.get("clean"),true);
       if (requestParams.containsKey("optimize")) {
-        optimize = Boolean.parseBoolean((String) requestParams.get("optimize"));
+        optimize = StrUtils.parseBool((String) requestParams.get("optimize"),true);
         if (optimize)
           commit = true;
       }

Modified: lucene/dev/trunk/solr/src/common/org/apache/solr/common/util/StrUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/common/org/apache/solr/common/util/StrUtils.java?rev=1032446&r1=1032445&r2=1032446&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/common/org/apache/solr/common/util/StrUtils.java (original)
+++ lucene/dev/trunk/solr/src/common/org/apache/solr/common/util/StrUtils.java Mon Nov  8
02:29:24 2010
@@ -239,6 +239,24 @@ public class StrUtils {
   }
 
   /**
+   * {@link NullPointerException} and {@link SolrException} free version of {@link #parseBool(String)}
+   * @param s
+   * @param def
+   * @return
+   */
+  public static boolean parseBool(String s, boolean def) {
+    if( s != null ) {
+      if( s.startsWith("true") || s.startsWith("on") || s.startsWith("yes") ) {
+        return true;
+      }
+      if( s.startsWith("false") || s.startsWith("off") || s.equals("no") ) {
+        return false;
+      }
+    }
+    return def;
+  }
+  
+  /**
    * URLEncodes a value, replacing only enough chars so that
    * the URL may be unambiguously pasted back into a browser.
    * <p>



Mime
View raw message