Java

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • deleteDocuments being ingnored

    1 answers - 1733 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hello,
    I'm brand new to this, so hopefully you can help me. I'm
    attempting to use the IndexReader object in lucene v2 to delete and readd
    documents. I very easily set up an index and my documents are added. Now
    I'm trying to update the same index by deleting the document before
    readding. The problem is that it appears that my deleteDocument()
    instruction is being ignored. I've tried using the IndexModifier object
    and the IndexReader and both have the same behavior. If anyone can point
    out my error, or help me debug this I'll be forever in your debt. Here is
    the jist of the code.
    This is the main section:
    IndexWriter writer = new IndexWriter(indexDir,new
    StandardAnalyzer(), false);
    writer.setUseCompoundFile(false);
    indexDirectory(writer, dataDir);
    int numIndexed = writer.docCount();
    writer.optimize();
    writer.close();
    Down at the point just before readding my document I have the following
    code (i know batch is better, just doing it this for now):
    IndexReader ir = IndexReader.open(indexDir);
    System.out.println("" + ir.numDocs());
    ir.delete(new Term("filename",f.getAbsolutePath()));
    System.out.println("deletes?" + ir.hasDeletions());
    ir.close();
    if (deleted 0) {
    System.out.println("deleted old index of " +
    f.getAbsolutePath());
    }
    System.out.println("Indexing " + f.getAbsolutePath());
    Document doc = new Document();
    doc.add(new Field("contents",loadContents
    (doc),Field.Store.N,Field.Index.TKENIZED));
    doc.add(new Field("filename",
    f.getAbsolutePath(),Field.Store.YES,Field.Index.TK ENIZED));
    writer.addDocument(doc);
    Thanks,
    Chris
  • No.1 | | 903 bytes | |

    System.out.println("Indexing " + f.getAbsolutePath());
    Document doc = new Document();
    doc.add(new Field("contents",loadContents
    (doc),Field.Store.N,Field.Index.TKENIZED));
    doc.add(new Field("filename",
    f.getAbsolutePath(),Field.Store.YES,Field.Index.TK ENIZED));
    writer.addDocument(doc);

    Hi Chris,

    Do you open the writer to add your "update" to before you close the
    indexreader to delete the outdated index document?
    Another question comes in mind, do you open a new IndexReader for your
    searches after the update was written to the index?

    You have to follow these steps:
    1. Add you document
    2. close writer
    3. open reader
    4. delete the outdated stuff
    5. close reader
    6. open writer
    7. add the update
    8. close writer
    9. release new searcher / reader

    hope that gives you a little help.

    best regards simon

Re: deleteDocuments being ingnored


max 4000 letters.
Your nickname that display:
In order to stop the spam: 9 + 8 =
QUESTION ON "Java"

EMSDN.COM