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 "Paul J. Lucas" <pa...@lucasmail.org> on 2009/10/27 04:10:34 UTC

Deleting documents using "starts with"

I currently have code that looks like:

     Term[] terms = new Term[]{
         new Term( key1, value1 ),
         new Term( key2, value2 )
     };
     writer.deleteDocuments( terms );

I want to change things such that it will delete all documents having  
key2's value start with value2, i.e., if value2 were "foo" then I want  
all documents to be deleted where key2's value starts with  
"foo" (i.e., "foo*").

I still want key1's value to match value1 exactly, however.

What's the simplest way to do do what I want?  Thanks.

- Paul

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


Re: Deleting documents using "starts with"

Posted by Ian Lea <ia...@gmail.com>.
There are IndexWriter.deleteDocuments methods that take queries.
Passing a TermQuery and a WildcardQuery to
writer.deleteDocuments(Query[]) should do the trick.


--
Ian.


On Tue, Oct 27, 2009 at 3:10 AM, Paul J. Lucas <pa...@lucasmail.org> wrote:
> I currently have code that looks like:
>
>    Term[] terms = new Term[]{
>        new Term( key1, value1 ),
>        new Term( key2, value2 )
>    };
>    writer.deleteDocuments( terms );
>
> I want to change things such that it will delete all documents having key2's
> value start with value2, i.e., if value2 were "foo" then I want all
> documents to be deleted where key2's value starts with "foo" (i.e., "foo*").
>
> I still want key1's value to match value1 exactly, however.
>
> What's the simplest way to do do what I want?  Thanks.
>
> - Paul
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

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