
import java.io.*;
import java.util.*;

import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.standard.*;
import org.apache.lucene.util.Version;


/**
 * Simple custom analyzer that combines a bunch of common filters.
 * This would be nice to have in an external config file, but for
 * now we just have this little hard-coded class.
 */
public class CustomAnalyzer extends Analyzer
{
  boolean foldAccents  = false;
  boolean omitNonAlpha = false;
  Set<?> stopWords;

  public CustomAnalyzer( )
  {

  }

  public void setStopWords( Set<?> stopWords )
  {
    this.stopWords = stopWords;
  }

  public Set<?> getStopWords( )
  {
    return this.stopWords;
  }

  public void setOmitNonAlpha( boolean omitNonAlpha )
  {
    this.omitNonAlpha = omitNonAlpha;
  }

  public boolean getOmitNonAlpha( )
  {
    return this.omitNonAlpha;
  }

  public void setFoldAccents( boolean foldAccents )
  {
    this.foldAccents = foldAccents;
  }

  public boolean getFoldAccents( )
  {
    return this.foldAccents;
  }

  public TokenStream tokenStream( String fieldName, Reader reader )
  {
    TokenStream stream = new StandardTokenizer( Version.LUCENE_30, reader );
    stream = new StandardFilter( stream );
    stream = new LowerCaseFilter( stream );
    if ( this.foldAccents )
      {
        stream = new ASCIIFoldingFilter( stream );
      }
    if ( this.omitNonAlpha )
      {
        stream = new NonAlphaFilter( stream );
      }
    if ( this.stopWords != null && this.stopWords.size( ) > 0 )
      {
        stream = new StopFilter( true, stream, this.stopWords );
      }

    return stream;
  }

}

@@ -1,20 +1,617 @@
+/*%0A * Copyright 2010 Internet Archive%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22); you%0A * may not use this file except in compliance with the License. You%0A * may obtain a copy of the License at%0A *%0A *  http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or%0A * implied. See the License for the specific language governing%0A * permissions and limitations under the License.%0A */%0A
 %0Aimport java.io.*;%0Ai

Add license header.