lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <luc...@mikemccandless.com>
Subject Re: Deleted documents in the index.
Date Fri, 25 Jul 2008 12:18:59 GMT

When you call updateDocument, the old  document is deleted but a  
wholly new document is added.  So the "else" clause in your loop below  
will report on the newly added documents (you won't miss any).

Mike

(Nagesh S) wrote:

> Hi,
> I think, the earlier mail didn't make it through.
>
> I am writing a class to report on an index. This index has documents
> updated using the IndexWriter.updateDocument(Term, Document) method.
> That is, documents were deleted and added again. My aim is to see what
> documents (and their fields) are present in the index. Since the
> document was updated (i.e. deleted and added), it is marked as deleted
> and hence not able to obtain a Document object for the updated
> document.
>
> How do I report on such documents ?
>
> for (int i = 1; i < numDocs; i++) {
> //ir is an IndexReader object
>            if (ir.isDeleted(i)) {
>                bw.write("Document " + i + " has been deleted.");
>                bw.newLine();
>            } else {
>                Document d = getDocument(ir, i);
>
>                List<Field> l = d.getFields();
>                int numFields = l.size();
>                bw.write("Document has " + numFields + " fields as  
> follows");
>                bw.newLine();
>
>                for (int j = 0; j < numFields; j++) {
>                    String fieldName = l.get(j).name();
>                    bw.write("\t Field : " + fieldName + " Value : "
>                            + d.getField(fieldName).stringValue());
>                    bw.newLine();
>                }
>            }
>        }
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message