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 lu...@ajm.co.nz on 2002/10/09 13:50:50 UTC
Deleting a document found in a search
I am just getting started with Lucene and I think I have a problem
understanding some basic concepts.
I am using two-part identifiers to uniquely identify a document in the
index. So whenever I want to index a document, I first want to find and
delete the old form.
To find it, I intend to use:
BooleanQuery findOurs = new BooleanQuery();
findOurs.add(new TermQuery(new Term("Id", id)), true, false);
findOurs.add(new TermQuery(new Term("Domain", domain)), true, false);
System.out.println("Deleting document matching: \"" +
findOurs.toString("") + '"');
Searcher searcher = new IndexSearcher(directory);
Hits hits = searcher.search(findOurs);
// Assert: hits.length() <= 1
for (int i = 0 ; i < hits.length() && i < 10; i++) {
Document d = hits.doc(i);
// Now what can I do to find document id?
int id = ??????
searcher.delete(id);
}
But I can't discover how to convert a search result into a document id. It
is recorded in the private HitDoc class, but since it is not publicly
accessible, there must be a reason why it would not work to add a public
getter for it.
Is there an alternative way that I can do this? My first thought is to
define a Field.Keyword("composite-key", domain + "\u0000" + id). This
would allow me to use the delete(Term) interface to delete the key.
--
Thanks, Adrian.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Deleting a document found in a search
Posted by Doug Cutting <cu...@lucene.com>.
lucene.user@ajm.co.nz wrote:
> My first thought is to
> define a Field.Keyword("composite-key", domain + "\u0000" + id). This
> would allow me to use the delete(Term) interface to delete the key.
That sounds like a good way to solve this.
You could also use a HitCollector with a Query, but I think the
composite key is a better approach.
Doug
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Deleting a document found in a search
Posted by lu...@ajm.co.nz.
No, I mean HitDoc.id, the document number field stored in
the HitDoc class. This number is needed when calling
IndexReader.delete(int docnum) but it is not publicly
accessible.
--
Adrian
At 06:32 09/10/2002 -0700, Otis Gospodnetic wrote:
>You mean d.get("Id"); ?
>
>--- lucene.user@ajm.co.nz wrote:
>> I am just getting started with Lucene and I think I have
>> a problem understanding some basic concepts.
>>
>> I am using two-part identifiers to uniquely identify a
>> document in the index. So whenever I want to index a
>> document, I first want to find and delete the old form.
>>
>> To find it, I intend to use:
>>
>> BooleanQuery findOurs = new BooleanQuery();
>> findOurs.add(new TermQuery(new Term("Id", id)), true, false);
>> findOurs.add(new TermQuery(new Term("Domain", domain)), true, false);
>>
>> System.out.println("Deleting document matching: \"" +
>> findOurs.toString("") + '"');
>>
>> Searcher searcher = new IndexSearcher(directory);
>> Hits hits = searcher.search(findOurs);
>>
>> // Assert: hits.length() <= 1
>>
>> for (int i = 0 ; i < hits.length() && i < 10; i++) {
>> Document d = hits.doc(i);
>>
>> // Now what can I do to find document id?
>>
>> int id = ??????
>> searcher.delete(id);
>> }
>>
>> But I can't discover how to convert a search result into
>> a document id. It is recorded in the private HitDoc
>> class, but since it is not publicly accessible, there
>> must be a reason why it would not work to add a public
>> getter for it.
>>
>> Is there an alternative way that I can do this? My first
>> thought is to define a Field.Keyword("composite-key",
>> domain + "\u0000" + id). This would allow me to use the
>> delete(Term) interface to delete the key.
>>
>> --
>> Thanks, Adrian.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Deleting a document found in a search
Posted by Otis Gospodnetic <ot...@yahoo.com>.
You mean d.get("Id"); ?
Otis
--- lucene.user@ajm.co.nz wrote:
> I am just getting started with Lucene and I think I have a problem
> understanding some basic concepts.
>
> I am using two-part identifiers to uniquely identify a document in
> the
> index. So whenever I want to index a document, I first want to find
> and
> delete the old form.
>
> To find it, I intend to use:
>
> BooleanQuery findOurs = new BooleanQuery();
> findOurs.add(new TermQuery(new Term("Id", id)), true, false);
> findOurs.add(new TermQuery(new Term("Domain", domain)), true,
> false);
>
> System.out.println("Deleting document matching: \"" +
> findOurs.toString("") + '"');
>
> Searcher searcher = new IndexSearcher(directory);
> Hits hits = searcher.search(findOurs);
>
> // Assert: hits.length() <= 1
>
> for (int i = 0 ; i < hits.length() && i < 10; i++) {
> Document d = hits.doc(i);
>
> // Now what can I do to find document id?
>
> int id = ??????
> searcher.delete(id);
> }
>
> But I can't discover how to convert a search result into a document
> id. It
> is recorded in the private HitDoc class, but since it is not publicly
> accessible, there must be a reason why it would not work to add a
> public
> getter for it.
>
> Is there an alternative way that I can do this? My first thought is
> to
> define a Field.Keyword("composite-key", domain + "\u0000" + id).
> This
> would allow me to use the delete(Term) interface to delete the key.
>
> --
> Thanks, Adrian.
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>