lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris D <>
Subject Re: Adding document with FileReader and deletions.
Date Wed, 08 Jun 2005 14:15:04 GMT
On 6/7/05, Chris D <> wrote:
> Hi list,
> I've been trying to use lucene to index documents that change
> occasionally with fields that change frequently. When I add the
> contents of the file they are removed when I try to delete and readd
> the document. I and am using something like the following.
> public void index(String stuff, File f, boolean doContents){
>    Document doc = new Document();
>    writer.close()
>    reader =;
>    TermDocs td = reader.termDocs(new Term("fileid", fileid));
>    //Load the document into memory and delete the document from the index.
>    if({
>       doc = reader.document(tc.doc());
>       reader.delect(new Term("fileid", fileid)); //*******
>    }
>    //We're done deleting so we can move along.
>    reader.close();
>    writer = new IndexWriter(...);
>    doc.removeFields("stuff");
>    doc.add(new Field("stuff", stuff, File.Store.YES, File.Index.TOKENIZED));
>    //More fields...
>    //If the contents need to be readded... Do so.
>    if(doContents){
>       doc.removeFields("contents");
>       doc.add(new Field("contents", new FileReader(f), Field.TermVector.YES));
>       //System.out.println(doc.get("contents"));
>    }
>    writeDoc(doc)
> }
> There are other fields in doc that will stay the same when it updates
> which is why I do the removeFields instead of just deleting the doc
> and replacing it.
> Now if I remove the reader.delete call that's starred the contents get
> added. (Albeit over and over again) If it remains then all of the
> contents go missing in the index. (Verified with Luke and by searching
> for contents:a* etc)
> I figure I'm missing something silly, hopefully someone can help me
> out, I've been fighting with this for a day or two now, with little
> progress, but many more printlns.
> Cheers,
> Chris

What I think is happening is that because "contents" isn't stored,
when I read the document and delete it I delete any of the information
that was held in that fied. Is there a way to retrieve that
information so that it doesn't disappear?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message