You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Samuel Jackson <sa...@yahoo.de> on 2005/10/25 01:33:44 UTC
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: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
RE: Indexing problem - empty index files!
Posted by Koji Sekiguchi <ko...@m4.dion.ne.jp>.
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:samurujackson@yahoo.de]
> 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: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org