Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mimirtech.search.solr.analysis;
- import java.io.IOException;
- import org.apache.lucene.analysis.Token;
- import org.apache.lucene.analysis.TokenFilter;
- import org.apache.lucene.analysis.TokenStream;
- public class AspellFilter extends TokenFilter
- {
- static
- {
- try
- {
- System.loadLibrary( "java_aspell" );
- }
- catch( UnsatisfiedLinkError e )
- {
- System.loadLibrary( "/usr/local/lib/", "java_aspell" );
- //System.err.println( "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
- //System.exit( 1 );
- }
- }
- com.mimirtech.speller.aspell.Suggest fsuggest;
- public AspellFilter(TokenStream input) throws java.lang.Exception
- {
- super( input );
- fsuggest = new com.mimirtech.speller.aspell.Suggest( "en_SG", "utf-8",
- "", "60" );
- }
- /*********************************************************************/
- public AspellFilter(TokenStream input, String lang, String encoding,
- String jargon, String size) throws java.lang.Exception
- {
- super( input );
- fsuggest = new com.mimirtech.speller.aspell.Suggest( lang, encoding,
- jargon, size );
- }
- /*********************************************************************/
- public Token next() throws IOException
- {
- return parseToken( this.input.next() );
- }
- /*********************************************************************/
- public Token next(Token result) throws IOException
- {
- return parseToken( this.input.next() );
- }
- /*********************************************************************/
- protected Token parseToken(Token in)
- {
- if( in != null )
- {
- // FIXME: Alter the char[] from TermBuffer directly to
- // improve efficiency.
- // See http://lucene.apache.org/java/2_3_2/api/org/apache/lucene/analysis/Token.html#setTermBuffer(char[],%20int,%20int)
- String text = String.valueOf( in.termBuffer() );
- String soundslike = fsuggest.SoundsLike( text );
- in.setTermBuffer( soundslike, 0, soundslike.length() );
- }
- return in;
- }
- /*********************************************************************/
- } // public class AspellFilter
- /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@ END OF FILE @@@@@@@@@@@@@@@@@@@@@@@@@@*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement