1
我索引使用Lucene的文件,並正嘗試應用SnowballAnalyzer從文本標點符號和停用詞去除。我不斷收到以下錯誤:(異常索引時使用Lucene文本文檔,使用SnowballAnalyzer清理
IllegalAccessError:嘗試訪問方法org.apache.lucene.analysis.Tokenizer(Ljava/IO /閱讀器;)從V類org.apache.lucene.analysis.snowball.SnowballAnalyzer
下面是代碼,我願意。非常感謝幫助!!!!我是新的這個..
公開課索引器{
private Indexer(){};
private String[] stopWords = {....};
private String indexName;
private IndexWriter iWriter;
private static String FILES_TO_INDEX = "/Users/ssi/forindexing";
public static void main(String[] args) throws Exception {
Indexer m = new Indexer();
m.index("./newindex");
}
public void index(String indexName) throws Exception {
this.indexName = indexName;
final File docDir = new File(FILES_TO_INDEX);
if(!docDir.exists() || !docDir.canRead()){
System.err.println("Something wrong... " + docDir.getPath());
System.exit(1);
}
Date start = new Date();
PerFieldAnalyzerWrapper analyzers = new PerFieldAnalyzerWrapper(new SimpleAnalyzer());
analyzers.addAnalyzer("text", new SnowballAnalyzer("English", stopWords));
Directory directory = FSDirectory.open(new File(this.indexName));
IndexWriter.MaxFieldLength maxLength = IndexWriter.MaxFieldLength.UNLIMITED;
iWriter = new IndexWriter(directory, analyzers, true, maxLength);
System.out.println("Indexing to dir..........." + indexName);
if(docDir.isDirectory()){
File[] files = docDir.listFiles();
if(files != null){
for (int i = 0; i < files.length; i++) {
try {
indexDocument(files[i]);
}catch (FileNotFoundException fnfe){
fnfe.printStackTrace();
}
}
}
}
System.out.println("Optimizing...... ");
iWriter.optimize();
iWriter.close();
Date end = new Date();
System.out.println("Time to index was" + (end.getTime()-start.getTime()) + "miliseconds");
}
私人無效indexDocument(文件someDoc)拋出IOException異常{
Document doc = new Document();
Field name = new Field("name", someDoc.getName(), Field.Store.YES, Field.Index.ANALYZED);
Field text = new Field("text", new FileReader(someDoc), Field.TermVector.WITH_POSITIONS_OFFSETS);
doc.add(name);
doc.add(text);
iWriter.addDocument(doc);
}}
Thanx Sean!我仍然無法解決它.....我正在使用lucene-core3.0.1,並嘗試了幾種不同的雪球罐。 目前沒有任何幫助:/ – Julia 2010-04-28 11:08:01
我看,雪球是一個單獨的.jar?那麼很可能您的版本與您正在使用的Lucene版本不兼容。 – 2010-04-28 17:26:08
是的,它是在單獨的jar,因爲在我使用的lucene-core jar版本(3.0.1)中沒有org.apache.lucene.analysis中的snowballAnalyzer ..所以我單獨下載它,嘗試了4個版本的雪球, 沒有解決方案。 Ive發現的最新版本是snowball-2.4.0。也許我可以俯瞰愚蠢的東西? lucene-core distibution應該是雪球嗎? – Julia 2010-04-28 19:51:02