lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r923109 - in /lucene/solr/branches/solr/src/java/org/apache/solr: analysis/BaseTokenFilterFactory.java analysis/BaseTokenStreamFactory.java analysis/BaseTokenizerFactory.java analysis/StandardTokenizerFactory.java schema/IndexSchema.java
Date Mon, 15 Mar 2010 08:09:34 GMT
Author: uschindler
Date: Mon Mar 15 08:09:34 2010
New Revision: 923109

URL: http://svn.apache.org/viewvc?rev=923109&view=rev
Log:
SOLR-1677: Code cleanup (heavy duplication removal) and more checks.

Added:
    lucene/solr/branches/solr/src/java/org/apache/solr/analysis/BaseTokenStreamFactory.java
  (with props)
Modified:
    lucene/solr/branches/solr/src/java/org/apache/solr/analysis/BaseTokenFilterFactory.java
    lucene/solr/branches/solr/src/java/org/apache/solr/analysis/BaseTokenizerFactory.java
    lucene/solr/branches/solr/src/java/org/apache/solr/analysis/StandardTokenizerFactory.java
    lucene/solr/branches/solr/src/java/org/apache/solr/schema/IndexSchema.java

Modified: lucene/solr/branches/solr/src/java/org/apache/solr/analysis/BaseTokenFilterFactory.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/solr/src/java/org/apache/solr/analysis/BaseTokenFilterFactory.java?rev=923109&r1=923108&r2=923109&view=diff
==============================================================================
--- lucene/solr/branches/solr/src/java/org/apache/solr/analysis/BaseTokenFilterFactory.java
(original)
+++ lucene/solr/branches/solr/src/java/org/apache/solr/analysis/BaseTokenFilterFactory.java
Mon Mar 15 08:09:34 2010
@@ -17,71 +17,14 @@
 
 package org.apache.solr.analysis;
 
-import org.apache.solr.core.Config;
-import org.apache.solr.schema.IndexSchema;
-
-import java.util.Map;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.apache.lucene.util.Version;
-
 
 /**
  * Simple abstract implementation that handles init arg processing.
  * 
  * @version $Id$
  */
-public abstract class BaseTokenFilterFactory implements TokenFilterFactory {
+public abstract class BaseTokenFilterFactory extends BaseTokenStreamFactory implements TokenFilterFactory
{
   public static final Logger log = LoggerFactory.getLogger(BaseTokenFilterFactory.class);
-  
-  /** The init args */
-  protected Map<String,String> args;
-  
-  /** the luceneVersion arg */
-  protected Version luceneMatchVersion = null;
-
-  public void init(Map<String,String> args) {
-    this.args=args;
-    String matchVersion = args.get(IndexSchema.LUCENE_MATCH_VERSION_PARAM);
-    if (matchVersion != null) {
-      luceneMatchVersion = Config.parseLuceneVersionString(matchVersion);
-    }
-  }
-
-  public Map<String,String> getArgs() {
-    return args;
-  }
-
-  // TODO: move these somewhere that tokenizers and others
-  // can also use them...
-  protected int getInt(String name) {
-    return getInt(name,-1,false);
-  }
-
-  protected int getInt(String name, int defaultVal) {
-    return getInt(name,defaultVal,true);
-  }
-
-  protected int getInt(String name, int defaultVal, boolean useDefault) {
-    String s = args.get(name);
-    if (s==null) {
-      if (useDefault) return defaultVal;
-      throw new RuntimeException("Configuration Error: missing parameter '" + name + "'");
-    }
-    return Integer.parseInt(s);
-  }
-
-  protected boolean getBoolean(String name, boolean defaultVal) {
-    return getBoolean(name,defaultVal,true);
-  }
-
-  protected boolean getBoolean(String name, boolean defaultVal, boolean useDefault) {
-    String s = args.get(name);
-    if (s==null) {
-      if (useDefault) return defaultVal;
-      throw new RuntimeException("Configuration Error: missing parameter '" + name + "'");
-    }
-    return Boolean.parseBoolean(s);
-  }
-
 }

Added: lucene/solr/branches/solr/src/java/org/apache/solr/analysis/BaseTokenStreamFactory.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/solr/src/java/org/apache/solr/analysis/BaseTokenStreamFactory.java?rev=923109&view=auto
==============================================================================
--- lucene/solr/branches/solr/src/java/org/apache/solr/analysis/BaseTokenStreamFactory.java
(added)
+++ lucene/solr/branches/solr/src/java/org/apache/solr/analysis/BaseTokenStreamFactory.java
Mon Mar 15 08:09:34 2010
@@ -0,0 +1,97 @@
+/**
+ * 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.analysis;
+
+import org.apache.solr.core.Config;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.schema.IndexSchema;
+
+import java.util.Map;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.lucene.util.Version;
+
+
+/**
+ * Simple abstract implementation that handles init arg processing, is not really
+ * a factory as it implements no interface, but removes code duplication
+ * in its subclasses.
+ * 
+ * @version $Id$
+ */
+abstract class BaseTokenStreamFactory {
+  /** The init args */
+  protected Map<String,String> args;
+  
+  /** the luceneVersion arg */
+  protected Version luceneMatchVersion = null;
+
+  public void init(Map<String,String> args) {
+    this.args=args;
+    String matchVersion = args.get(IndexSchema.LUCENE_MATCH_VERSION_PARAM);
+    if (matchVersion != null) {
+      luceneMatchVersion = Config.parseLuceneVersionString(matchVersion);
+    }
+  }
+
+  public Map<String,String> getArgs() {
+    return args;
+  }
+  
+  /** this method can be called in the {@link #create} method,
+   * to inform user, that for this factory a {@link #luceneMatchVersion} is required */
+  protected final void assureMatchVersion() {
+    if (luceneMatchVersion == null) {
+      throw new RuntimeException("Configuration Error: Factory '" + this.getClass().getName()
+
+        "' needs a 'luceneMatchVersion' parameter");
+    }
+  }
+
+  // TODO: move these somewhere that tokenizers and others
+  // can also use them...
+  protected int getInt(String name) {
+    return getInt(name,-1,false);
+  }
+
+  protected int getInt(String name, int defaultVal) {
+    return getInt(name,defaultVal,true);
+  }
+
+  protected int getInt(String name, int defaultVal, boolean useDefault) {
+    String s = args.get(name);
+    if (s==null) {
+      if (useDefault) return defaultVal;
+      throw new RuntimeException("Configuration Error: missing parameter '" + name + "'");
+    }
+    return Integer.parseInt(s);
+  }
+
+  protected boolean getBoolean(String name, boolean defaultVal) {
+    return getBoolean(name,defaultVal,true);
+  }
+
+  protected boolean getBoolean(String name, boolean defaultVal, boolean useDefault) {
+    String s = args.get(name);
+    if (s==null) {
+      if (useDefault) return defaultVal;
+      throw new RuntimeException("Configuration Error: missing parameter '" + name + "'");
+    }
+    return Boolean.parseBoolean(s);
+  }
+
+}

Propchange: lucene/solr/branches/solr/src/java/org/apache/solr/analysis/BaseTokenStreamFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/solr/branches/solr/src/java/org/apache/solr/analysis/BaseTokenStreamFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: lucene/solr/branches/solr/src/java/org/apache/solr/analysis/BaseTokenizerFactory.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/solr/src/java/org/apache/solr/analysis/BaseTokenizerFactory.java?rev=923109&r1=923108&r2=923109&view=diff
==============================================================================
--- lucene/solr/branches/solr/src/java/org/apache/solr/analysis/BaseTokenizerFactory.java
(original)
+++ lucene/solr/branches/solr/src/java/org/apache/solr/analysis/BaseTokenizerFactory.java
Mon Mar 15 08:09:34 2010
@@ -17,38 +17,14 @@
 
 package org.apache.solr.analysis;
 
-import org.apache.solr.core.Config;
-import org.apache.solr.schema.IndexSchema;
-
-import java.util.Map;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.apache.lucene.util.Version;
-
 
 /**
  * Simple abstract implementation that handles init arg processing.
  * 
  * @version $Id$
  */
-public abstract class BaseTokenizerFactory implements TokenizerFactory {
+public abstract class BaseTokenizerFactory extends BaseTokenStreamFactory implements TokenizerFactory
{
   public static final Logger log = LoggerFactory.getLogger(BaseTokenizerFactory.class);
-  
-  /** The init args */
-  protected Map<String,String> args;
-  
-  /** the luceneVersion arg */
-  protected Version luceneMatchVersion = null;
-
-  public void init(Map<String,String> args) {
-    this.args=args;
-    String matchVersion = args.get(IndexSchema.LUCENE_MATCH_VERSION_PARAM);
-    if (matchVersion != null) {
-      luceneMatchVersion = Config.parseLuceneVersionString(matchVersion);
-    }
-  }
-  
-  public Map<String,String> getArgs() {
-    return args;
-  }
 }

Modified: lucene/solr/branches/solr/src/java/org/apache/solr/analysis/StandardTokenizerFactory.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/solr/src/java/org/apache/solr/analysis/StandardTokenizerFactory.java?rev=923109&r1=923108&r2=923109&view=diff
==============================================================================
--- lucene/solr/branches/solr/src/java/org/apache/solr/analysis/StandardTokenizerFactory.java
(original)
+++ lucene/solr/branches/solr/src/java/org/apache/solr/analysis/StandardTokenizerFactory.java
Mon Mar 15 08:09:34 2010
@@ -28,6 +28,7 @@ import java.io.Reader;
 
 public class StandardTokenizerFactory extends BaseTokenizerFactory {
   public StandardTokenizer create(Reader input) {
+    assureMatchVersion();
     return new StandardTokenizer(luceneMatchVersion, input);
   }
 }

Modified: lucene/solr/branches/solr/src/java/org/apache/solr/schema/IndexSchema.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/solr/src/java/org/apache/solr/schema/IndexSchema.java?rev=923109&r1=923108&r2=923109&view=diff
==============================================================================
--- lucene/solr/branches/solr/src/java/org/apache/solr/schema/IndexSchema.java (original)
+++ lucene/solr/branches/solr/src/java/org/apache/solr/schema/IndexSchema.java Mon Mar 15
08:09:34 2010
@@ -830,6 +830,11 @@ public final class IndexSchema {
           final String matchVersionStr = DOMUtil.getAttr(attrs, LUCENE_MATCH_VERSION_PARAM);
           final Version luceneMatchVersion = (matchVersionStr == null) ?
             solrConfig.luceneMatchVersion : Config.parseLuceneVersionString(matchVersionStr);
+          if (luceneMatchVersion == null) {
+            throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,
+              "Configuration Error: Analyzer '" + clazz.getName() +
+              "' needs a 'luceneMatchVersion' parameter");
+          }
           return cnstr.newInstance(luceneMatchVersion);
         } catch (NoSuchMethodException nsme) {
           // otherwise use default ctor



Mime
View raw message