You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Miguel Ferreira (JIRA)" <ji...@apache.org> on 2013/01/09 17:06:14 UTC
[jira] [Comment Edited] (LUCENE-4669) Document wrongly deleted from
index
[ https://issues.apache.org/jira/browse/LUCENE-4669?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13548607#comment-13548607 ]
Miguel Ferreira edited comment on LUCENE-4669 at 1/9/13 4:05 PM:
-----------------------------------------------------------------
I've seen the javadocs for numDocs and I still don't get why is it that when I delete de document with field path=a the document with field path=c is removed from the index.
Do you care to explain?
was (Author: miguelferreira):
I've seen the javadocs for numDocs and I still don't get why is it that when I delete de document with field path=a the document with field path=c is removed from the idnex.
Do you care to explain?
> Document wrongly deleted from index
> -----------------------------------
>
> Key: LUCENE-4669
> URL: https://issues.apache.org/jira/browse/LUCENE-4669
> Project: Lucene - Core
> Issue Type: Bug
> Components: core/index
> Affects Versions: 4.0
> Environment: OS = Mac OS X 10.7.5
> Java = JVM 1.6
> Reporter: Miguel Ferreira
>
> I'm trying to implement document deletion from an index.
> If I create an index with three documents (A, B and C) and then try to delete A, A gets marked as deleted but C is removed from the index. I've tried this with different number of documents and saw that it is always the last document that is removed.
> When I run the example unit test code bellow I get this output:
> {code}
> Before delete
> Found 3 documents
> Document at = 0; isDeleted = false; path = a;
> Document at = 1; isDeleted = false; path = b;
> Document at = 2; isDeleted = false; path = c;
> After delete
> Found 2 documents
> Document at = 0; isDeleted = true; path = a;
> Document at = 1; isDeleted = false; path = b;
> {code}
> Example unit test:
> {code:title=ExampleUnitTest.java}
> @Test
> public void delete() throws Exception {
> File indexDir = FileUtils.createTempDir();
> IndexWriter writer = new IndexWriter(new NIOFSDirectory(indexDir), new IndexWriterConfig(Version.LUCENE_40,
> new StandardAnalyzer(Version.LUCENE_40)));
> Document doc = new Document();
> String fieldName = "path";
> doc.add(new StringField(fieldName, "a", Store.YES));
> writer.addDocument(doc);
> doc = new Document();
> doc.add(new StringField(fieldName, "b", Store.YES));
> writer.addDocument(doc);
> doc = new Document();
> doc.add(new StringField(fieldName, "c", Store.YES));
> writer.addDocument(doc);
> writer.commit();
> System.out.println("Before delete");
> print(indexDir);
> writer.deleteDocuments(new Term(fieldName, "a"));
> writer.commit();
> System.out.println("After delete");
> print(indexDir);
> }
> public static void print(File indexDirectory) throws IOException {
> DirectoryReader reader = DirectoryReader.open(new NIOFSDirectory(indexDirectory));
> Bits liveDocs = MultiFields.getLiveDocs(reader);
> int numDocs = reader.numDocs();
> System.out.println("Found " + numDocs + " documents");
> for (int i = 0; i < numDocs; i++) {
> Document document = reader.document(i);
> StringBuffer sb = new StringBuffer();
> sb.append("Document at = ").append(i);
> sb.append("; isDeleted = ").append(liveDocs != null ? !liveDocs.get(i) : false).append("; ");
> for (IndexableField field : document.getFields()) {
> String fieldName = field.name();
> for (String value : document.getValues(fieldName)) {
> sb.append(fieldName).append(" = ").append(value).append("; ");
> }
> }
> System.out.println(sb.toString());
> }
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org