hello list sory, this is maeby a stupid questin, but i can't resolve. so maeby you can help me:
i try to compile the indexer-example from the book lucene in action, 2nd edition (http://www.manning.com/hatcher3/hatcher_meapch1.pdf), but get the following error: ---------------------------------------------------------------------- javac -Xlint -cp ":.:./lucene/lucene-core-2.4.1.jar" Indexer.java Indexer.java:37: cannot find symbol symbol : constructor FSDirectory(java.io.File,<nulltype>) location: class org.apache.lucene.store.FSDirectory Directory dir = new FSDirectory(new File(indexDir), null); ^ 1 error ---------------------------------------------------------------------- it means the following codesgement: public Indexer(String indexDir) throws IOException { Directory dir = new FSDirectory(new File(indexDir)); writer = new IndexWriter(dir, new StandardAnalyzer(), true, IndexWriter.maxFieldLength.UNLIMITED); } im using debian testing with.. java -version java version "1.6.0_0" OpenJDK Runtime Environment (build 1.6.0_0-b11) OpenJDK Server VM (build 1.6.0_0-b11, mixed mode) sourcecode+makefile are attached: thanks for your help, timon
import org.apache.lucene.index.IndexWriter; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.store.Directory; import java.io.File; import java.io.IOException; import java.io.FileReader; public class Indexer { private IndexWriter writer; public static void main(String[] args) throws Exception { if (args.length != 2) { throw new Exception("Usage: java " + Indexer.class.getName() + " <index dir> <data dir>"); } String indexDir = args[0]; String dataDir = args[1]; long start = System.currentTimeMillis(); Indexer indexer = new Indexer(indexDir); int numIndexed = indexer.index(dataDir); indexer.close(); long end = System.currentTimeMillis(); System.out.println("Indexing " + numIndexed + " files took " + (end - start) + " milliseconds"); } public Indexer(String indexDir) throws IOException { Directory dir = new FSDirectory(new File(indexDir), null); writer = new IndexWriter(dir, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED); } public void close() throws IOException { writer.close(); } public int index(String dataDir) throws Exception { File[] files = new File(dataDir).listFiles(); for (int i = 0; i < files.length; i++) { File f = files[i]; if (!f.isDirectory() && !f.isHidden() && f.exists() && f.canRead() && acceptFile(f)) { indexFile(f); } } return writer.numDocs(); } protected boolean acceptFile(File f) { return f.getName().endsWith(".txt"); } protected Document getDocument(File f) throws Exception { Document doc = new Document(); doc.add(new Field("contents", new FileReader(f))); doc.add(new Field("filename", f.getCanonicalPath(), Field.Store.YES, Field.Index.NOT_ANALYZED)); return doc; } private void indexFile(File f) throws Exception { System.out.println("Indexing " + f.getCanonicalPath()); Document doc = getDocument(f); if (doc != null) { writer.addDocument(doc); } } }
LANG='de_CH'; CP="$(CLASSPATH):.:./lucene/lucene-core-2.4.1.jar" all: javac -Xlint -cp $(CP) Indexer.java
--------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org