lucene 3.3 i tried liek this
"" import org.apache.lucene.demo.FileDocument; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.queryParser.QueryParser; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.Version; import java.sql.*; import java.util.Properties; import org.apache.lucene.document.*; import java.io.*; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.store.SimpleFSDirectory; public class Con{ public static void main(String[] args) throws Exception { final File INDEX_DIR = new File("index"); Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1/test", "root", "passwort"); StandardAnalyzer analyzer = new StandardAnalyzer(null); Directory directory = new SimpleFSDirectory(new File("home/lucius/Desktop/index")); IndexWriter w = new IndexWriter(directory, analyzer,true, new IndexWriter.MaxFieldLength(25000)); System.out.println("Indexing to directory '" + INDEX_DIR + "'..."); indexDocs(w, conn); w.optimize(); w.close(); } private static void indexDocs(IndexWriter writer, Connection conn) throws Exception { String sql = "select c_id, city from city"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { Document d = new Document(); d.add(new Field("c_id", rs.getString("c_id"), Field.Store.YES, Field.Index.NO)); d.add(new Field("city", rs.getString("city"), Field.Store.NO, Field.Index.ANALYZED)); writer.addDocument(d); } } } """" I ' on the right track ? now i get this message after compiling "" Exception in thread "main" java.lang.NullPointerException at org.apache.lucene.analysis.StopFilter.getEnablePositionIncrementsVersionDefault(StopFilter.java:162) at org.apache.lucene.analysis.standard.StandardAnalyzer.<init>(StandardAnalyzer.java:73) at org.apache.lucene.analysis.standard.StandardAnalyzer.<init>(StandardAnalyzer.java:63) at Con.main(Con.java:29) """ once again many thanks Erick Erickson wrote: > > What version are you using? Because there's no such constructor > (i.e. one that takes a File) in 3.0..... > > You might want to use something like FSDirectory.open(file) in > your IndexWriter constructor.... > > If this doesn't work, more details please.... > > Erick > > On Thu, Jan 28, 2010 at 3:30 PM, luciusvorenus > <lucius.vore...@hotmail.de>wrote: > >> >> Hello >> >> I tried to index a database >> >> "" >> import org.apache.lucene.demo.FileDocument; >> import org.apache.lucene.document.Document; >> import org.apache.lucene.document.Field; >> import org.apache.lucene.analysis.Analyzer; >> import org.apache.lucene.analysis.standard.StandardAnalyzer; >> import org.apache.lucene.index.IndexWriter; >> import org.apache.lucene.search.IndexSearcher; >> import org.apache.lucene.search.Query; >> import org.apache.lucene.queryParser.QueryParser; >> import org.apache.lucene.store.FSDirectory; >> import org.apache.lucene.util.Version; >> import java.sql.*; >> import java.util.Properties; >> import org.apache.lucene.document.*; >> import java.io.*; >> import org.apache.lucene.store.Directory; >> import org.apache.lucene.store.FSDirectory; >> >> public class Con{ >> public static void main(String[] args) throws Exception >> >> { >> final File INDEX_DIR = new File("index"); >> >> >> Class.forName("com.mysql.jdbc.Driver").newInstance(); >> Connection conn = >> DriverManager.getConnection("jdbc:mysql://127.0.0.1/test", "root", >> "passwort"); >> StandardAnalyzer analyzer = new StandardAnalyzer(null); >> IndexWriter writer = new IndexWriter(INDEX_DIR, >> analyzer, >> true); >> System.out.println("Indexing to directory '" + >> INDEX_DIR >> + "'..."); >> indexDocs(writer, conn); >> writer.optimize(); >> writer.close(); >> >> >> >> } >> >> >> private static void indexDocs(IndexWriter writer, Connection conn) >> throws >> Exception { >> String sql = "select c_id, city from city"; >> Statement stmt = conn.createStatement(); >> ResultSet rs = stmt.executeQuery(sql); >> while (rs.next()) { >> Document d = new Document(); >> d.add(new Field("c_id", rs.getString("c_id"), >> Field.Store.YES, >> Field.Index.NO)); >> d.add(new Field("city", rs.getString("city"), Field.Store.NO, >> Field.Index.ANALYZED)); >> >> writer.addDocument(d); >> } >> >> } >> } >> """ >> and i get this message >> >> "" >> symbol : constructor >> >> IndexWriter(java.io.File,org.apache.lucene.analysis.standard.StandardAnalyzer,boolean) >> location: class org.apache.lucene.index.IndexWriter >> IndexWriter writer = new IndexWriter(INDEX_DIR, >> analyzer, >> true); >> ^ >> 1 error >> >> What i am doing wrong?? >> >> I'm a newbie ... >> >> Thank U >> -- >> View this message in context: >> http://old.nabble.com/index-a-database-tp27358959p27358959.html >> Sent from the Lucene - Java Users mailing list archive at Nabble.com. >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org >> For additional commands, e-mail: java-user-h...@lucene.apache.org >> >> > > -- View this message in context: http://old.nabble.com/index-a--mysql-database-tp27358959p27363073.html Sent from the Lucene - Java Users mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org