Samuel, IndexWriter should be opened once and keep it open until all documents are added to the writer, then close the writer.
modified sample code: final IndexWriter writer = new IndexWriter(indexLocation, new StandardAnalyzer(),true); for (Iterator iter = someData.iterator(); iter.hasNext(); ) { Item item = (Item) iter.next(); Document doc = new Document(); doc.add(Field.Text("id", Long.toString(item.getId()))); doc.add(Field.Text("title", item.getTitle())); doc.add(Field.Text("description", item.getTitle())); writer.addDocument(doc); } writer.optimize(); writer.close(); Koji > -----Original Message----- > From: Samuel Jackson [mailto:[EMAIL PROTECTED] > Sent: Tuesday, October 25, 2005 8:34 AM > To: java-user@lucene.apache.org > Subject: Indexing problem - empty index files! > > > Hi to all! > > I'm new to Lucene and wanted to create a sample > application to index certain database fields. > > But there seems to be some problem because the created > files in the index target directory are only 1kb --> > So I don't get any results of course. > > > Here is what I did - can anyone give me a hint whats > wrong? > > for (Iterator iter = someData.iterator(); > iter.hasNext(); ) { > Item item = (Item) iter.next(); > Document doc = new Document(); > doc.add(Field.Text("id", > Long.toString(item.getId()))); > doc.add(Field.Text("title", item.getTitle())); > doc.add(Field.Text("description", item.getTitle())); > try { > final IndexWriter writer = new > IndexWriter(indexLocation, new StandardAnalyzer(), > true); > writer.addDocument(doc); > writer.optimize(); > writer.close(); > indexCreated = true; > } > catch (IOException e) { > e.printStackTrace(); > } > } > > > > > > > > > > > ___________________________________________________________ > Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - > Hier anmelden: http://mail.yahoo.de > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]