You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by Wen Gao <sa...@gmail.com> on 2011/03/02 22:01:37 UTC

[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

RE: [Lucene.Net] Arithmetic Overflow

Posted by Digy <di...@gmail.com>.
No, I don't think it is a bad design. It could be limited to some number,
but what would it be? 10,100,1000,1000000 or 100000000?
Besides that you have other alternatives to use while searching.

DIGY.

-----Original Message-----
From: steven.hoff@pattersoncompanies.com
[mailto:steven.hoff@pattersoncompanies.com] 
Sent: Monday, March 21, 2011 9:16 PM
To: lucene-net-dev@lucene.apache.org
Subject: RE: [Lucene.Net] Arithmetic Overflow

While I understand that and thank you for taking the time to respond, my 
concern was that passing a perfectly valid parameter leads to an 
exception. So this is bad design.


Regards, 
Steve Hoff




From:   "Digy" <di...@gmail.com>
To:     <lu...@lucene.apache.org>
Date:   03/21/2011 01:53 PM
Subject:        RE: [Lucene.Net] Arithmetic Overflow



This is an expected behaviour. You get arithmetic overflow since an
array[MaxInt] is created in PriorityQueue to store the results.
(Lucene doesn't know the result-count before iterating over the results).
If you want to collect all results( say,not the top 10 or 100), you can 
use
HitCollector.

DIGY

-----Original Message-----
From: steven.hoff@pattersoncompanies.com
[mailto:steven.hoff@pattersoncompanies.com] 
Sent: Monday, March 21, 2011 7:10 PM
To: lucene-net-dev@lucene.apache.org
Subject: RE: [Lucene.Net] Arithmetic Overflow

I'm not sure how to report this or if this is working as intended, however 

using the recommended Search overload of IndexSearcher and passing 
Int32.MaxValue, results in an arithmetic overflow exception in 
PriorityQueue.Initialize(int maxSize). 

I tested this out on several platforms, including Windows 7 - 32, 64, 
Server 2003, Server 2008.

Perhaps the parameter that is passed to the Search method should be 
updated to reflect a more realistic value? 

Regards, 
Steve Hoff

NOTICE: This email transmission and any attachments that accompany it may 
contain information that is confidential or otherwise exempt from 
disclosure under applicable law and is intended solely for the use of the 
individual(s) to whom it was intended to be addressed. If you have 
received this email by mistake, or you are not the intended recipient, any 

disclosure, dissemination, distribution, copying or other use or retention 

of this communication or its substance is prohibited. If you have received 

this communication in error, please immediately report to the author via 
email that you received this message by mistake and also permanently 
destroy printed copies and delete the original and all copies of this 
email and any attachments from your computer. 



NOTICE: This email transmission and any attachments that accompany it may 
contain information that is confidential or otherwise exempt from 
disclosure under applicable law and is intended solely for the use of the 
individual(s) to whom it was intended to be addressed. If you have 
received this email by mistake, or you are not the intended recipient, any 
disclosure, dissemination, distribution, copying or other use or retention 
of this communication or its substance is prohibited. If you have received 
this communication in error, please immediately report to the author via 
email that you received this message by mistake and also permanently 
destroy printed copies and delete the original and all copies of this 
email and any attachments from your computer. 


Re: [Lucene.Net] Arithmetic Overflow

Posted by Troy Howard <th...@gmail.com>.
That's a good point. There are a lot of scenarios where exceptions
could still occur, even with parameter validation.

The difference is, in some situations, MaxInt/2 is a valid value.
However, Int32.MaxValue is never a valid value due to the internal
sorting logic requiring an additional array slot beyond the parameter
value. Another example is any negative value. Negative values are
always invalid for this parameter.

The parameter values should be checked for known 'always invalid'
conditions, and ArgumentException should be thrown explaining the
problem.

Thanks,
Troy

On Mon, Mar 21, 2011 at 12:58 PM, Digy <di...@gmail.com> wrote:
> Is -for ex- MaxInt/2 a valid value? You can get easily an OOM exception( and the worst case would be getting sporadic OOM when search fequency increases).
>
> DIGY
>
> -----Original Message-----
> From: Troy Howard [mailto:thoward37@gmail.com]
> Sent: Monday, March 21, 2011 9:43 PM
> To: lucene-net-dev@lucene.apache.org
> Subject: Re: [Lucene.Net] Arithmetic Overflow
>
> I agree that it should not throw an overflow exception. That's not
> very helpful for debugging.
>
> The valid range of that parameter is essentially [0...
> Int32.MaxValue-1].. That's because it needs one extra slot in it's
> internal array, beyond the max size for juggling values during sort.
> The exception is thrown when it tries to setup the array to be the
> parameter value +1 to accommodate that... So the best we could do
> would be to throw a nicer exception when someone passes an invalid
> value.
>
> Until a nicer exception can be worked into the code, the documentation
> should be updated to reflect that limit...
>
> Thanks,
> Troy
>
> On Mon, Mar 21, 2011 at 12:15 PM,  <st...@pattersoncompanies.com> wrote:
>> While I understand that and thank you for taking the time to respond, my
>> concern was that passing a perfectly valid parameter leads to an
>> exception. So this is bad design.
>>
>>
>> Regards,
>> Steve Hoff
>>
>>
>>
>>
>> From:   "Digy" <di...@gmail.com>
>> To:     <lu...@lucene.apache.org>
>> Date:   03/21/2011 01:53 PM
>> Subject:        RE: [Lucene.Net] Arithmetic Overflow
>>
>>
>>
>> This is an expected behaviour. You get arithmetic overflow since an
>> array[MaxInt] is created in PriorityQueue to store the results.
>> (Lucene doesn't know the result-count before iterating over the results).
>> If you want to collect all results( say,not the top 10 or 100), you can
>> use
>> HitCollector.
>>
>> DIGY
>>
>> -----Original Message-----
>> From: steven.hoff@pattersoncompanies.com
>> [mailto:steven.hoff@pattersoncompanies.com]
>> Sent: Monday, March 21, 2011 7:10 PM
>> To: lucene-net-dev@lucene.apache.org
>> Subject: RE: [Lucene.Net] Arithmetic Overflow
>>
>> I'm not sure how to report this or if this is working as intended, however
>>
>> using the recommended Search overload of IndexSearcher and passing
>> Int32.MaxValue, results in an arithmetic overflow exception in
>> PriorityQueue.Initialize(int maxSize).
>>
>> I tested this out on several platforms, including Windows 7 - 32, 64,
>> Server 2003, Server 2008.
>>
>> Perhaps the parameter that is passed to the Search method should be
>> updated to reflect a more realistic value?
>>
>> Regards,
>> Steve Hoff
>>
>> NOTICE: This email transmission and any attachments that accompany it may
>> contain information that is confidential or otherwise exempt from
>> disclosure under applicable law and is intended solely for the use of the
>> individual(s) to whom it was intended to be addressed. If you have
>> received this email by mistake, or you are not the intended recipient, any
>>
>> disclosure, dissemination, distribution, copying or other use or retention
>>
>> of this communication or its substance is prohibited. If you have received
>>
>> this communication in error, please immediately report to the author via
>> email that you received this message by mistake and also permanently
>> destroy printed copies and delete the original and all copies of this
>> email and any attachments from your computer.
>>
>>
>>
>> NOTICE: This email transmission and any attachments that accompany it may
>> contain information that is confidential or otherwise exempt from
>> disclosure under applicable law and is intended solely for the use of the
>> individual(s) to whom it was intended to be addressed. If you have
>> received this email by mistake, or you are not the intended recipient, any
>> disclosure, dissemination, distribution, copying or other use or retention
>> of this communication or its substance is prohibited. If you have received
>> this communication in error, please immediately report to the author via
>> email that you received this message by mistake and also permanently
>> destroy printed copies and delete the original and all copies of this
>> email and any attachments from your computer.
>>
>
>

RE: [Lucene.Net] Arithmetic Overflow

Posted by Digy <di...@gmail.com>.
Is -for ex- MaxInt/2 a valid value? You can get easily an OOM exception( and the worst case would be getting sporadic OOM when search fequency increases).

DIGY 

-----Original Message-----
From: Troy Howard [mailto:thoward37@gmail.com] 
Sent: Monday, March 21, 2011 9:43 PM
To: lucene-net-dev@lucene.apache.org
Subject: Re: [Lucene.Net] Arithmetic Overflow

I agree that it should not throw an overflow exception. That's not
very helpful for debugging.

The valid range of that parameter is essentially [0...
Int32.MaxValue-1].. That's because it needs one extra slot in it's
internal array, beyond the max size for juggling values during sort.
The exception is thrown when it tries to setup the array to be the
parameter value +1 to accommodate that... So the best we could do
would be to throw a nicer exception when someone passes an invalid
value.

Until a nicer exception can be worked into the code, the documentation
should be updated to reflect that limit...

Thanks,
Troy

On Mon, Mar 21, 2011 at 12:15 PM,  <st...@pattersoncompanies.com> wrote:
> While I understand that and thank you for taking the time to respond, my
> concern was that passing a perfectly valid parameter leads to an
> exception. So this is bad design.
>
>
> Regards,
> Steve Hoff
>
>
>
>
> From:   "Digy" <di...@gmail.com>
> To:     <lu...@lucene.apache.org>
> Date:   03/21/2011 01:53 PM
> Subject:        RE: [Lucene.Net] Arithmetic Overflow
>
>
>
> This is an expected behaviour. You get arithmetic overflow since an
> array[MaxInt] is created in PriorityQueue to store the results.
> (Lucene doesn't know the result-count before iterating over the results).
> If you want to collect all results( say,not the top 10 or 100), you can
> use
> HitCollector.
>
> DIGY
>
> -----Original Message-----
> From: steven.hoff@pattersoncompanies.com
> [mailto:steven.hoff@pattersoncompanies.com]
> Sent: Monday, March 21, 2011 7:10 PM
> To: lucene-net-dev@lucene.apache.org
> Subject: RE: [Lucene.Net] Arithmetic Overflow
>
> I'm not sure how to report this or if this is working as intended, however
>
> using the recommended Search overload of IndexSearcher and passing
> Int32.MaxValue, results in an arithmetic overflow exception in
> PriorityQueue.Initialize(int maxSize).
>
> I tested this out on several platforms, including Windows 7 - 32, 64,
> Server 2003, Server 2008.
>
> Perhaps the parameter that is passed to the Search method should be
> updated to reflect a more realistic value?
>
> Regards,
> Steve Hoff
>
> NOTICE: This email transmission and any attachments that accompany it may
> contain information that is confidential or otherwise exempt from
> disclosure under applicable law and is intended solely for the use of the
> individual(s) to whom it was intended to be addressed. If you have
> received this email by mistake, or you are not the intended recipient, any
>
> disclosure, dissemination, distribution, copying or other use or retention
>
> of this communication or its substance is prohibited. If you have received
>
> this communication in error, please immediately report to the author via
> email that you received this message by mistake and also permanently
> destroy printed copies and delete the original and all copies of this
> email and any attachments from your computer.
>
>
>
> NOTICE: This email transmission and any attachments that accompany it may
> contain information that is confidential or otherwise exempt from
> disclosure under applicable law and is intended solely for the use of the
> individual(s) to whom it was intended to be addressed. If you have
> received this email by mistake, or you are not the intended recipient, any
> disclosure, dissemination, distribution, copying or other use or retention
> of this communication or its substance is prohibited. If you have received
> this communication in error, please immediately report to the author via
> email that you received this message by mistake and also permanently
> destroy printed copies and delete the original and all copies of this
> email and any attachments from your computer.
>


Re: [Lucene.Net] Arithmetic Overflow

Posted by Troy Howard <th...@gmail.com>.
I agree that it should not throw an overflow exception. That's not
very helpful for debugging.

The valid range of that parameter is essentially [0...
Int32.MaxValue-1].. That's because it needs one extra slot in it's
internal array, beyond the max size for juggling values during sort.
The exception is thrown when it tries to setup the array to be the
parameter value +1 to accommodate that... So the best we could do
would be to throw a nicer exception when someone passes an invalid
value.

Until a nicer exception can be worked into the code, the documentation
should be updated to reflect that limit...

Thanks,
Troy

On Mon, Mar 21, 2011 at 12:15 PM,  <st...@pattersoncompanies.com> wrote:
> While I understand that and thank you for taking the time to respond, my
> concern was that passing a perfectly valid parameter leads to an
> exception. So this is bad design.
>
>
> Regards,
> Steve Hoff
>
>
>
>
> From:   "Digy" <di...@gmail.com>
> To:     <lu...@lucene.apache.org>
> Date:   03/21/2011 01:53 PM
> Subject:        RE: [Lucene.Net] Arithmetic Overflow
>
>
>
> This is an expected behaviour. You get arithmetic overflow since an
> array[MaxInt] is created in PriorityQueue to store the results.
> (Lucene doesn't know the result-count before iterating over the results).
> If you want to collect all results( say,not the top 10 or 100), you can
> use
> HitCollector.
>
> DIGY
>
> -----Original Message-----
> From: steven.hoff@pattersoncompanies.com
> [mailto:steven.hoff@pattersoncompanies.com]
> Sent: Monday, March 21, 2011 7:10 PM
> To: lucene-net-dev@lucene.apache.org
> Subject: RE: [Lucene.Net] Arithmetic Overflow
>
> I'm not sure how to report this or if this is working as intended, however
>
> using the recommended Search overload of IndexSearcher and passing
> Int32.MaxValue, results in an arithmetic overflow exception in
> PriorityQueue.Initialize(int maxSize).
>
> I tested this out on several platforms, including Windows 7 - 32, 64,
> Server 2003, Server 2008.
>
> Perhaps the parameter that is passed to the Search method should be
> updated to reflect a more realistic value?
>
> Regards,
> Steve Hoff
>
> NOTICE: This email transmission and any attachments that accompany it may
> contain information that is confidential or otherwise exempt from
> disclosure under applicable law and is intended solely for the use of the
> individual(s) to whom it was intended to be addressed. If you have
> received this email by mistake, or you are not the intended recipient, any
>
> disclosure, dissemination, distribution, copying or other use or retention
>
> of this communication or its substance is prohibited. If you have received
>
> this communication in error, please immediately report to the author via
> email that you received this message by mistake and also permanently
> destroy printed copies and delete the original and all copies of this
> email and any attachments from your computer.
>
>
>
> NOTICE: This email transmission and any attachments that accompany it may
> contain information that is confidential or otherwise exempt from
> disclosure under applicable law and is intended solely for the use of the
> individual(s) to whom it was intended to be addressed. If you have
> received this email by mistake, or you are not the intended recipient, any
> disclosure, dissemination, distribution, copying or other use or retention
> of this communication or its substance is prohibited. If you have received
> this communication in error, please immediately report to the author via
> email that you received this message by mistake and also permanently
> destroy printed copies and delete the original and all copies of this
> email and any attachments from your computer.
>

RE: [Lucene.Net] Arithmetic Overflow

Posted by st...@pattersoncompanies.com.
While I understand that and thank you for taking the time to respond, my 
concern was that passing a perfectly valid parameter leads to an 
exception. So this is bad design.


Regards, 
Steve Hoff




From:   "Digy" <di...@gmail.com>
To:     <lu...@lucene.apache.org>
Date:   03/21/2011 01:53 PM
Subject:        RE: [Lucene.Net] Arithmetic Overflow



This is an expected behaviour. You get arithmetic overflow since an
array[MaxInt] is created in PriorityQueue to store the results.
(Lucene doesn't know the result-count before iterating over the results).
If you want to collect all results( say,not the top 10 or 100), you can 
use
HitCollector.

DIGY

-----Original Message-----
From: steven.hoff@pattersoncompanies.com
[mailto:steven.hoff@pattersoncompanies.com] 
Sent: Monday, March 21, 2011 7:10 PM
To: lucene-net-dev@lucene.apache.org
Subject: RE: [Lucene.Net] Arithmetic Overflow

I'm not sure how to report this or if this is working as intended, however 

using the recommended Search overload of IndexSearcher and passing 
Int32.MaxValue, results in an arithmetic overflow exception in 
PriorityQueue.Initialize(int maxSize). 

I tested this out on several platforms, including Windows 7 - 32, 64, 
Server 2003, Server 2008.

Perhaps the parameter that is passed to the Search method should be 
updated to reflect a more realistic value? 

Regards, 
Steve Hoff

NOTICE: This email transmission and any attachments that accompany it may 
contain information that is confidential or otherwise exempt from 
disclosure under applicable law and is intended solely for the use of the 
individual(s) to whom it was intended to be addressed. If you have 
received this email by mistake, or you are not the intended recipient, any 

disclosure, dissemination, distribution, copying or other use or retention 

of this communication or its substance is prohibited. If you have received 

this communication in error, please immediately report to the author via 
email that you received this message by mistake and also permanently 
destroy printed copies and delete the original and all copies of this 
email and any attachments from your computer. 



NOTICE: This email transmission and any attachments that accompany it may 
contain information that is confidential or otherwise exempt from 
disclosure under applicable law and is intended solely for the use of the 
individual(s) to whom it was intended to be addressed. If you have 
received this email by mistake, or you are not the intended recipient, any 
disclosure, dissemination, distribution, copying or other use or retention 
of this communication or its substance is prohibited. If you have received 
this communication in error, please immediately report to the author via 
email that you received this message by mistake and also permanently 
destroy printed copies and delete the original and all copies of this 
email and any attachments from your computer. 

RE: [Lucene.Net] Arithmetic Overflow

Posted by Digy <di...@gmail.com>.
This is an expected behaviour. You get arithmetic overflow since an
array[MaxInt] is created in PriorityQueue to store the results.
(Lucene doesn't know the result-count before iterating over the results).
If you want to collect all results( say,not the top 10 or 100), you can use
HitCollector.

DIGY

-----Original Message-----
From: steven.hoff@pattersoncompanies.com
[mailto:steven.hoff@pattersoncompanies.com] 
Sent: Monday, March 21, 2011 7:10 PM
To: lucene-net-dev@lucene.apache.org
Subject: RE: [Lucene.Net] Arithmetic Overflow

I'm not sure how to report this or if this is working as intended, however 
using the recommended Search overload of IndexSearcher and passing 
Int32.MaxValue, results in an arithmetic overflow exception in 
PriorityQueue.Initialize(int maxSize). 

I tested this out on several platforms, including Windows 7 - 32, 64, 
Server 2003, Server 2008.

Perhaps the parameter that is passed to the Search method should be 
updated to reflect a more realistic value? 

Regards, 
Steve Hoff

NOTICE: This email transmission and any attachments that accompany it may 
contain information that is confidential or otherwise exempt from 
disclosure under applicable law and is intended solely for the use of the 
individual(s) to whom it was intended to be addressed. If you have 
received this email by mistake, or you are not the intended recipient, any 
disclosure, dissemination, distribution, copying or other use or retention 
of this communication or its substance is prohibited. If you have received 
this communication in error, please immediately report to the author via 
email that you received this message by mistake and also permanently 
destroy printed copies and delete the original and all copies of this 
email and any attachments from your computer. 


RE: [Lucene.Net] Arithmetic Overflow

Posted by st...@pattersoncompanies.com.
I'm not sure how to report this or if this is working as intended, however 
using the recommended Search overload of IndexSearcher and passing 
Int32.MaxValue, results in an arithmetic overflow exception in 
PriorityQueue.Initialize(int maxSize). 

I tested this out on several platforms, including Windows 7 - 32, 64, 
Server 2003, Server 2008.

Perhaps the parameter that is passed to the Search method should be 
updated to reflect a more realistic value? 

Regards, 
Steve Hoff

NOTICE: This email transmission and any attachments that accompany it may 
contain information that is confidential or otherwise exempt from 
disclosure under applicable law and is intended solely for the use of the 
individual(s) to whom it was intended to be addressed. If you have 
received this email by mistake, or you are not the intended recipient, any 
disclosure, dissemination, distribution, copying or other use or retention 
of this communication or its substance is prohibited. If you have received 
this communication in error, please immediately report to the author via 
email that you received this message by mistake and also permanently 
destroy printed copies and delete the original and all copies of this 
email and any attachments from your computer. 

RE: [Lucene.Net] how to add a new record to existing index

Posted by "Granroth, Neal V." <ne...@thermofisher.com>.
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 [mailto:digydigy@gmail.com] 
Sent: Thursday, March 03, 2011 12:16 PM
To: lucene-net-dev@lucene.apache.org
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*,
IndexWriter.DEFAULT_MAX_FIELD_LENGTH);
	......
	writer.AddDocument(doc);

DIGY

-----Original Message-----
From: Wen Gao [mailto:samuel.gaowen@gmail.com] 
Sent: Thursday, March 03, 2011 1:43 AM
To: lucene-net-dev@lucene.apache.org
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.

Thanks,
Wen

2011/3/2 Digy <di...@gmail.com>

>
> First of all, your code doesn't mean anything to me other than you add
some
> 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.
>
> DIGY
>
> 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 [mailto:samuel.gaowen@gmail.com]
> Sent: Wednesday, March 02, 2011 11:02 PM
> To: lucene-net-dev@lucene.apache.org
> 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
>
>


RE: [Lucene.Net] how to add a new record to existing index

Posted by Digy <di...@gmail.com>.
I don't think that I understand your problem.
Is it something like 
	IndexWriter writer = new IndexWriter(path, analyzer, *false*,
IndexWriter.DEFAULT_MAX_FIELD_LENGTH);
	......
	writer.AddDocument(doc);

DIGY

-----Original Message-----
From: Wen Gao [mailto:samuel.gaowen@gmail.com] 
Sent: Thursday, March 03, 2011 1:43 AM
To: lucene-net-dev@lucene.apache.org
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.

Thanks,
Wen

2011/3/2 Digy <di...@gmail.com>

>
> First of all, your code doesn't mean anything to me other than you add
some
> 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.
>
> DIGY
>
> 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 [mailto:samuel.gaowen@gmail.com]
> Sent: Wednesday, March 02, 2011 11:02 PM
> To: lucene-net-dev@lucene.apache.org
> 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
>
>


Re: [Lucene.Net] how to add a new record to existing index

Posted by Wen Gao <sa...@gmail.com>.
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.

Thanks,
Wen

2011/3/2 Digy <di...@gmail.com>

>
> First of all, your code doesn't mean anything to me other than you add some
> 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.
>
> DIGY
>
> 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 [mailto:samuel.gaowen@gmail.com]
> Sent: Wednesday, March 02, 2011 11:02 PM
> To: lucene-net-dev@lucene.apache.org
> 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
>
>

RE: [Lucene.Net] how to add a new record to existing index

Posted by Digy <di...@gmail.com>.
First of all, your code doesn't mean anything to me other than you add some
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.

DIGY

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 [mailto:samuel.gaowen@gmail.com] 
Sent: Wednesday, March 02, 2011 11:02 PM
To: lucene-net-dev@lucene.apache.org
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