1

我正在使用 Lucene 对文档进行索引,并尝试应用 SnowballAnalyzer 从文本中删除标点符号和停用词。我不断收到以下错误:(

IllegalAccessError:试图从类 org.apache.lucene.analysis.snowball.SnowballAnalyzer 访问方法 org.apache.lucene.analysis.Tokenizer.(Ljava/io/Reader;)V

这是代码,我将非常感谢帮助!!!!我是新来的..

公共类索引器{

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");  

}

private void indexDocument(File 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);

} }

4

1 回答 1

3

这表示一个 Lucene 类与另一个 Lucene 类不一致——一个正在访问另一个它不能访问的成员。这强烈表明您的类路径中有两个不同且不兼容的 Lucene 版本。

于 2010-04-28T08:05:54.677 回答