Remove Docs from Index

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Remove Docs from Index

Fernando G Bernardino
Hi People!

My app needs to update documents from index, so I have to remove and
insert again, all right?

First I wrote this code:
---
        IndexReader reader = null;
        try
        {
            String index = Webp.getProperty("webp.search.indexFolder");
            Directory directory = FSDirectory.getDirectory(index, false);
           
            reader = IndexReader.open(directory);
            reader.delete(new Term("contentPid",
String.valueOf("C_"+content.pidObject())));
        }
        ....
---

But It's not working well.. I want to use de method 'reader.delete(int)'
but I can't discover the document 'ID' to use as parameter.
I wrote some code to return the documents that I have to delete. How can
I get that ID?

Thanks!

--
Fernando Bernardino

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Remove Docs from Index

Erick Erickson
When you say it isn't working very well, what do you mean? It's slow? It's
not removing what you expect? If the latter, I suspect you're tokenizing the
term when you index such that it's not being found correctly....

You need to, somehow, get the Lucene document ID to remove. You can either
do a search, or you can use the termenum/termdocs classes to find out what
documents contain the term you want.


Best
Erick

On 1/10/07, Fernando G Bernardino <[hidden email]> wrote:

>
> Hi People!
>
> My app needs to update documents from index, so I have to remove and
> insert again, all right?
>
> First I wrote this code:
> ---
>         IndexReader reader = null;
>         try
>         {
>             String index = Webp.getProperty("webp.search.indexFolder");
>             Directory directory = FSDirectory.getDirectory(index, false);
>
>             reader = IndexReader.open(directory);
>             reader.delete(new Term("contentPid",
> String.valueOf("C_"+content.pidObject())));
>         }
>         ....
> ---
>
> But It's not working well.. I want to use de method 'reader.delete(int)'
> but I can't discover the document 'ID' to use as parameter.
> I wrote some code to return the documents that I have to delete. How can
> I get that ID?
>
> Thanks!
>
> --
> Fernando Bernardino
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Remove Docs from Index

Doron Cohen
In reply to this post by Fernando G Bernardino
Fernando, this code seems okay, in what sense is it "not working well"?

One thing to verify is that the "contentPid" field you are deleting by was
added to the index with Index.UN_TOKENIZED, otherwise the analyzer in use
while indexing might have broken or lower-cased that term (e.g.
"contentPid:C_1078") and in that case the delete-by-term would not delete
anything.

Deleting by term is a cleaner way to go, well, cleaner than deleting by id,
but if you prefer, you can do a search for the appropriate term, extract
the  docid (or docids) from the search result, and then use the (same)
reader to delete by docid. Make sure to use the same reader, because docids
found in one reader are not necessarily valid in another reader.

Fernando G Bernardino <[hidden email]> wrote on 10/01/2007
09:48:53:

> Hi People!
>
> My app needs to update documents from index, so I have to remove and
> insert again, all right?
>
> First I wrote this code:
> ---
>         IndexReader reader = null;
>         try
>         {
>             String index = Webp.getProperty("webp.search.indexFolder");
>             Directory directory = FSDirectory.getDirectory(index, false);
>
>             reader = IndexReader.open(directory);
>             reader.delete(new Term("contentPid",
> String.valueOf("C_"+content.pidObject())));
>         }
>         ....
> ---
>
> But It's not working well.. I want to use de method 'reader.delete(int)'
> but I can't discover the document 'ID' to use as parameter.
> I wrote some code to return the documents that I have to delete. How can
> I get that ID?
>
> Thanks!
>
> --
> Fernando Bernardino
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]