-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* | ||
*/ | ||
package org.wltea.analyzer.solr; | ||
|
||
import java.io.Reader; | ||
import java.util.Map; | ||
|
||
import org.apache.lucene.analysis.Tokenizer; | ||
import org.apache.solr.analysis.BaseTokenizerFactory; | ||
import org.wltea.analyzer.lucene.IKTokenizer; | ||
|
||
/** | ||
* 实现Solr1.4分词器接口 | ||
* 基于IKTokenizer的实现 | ||
* | ||
* @author 李良杰 | ||
* | ||
*/ | ||
public final class IKTokenizerFactory14 extends BaseTokenizerFactory{ | ||
|
||
private boolean isMaxWordLength = false; | ||
|
||
/** | ||
* IK分词器Solr TokenizerFactory接口实现类 | ||
* 默认最细粒度切分算法 | ||
*/ | ||
public IKTokenizerFactory14(){ | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.apache.solr.analysis.BaseTokenizerFactory#init(java.util.Map) | ||
*/ | ||
public void init(Map<String,String> args){ | ||
String _arg = args.get("isMaxWordLength"); | ||
isMaxWordLength = Boolean.parseBoolean(_arg); | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.apache.solr.analysis.TokenizerFactory#create(java.io.Reader) | ||
*/ | ||
public Tokenizer create(Reader reader) { | ||
return new IKTokenizer(reader , isMaxWordLength()); | ||
} | ||
|
||
public void setMaxWordLength(boolean isMaxWordLength) { | ||
this.isMaxWordLength = isMaxWordLength; | ||
} | ||
|
||
public boolean isMaxWordLength() { | ||
return isMaxWordLength; | ||
} | ||
|
||
} |