1

I am indexing the documents with Lucene and am trying to apply the SnowballAnalyzer for punctuation and stopword removal from text .. I keep getting the following error :(

IllegalAccessError: tried to access method org.apache.lucene.analysis.Tokenizer.(Ljava/io/Reader;)V from class org.apache.lucene.analysis.snowball.SnowballAnalyzer

Here is the code, I would very much appreciate help!!!! I am new with this..

public class Indexer {

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

} }

Julia
  • 1,217
  • 8
  • 23
  • 46

1 Answers1

3

This says that one Lucene class is inconsistent with another Lucene class -- one is accessing a member of the other that it can't. This strongly suggests you have two different and incompatible versions of Lucene in your classpath somehow.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
  • Thanx Sean! I still did not manage to resolve it..... am using lucene-core3.0.1 and i tried with several different Snowball jars. Nothing helps so far :/ – Julia Apr 28 '10 at 11:08
  • I see, snowball is a separate .jar? then it's likely that the version you have is not compatible with the version of Lucene you're using. – Sean Owen Apr 28 '10 at 17:26
  • Yes it is in separate jar, because in lucene-core jar version that I am using(3.0.1) there is no snowballAnalyzer in org.apache.lucene.analysis.. so i downloaded it separately, tried 4 versions of snowball, no solution. The latest Ive found is snowball-2.4.0. Maybe im overlooking something silly? Is snowball supposed to come in lucene-core distibution????? – Julia Apr 28 '10 at 19:51
  • I don't know what snowball is, I'm telling you what your error means. "snowball-2.4.0" suggest it is compatible with Lucene 2.4, not 3.0. – Sean Owen Apr 28 '10 at 22:54