lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Granroth, Neal V." <>
Subject RE: [Lucene.Net] how to add a new record to existing index
Date Thu, 03 Mar 2011 19:08:16 GMT
There are several things to consider.

The first is what DIGY pointed out.  The third parameter of the IndexWriter constructor determines
if the code is creating a new index or opening an existing index for additions.  The code
must specify "false" to open an existing index for additions.

A second thing to consider is that the additions made to the index with writer.AddDocument()
will not be visible until the IndexWriter is closed, or the Commit() method is called.

A third thing to consider, instances of IndexReader can only see the content of the index
at the time the IndexReader instance was opened.  Even after the IndexWriter commits its changes,
IndexReader instances must be re-opened in order to see the new index content.

It seems you should check your code to ensure:

- IndexWriter constructor is being called with the right parameters to open an existing index.

- IndexWriter is closed or commit is called after changes have been made.

- IndexReader instances are re-opened after changes have been committed.

- Neal

-----Original Message-----
From: Digy [] 
Sent: Thursday, March 03, 2011 12:16 PM
Subject: RE: [Lucene.Net] how to add a new record to existing index

I don't think that I understand your problem.
Is it something like 
	IndexWriter writer = new IndexWriter(path, analyzer, *false*,


-----Original Message-----
From: Wen Gao [] 
Sent: Thursday, March 03, 2011 1:43 AM
Subject: Re: [Lucene.Net] how to add a new record to existing index

Hi Digy,
It was my fault that i didnt say it clearly. I mean I have created an
index,but it is not updated real time. So I want to update the index
everytime after I add data to database to keep the index up-to-date. My data
is what user inputs and inserted to database.Then

BTW, I know how to delete a term from index using IndexReader. Likewise, I
want to write a term to the created index instead of creating a new index.
I appreciate your time.


2011/3/2 Digy <>

> First of all, your code doesn't mean anything to me other than you add
> fields to a document object.
> Also,  I can't see what you mean with *existing* index. The directory you
> pass to the IndexWriter is the index you use
> and every document added(using IndexWriter's AddDocument) is written to
> that
> index.
> I think, we have problems in using a common terminology.
> PS: It would be better if you use "user" mailing list to ask questions.
> This
> mailing lists is intented to be for development purposes.
> -----Original Message-----
> From: Wen Gao []
> Sent: Wednesday, March 02, 2011 11:02 PM
> To:
> Subject: [Lucene.Net] how to add a new record to existing index
> Hi,
> I already have created an index, and I want to insert an index record to
> this existing index everytime I insert a new record to database.
> For example,  if I want to insert an reord ("l1", "15","tom",
> "20","2010/01/02") to my *existing* index, how can i do this? (I dont want
> to create a new index, which takes too much time)
> my format of index is as follows:
>  ///////////////////////////
>  doc.Add(new Lucene.Net.Documents.Field(
>                "lmname",
>                readerreader1["lmname"].ToString(),
>                    //new
> System.IO.StringReader(readerreader["cname"].ToString()),
>                Lucene.Net.Documents.Field.Store.YES,
>                 Lucene.Net.Documents.Field.Index.TOKENIZED)
>                );
>                //lmid
>                doc.Add(new Lucene.Net.Documents.Field(
>                "lmid",
>                readerreader1["lmid"].ToString(),
>                 Lucene.Net.Documents.Field.Store.YES,
>                 Lucene.Net.Documents.Field.Index.UN_TOKENIZED));
>                // nick name of user
>                doc.Add(new Lucene.Net.Documents.Field(
>                "nickName",
>                 readerreader1["nickName"].ToString(),
>                 Lucene.Net.Documents.Field.Store.YES,
>                 Lucene.Net.Documents.Field.Index.UN_TOKENIZED));
>                // uid
>                doc.Add(new Lucene.Net.Documents.Field(
>                "uid",
>                 readerreader1["uid"].ToString(),
>                 Lucene.Net.Documents.Field.Store.YES,
>                 Lucene.Net.Documents.Field.Index.UN_TOKENIZED));
>                // acttime
>                doc.Add(new Lucene.Net.Documents.Field(
>                "acttime",
>                 readerreader1["acttime"].ToString(),
>                 Lucene.Net.Documents.Field.Store.YES,
>                 Lucene.Net.Documents.Field.Index.UN_TOKENIZED));
>                writer.AddDocument(doc);
>                ///////////////////////////////////////////////////
> Thanks,
> Wen

View raw message