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 Pulkit Singhal <pu...@gmail.com> on 2011/04/13 15:15:15 UTC

Update Document based on Query instead of Term

Lucene's IndexWriter allows users to update documents by Term via this
method signature:
void updateDocument(Term term, Document doc)

But what about updating them by Query? Like so:
void updateDocument(Query query, Document doc)

1) How can this be done? As far as I know there is no such method
signature right now. In my data there is no way for me to uniquely
identify a document for update without matching more that one term, so
I really need to use a Query.
2) Would it be better to change the initial underlying indexing
process such that the multiple fields (that can identify a unique
document) will be concatenated into one string and indexed? Then that
field can be used for identification when doing updates? Is this the
common practice?
3) Or, would it be better to use the Query I have to search for the
docID that the Lucene index assigns to the data inside it and then try
to update based on that? Will I get in trouble here somehow?

Any tips are appreciated.

Thanks!
- Pulkit

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


Re: Update Document based on Query instead of Term

Posted by David Causse <dc...@spotter.com>.
On Wed, Apr 13, 2011 at 09:15:15AM -0400, Pulkit Singhal wrote:
> Lucene's IndexWriter allows users to update documents by Term via this
> method signature:
> void updateDocument(Term term, Document doc)
> 
> But what about updating them by Query? Like so:
> void updateDocument(Query query, Document doc)

Hi,

as updateDocument(Term t, Document d) is just a delete + add, you can
use :
IndexWriter.delete(Query query);
IndexWriter.add(Document d);

Regards.

-- 
David Causse
Spotter
http://www.spotter.com/

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


Re: Update Document based on Query instead of Term

Posted by Anshum <an...@gmail.com>.
So Update basically is nothing but delete and add (a fresh doc). You could
just go ahead at using the deletedocument(Query query) function and then
adding the new document? That is the general approach for such cases and it
works just about fine.

--
Anshum Gupta
http://ai-cafe.blogspot.com


On Wed, Apr 13, 2011 at 6:45 PM, Pulkit Singhal <pu...@gmail.com>wrote:

> Lucene's IndexWriter allows users to update documents by Term via this
> method signature:
> void updateDocument(Term term, Document doc)
>
> But what about updating them by Query? Like so:
> void updateDocument(Query query, Document doc)
>
> 1) How can this be done? As far as I know there is no such method
> signature right now. In my data there is no way for me to uniquely
> identify a document for update without matching more that one term, so
> I really need to use a Query.
> 2) Would it be better to change the initial underlying indexing
> process such that the multiple fields (that can identify a unique
> document) will be concatenated into one string and indexed? Then that
> field can be used for identification when doing updates? Is this the
> common practice?
> 3) Or, would it be better to use the Query I have to search for the
> docID that the Lucene index assigns to the data inside it and then try
> to update based on that? Will I get in trouble here somehow?
>
> Any tips are appreciated.
>
> Thanks!
> - Pulkit
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>