我正在使用自定义分析器使用Lucene 5.4.1版本构建索引文件,并且正在尝试使用Luke在索引文件中查找数据。我试图用Luke添加我的自定义分析器,但是我在“分析器”选项卡中找不到。
我正在使用以下语法将分析器添加到Luke java -cp“ pivot-luke-with-deps.jar; CatalogSearchAnalyzer.jar” org.getopt.luke.Luke
我的分析器代码
public class CatalogSearchAnalyzer extends Analyzer {
private Version matchVersion;
private String termValue;
private boolean retMultiple;
public static final String[] STOP_WORDS = { "a", "and", "are", "as", "at",
"be", "but", "by", "for", "if", "in", "into", "is", "it", "no",
"not", "of", "on", "or", "such", "t", "that", "the", "their",
"then", "there", "these", "they", "this", "to", "was", "will",
"with" };
private CharArraySet stopTable;
private int maxTokenLength;
public CatalogSearchAnalyzer(Version matchVersion) {
this.stopTable = StopFilter.makeStopSet(STOP_WORDS);
this.maxTokenLength = 255;
this.matchVersion = matchVersion;
}
public CatalogSearchAnalyzer() {
this(STOP_WORDS);
}
public void setTermValue(String termValue) {
}
public void setRetMultiple(boolean retMultiple) {
}
public CatalogSearchAnalyzer(String[] stopWords) {
this.stopTable = StopFilter.makeStopSet(STOP_WORDS);
this.maxTokenLength = 255;
StopFilter.makeStopSet(stopWords);
}
private TokenStream getStemmingFilter(TokenStream result) {
PorterStemFilter temp = new PorterStemFilter(result);
temp.setRetMultiple(this.retMultiple);
return temp;
}
protected Analyzer.TokenStreamComponents createComponents(String fieldName) {
StandardTokenizer st = new StandardTokenizer();
st.setMaxTokenLength(this.maxTokenLength);
Tokenizer tk = st;
TokenStream ts = new StandardFilter(tk);
ts = new LowerCaseFilter(ts);
ts = new StopFilter(ts, this.stopTable);
ts = getStemmingFilter(ts);
return new Analyzer.TokenStreamComponents(tk, ts) {
protected void setReader(Reader reader) {
int m = CatalogSearchAnalyzer.this.maxTokenLength;
if (this.source instanceof CmgtTokenizer) {
((CmgtTokenizer) this.source).setMaxTokenLength(m);
}
super.setReader(reader);
}
};
}
}
`
将罐子添加到Luke时,我没有任何异常。
预先感谢您对此进行调查。
最佳答案
如该问题下的评论部分所述,解决方案是使用原始的基于薄片的luke代替基于枢轴的luke。基于枢轴的luke正在开发中,尚不支持所有功能(尽管鼓励进行更多测试!)
母版上的薄片卢克(当前):https://github.com/DmitryKey/luke
分支上的支点卢克:https://github.com/DmitryKey/luke/tree/pivot-luke
关于java - 卢克+ Lucene 5.4.1,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38518590/