You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Cauvery Developer <ka...@gmail.com> on 2007/12/01 11:02:39 UTC

Term(String, BufferedReader) constructor ?

Hi,
If we are able to create a Field using a BufferedReader, why not do the same
for the Term as well ?

I am trying to implement Lucene for a small set of source files, where the
entire source is the value for a Field named 'source'. Creating the field
was easy because there is a constructor for Field using a BufferedReader.
When there are changes in the source file, I need to update the Document in
the Index using updateDocument(Term, Document). Since, a Term is "...is
composed of two elements, the text of the word, as a string, and the name of
the field that the text occured in...", I would have to build the Term with
the modified source. But, there isn't such a constructor for Term.

I know, I can I use IndexWriter with createFlag set to false while updating.
But, this sounds too "comprehensive".

Regards,
Nags

Re: Term(String, BufferedReader) constructor ?

Posted by Michael McCandless <lu...@mikemccandless.com>.
"Cauvery Developer" <ka...@gmail.com> wrote:

> I know, I can I use IndexWriter with createFlag set to false while
> updating. But, this sounds too "comprehensive".

Nomatter what if you are going to update a document, you will have to
open a writer for doing so (or, use a writer you already have open).

> I am trying to implement Lucene for a small set of source files, where
> the entire source is the value for a Field named 'source'. Creating
> the field was easy because there is a constructor for Field using a
> BufferedReader. When there are changes in the source file, I need to
> update the Document in the Index using updateDocument(Term, Document).
> Since, a Term is "...is composed of two elements, the text of the
> word, as a string, and the name of the field that the text occured
> in...", I would have to build the Term with the modified source. But,
> there isn't such a constructor for Term.

The Term that you pass as the first argument to updateDocument must
"identify" the document you want to replace.  EG you could add a field
"documentID" that has a unique value per document.  You then pass in
Term("documentID", <string-ID>) to updateDocument.  In your case maybe
you could use a canonical fileName or URI to identify the document.

Then, you put your modified source as a Field into the second argument
(document) to the updateDocument method.

Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org