[ 
https://issues.apache.org/jira/browse/SOLR-813?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12640637#action_12640637
 ] 

Ryan McKinley commented on SOLR-813:
------------------------------------

rather then create a new Filter for DoubleMetaphone, why not just extend 
PhoneticFilter to support maxCodeLength?

Here is a quick untested bit that uses reflection to set the maxCodeLength -- 
the advantage is that it would also work for 'Metaphone' (though i'm not sure 
anyone uses that).

Since the reflection only happens once at starup, it is not a big deal.

{code:java}
Index: src/java/org/apache/solr/analysis/PhoneticFilterFactory.java
===================================================================
--- src/java/org/apache/solr/analysis/PhoneticFilterFactory.java        
(revision 704289)
+++ src/java/org/apache/solr/analysis/PhoneticFilterFactory.java        
(working copy)
@@ -17,10 +17,10 @@
 
 package org.apache.solr.analysis;
 
+import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.solr.core.SolrConfig;
 import org.apache.commons.codec.Encoder;
 import org.apache.commons.codec.language.DoubleMetaphone;
 import org.apache.commons.codec.language.Metaphone;
@@ -80,6 +80,13 @@
     
     try {
       encoder = clazz.newInstance();
+      
+      // Try to set the maxCodeLength
+      String v = args.get( "maxCodeLength" );
+      if( v != null ) {
+        Method setter = encoder.getClass().getMethod( "setMaxCodeLength", 
Integer.class );
+        setter.invoke( encoder, Integer.parseInt( v ) );
+      }
     } 
     catch (Exception e) {
       throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Error 
initializing: "+name + "/"+clazz, e );

{code}

> Add new DoubleMetaphone Filter and Factory
> ------------------------------------------
>
>                 Key: SOLR-813
>                 URL: https://issues.apache.org/jira/browse/SOLR-813
>             Project: Solr
>          Issue Type: New Feature
>          Components: search
>    Affects Versions: 1.3
>            Reporter: Todd Feak
>            Priority: Minor
>         Attachments: SOLR-813.patch
>
>
> The existing PhoneticFilter allows for use of the DoubleMetaphone encoder. 
> However, it doesn't expose the maxCodeLength() setting, and it ignores the 
> alternate encodings that the encoder provides for some words. This new filter 
> is not as generic as the PhoneticFilter, but allows more detailed control 
> over the DoubleMetaphone encoder.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to