You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by pashupathinath <pa...@yahoo.com> on 2005/04/08 07:42:06 UTC

Updating Index.

hi,
  i've created an index for database records. the
problem is whenever i'm trying to update the database,
i mean adding or deleting records from the database i
want the index to be updated too.
   right now, i am adding new documents to the
existing index whenever i add new records to the
database. 
   the main problem is how do i traverse through the
existing index so that i wont add duplicate records in
the index. i can use my primary key to check for
duplicate records in the index. 
   how can i traverse through the values stored in the
index and make sure that the new records are not
duplicated ? once i encounter the duplicate primary
key, i should be able to delete all the various fields
values associated with that primary key.
   

thanks,
pashupathinath.k

Send instant messages to your online friends http://uk.messenger.yahoo.com 

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


Re: Updating Index.

Posted by Morus Walter <mo...@tanto.de>.
pashupathinath writes:
>    how can i traverse through the values stored in the
> index and make sure that the new records are not
> duplicated ? once i encounter the duplicate primary
> key, i should be able to delete all the various fields
> values associated with that primary key.
>    
There's no way to delete fields of a document in lucene. You can only 
delete documents. So update means to delete the old document for a 
given record and add the new record.

Deletion can be done based on the pk? Lucene will do the index search 
for you:
http://lucene.apache.org/java/docs/api/org/apache/lucene/index/IndexReader.html#delete(org.apache.lucene.index.Term)

The hard part is that you cannot have an index reader doing deletions
and an index writer doing document adds at the same time.
So you have to delete first and add then.

You can access all documents having a certain term using 
http://lucene.apache.org/java/docs/api/org/apache/lucene/index/IndexReader.html#termDocs(org.apache.lucene.index.Term)
if you really want to do that yourself...

HTH
	Morus

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


Re: Updating Index.

Posted by Paul Elschot <pa...@xs4all.nl>.
On Friday 08 April 2005 07:42, pashupathinath wrote:
> hi,
>   i've created an index for database records. the
> problem is whenever i'm trying to update the database,
> i mean adding or deleting records from the database i
> want the index to be updated too.
>    right now, i am adding new documents to the
> existing index whenever i add new records to the
> database. 
>    the main problem is how do i traverse through the
> existing index so that i wont add duplicate records in
> the index. i can use my primary key to check for
> duplicate records in the index. 
>    how can i traverse through the values stored in the
> index and make sure that the new records are not
> duplicated ? once i encounter the duplicate primary
> key, i should be able to delete all the various fields
> values associated with that primary key.

Lucene does not provide this, ie. one can add
any document to the an index as often as one wants.
That means that it is necessary to implement
the identity yourself, eg. by using one field as primary
key, and/or use some hash of the document content
in another field.
Before adding a new document, one can lookup the
old one and check whether it should be deleted or not.

Updating documents is done by deletion and insertion
and this is best done in batches for efficiency.

Regards,
Paul Elschot


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