lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Koji Sekiguchi" <koji.sekigu...@m4.dion.ne.jp>
Subject RE: Indexing problem - empty index files!
Date Tue, 25 Oct 2005 00:41:05 GMT
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


Mime
View raw message