FAQ
Hi,

I tried 3-4 ways to delete a document but still no results. I am using
Lucene 3.1

I used writer.UpdateDocuments(Term term, Document d)
as well as write.addDocument(d); and after that writer.deleteDocuments(d);

Using both I am not able to delete the previous document.

Is there any problem in my code?

String q1 = contract.getDocId();
Term term = new Term(contract.getDocId()); // where DocId is my field
try {
writer.deleteDocuments(term);
System.out.println("Deleting Document with the term "+term);
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
}
d.add(new Field("DocId",q1,Field.Store.YES,Field.Index.NOT_ANALYZED));
writer.addDocument(d);
writer.optimize() ;
writer.close();


Same is the result when I use writer.updateDocument(term,d)

Search Discussions

  • Ian Lea at Jun 10, 2011 at 9:52 am
    Try Term term = new Term("DocId", contract.getDocId());. See the
    javadocs for the difference between that and what you have.

    You don't need to call optimize() all the time, it at all.


    --
    Ian.


    On Fri, Jun 10, 2011 at 9:24 AM, Pranav goyal
    wrote:
    Hi,

    I tried 3-4 ways to delete a document but still no results. I am using
    Lucene 3.1

    I used writer.UpdateDocuments(Term term, Document d)
    as well as write.addDocument(d); and after that writer.deleteDocuments(d);

    Using both I am not able to delete the previous document.

    Is there any problem in my code?

    String q1 = contract.getDocId();
    Term term = new Term(contract.getDocId()); // where DocId is my field
    try {
    writer.deleteDocuments(term);
    System.out.println("Deleting Document with the term "+term);
    } catch (IOException e) {
    e.printStackTrace();  //To change body of catch statement use
    File | Settings | File Templates.
    }
    d.add(new Field("DocId",q1,Field.Store.YES,Field.Index.NOT_ANALYZED));
    writer.addDocument(d);
    writer.optimize() ;
    writer.close();


    Same is the result when I use writer.updateDocument(term,d)
    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Pranav goyal at Jun 10, 2011 at 10:21 am
    Hi Ian,

    Thanks for your reply. But even this isn't working.
    My document is not getting deleted.

    Can you please suggest me something else?


    On Fri, Jun 10, 2011 at 3:21 PM, Ian Lea wrote:

    Try Term term = new Term("DocId", contract.getDocId());. See the
    javadocs for the difference between that and what you have.

    You don't need to call optimize() all the time, it at all.


    --
    Ian.


    On Fri, Jun 10, 2011 at 9:24 AM, Pranav goyal
    wrote:
    Hi,

    I tried 3-4 ways to delete a document but still no results. I am using
    Lucene 3.1

    I used writer.UpdateDocuments(Term term, Document d)
    as well as write.addDocument(d); and after that
    writer.deleteDocuments(d);
    Using both I am not able to delete the previous document.

    Is there any problem in my code?

    String q1 = contract.getDocId();
    Term term = new Term(contract.getDocId()); // where DocId is my field
    try {
    writer.deleteDocuments(term);
    System.out.println("Deleting Document with the term "+term);
    } catch (IOException e) {
    e.printStackTrace(); //To change body of catch statement use
    File | Settings | File Templates.
    }
    d.add(new Field("DocId",q1,Field.Store.YES,Field.Index.NOT_ANALYZED));
    writer.addDocument(d);
    writer.optimize() ;
    writer.close();


    Same is the result when I use writer.updateDocument(term,d)
    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org

    --
    I'm very responsible, when ever something goes wrong they always say I'm
    responsible --
  • Pranav goyal at Jun 10, 2011 at 10:50 am
    When I am using a deleteAll() instead of deleteDocuments();

    it's working fine.
    What can be the problem. Still not able to figure it out.
    On Fri, Jun 10, 2011 at 3:50 PM, Pranav goyal wrote:

    Hi Ian,

    Thanks for your reply. But even this isn't working.
    My document is not getting deleted.

    Can you please suggest me something else?



    On Fri, Jun 10, 2011 at 3:21 PM, Ian Lea wrote:

    Try Term term = new Term("DocId", contract.getDocId());. See the
    javadocs for the difference between that and what you have.

    You don't need to call optimize() all the time, it at all.


    --
    Ian.


    On Fri, Jun 10, 2011 at 9:24 AM, Pranav goyal
    wrote:
    Hi,

    I tried 3-4 ways to delete a document but still no results. I am using
    Lucene 3.1

    I used writer.UpdateDocuments(Term term, Document d)
    as well as write.addDocument(d); and after that
    writer.deleteDocuments(d);
    Using both I am not able to delete the previous document.

    Is there any problem in my code?

    String q1 = contract.getDocId();
    Term term = new Term(contract.getDocId()); // where DocId is my field
    try {
    writer.deleteDocuments(term);
    System.out.println("Deleting Document with the term "+term);
    } catch (IOException e) {
    e.printStackTrace(); //To change body of catch statement use
    File | Settings | File Templates.
    }
    d.add(new Field("DocId",q1,Field.Store.YES,Field.Index.NOT_ANALYZED));
    writer.addDocument(d);
    writer.optimize() ;
    writer.close();


    Same is the result when I use writer.updateDocument(term,d)
    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org

    --
    I'm very responsible, when ever something goes wrong they always say I'm
    responsible --


    --
    I'm very responsible, when ever something goes wrong they always say I'm
    responsible --
  • Danny Lade at Jun 10, 2011 at 11:15 am

    You delete it first using your id:

    writer.deleteDocuments(term);
    and then re-add it with the same id:

    writer.addDocument(d);
    >

    Please explain:
    How looks your document BEFORE you try to delete it? (Which fields has it?)

    Greetings Danny
  • Pranav goyal at Jun 10, 2011 at 11:25 am
    Hi Danny,

    I have explained it above.

    It has many fields out of which DocId is the field which I am storing as
    well as indexing. While other fields I am just storing.
    And Each document has unique DocId.

    d=new Document();
    File indexDir = new File("./index-dir");
    StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_31);
    IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_31, analyzer);
    try {
    writer = new IndexWriter(FSDirectory.open(indexDir),conf);
    } catch (IOException e1) {
    e1.printStackTrace();
    }
    String q1 = contract.getDocId(); // Here I am getting my DocId
    Term term = new Term("DocID",contract.getDocId());


    Rest I have stated above.


    On Fri, Jun 10, 2011 at 4:44 PM, Danny Lade wrote:

    You delete it first using your id:
    writer.deleteDocuments(term);
    and then re-add it with the same id:

    writer.addDocument(d);
    Please explain:
    How looks your document BEFORE you try to delete it? (Which fields has it?)

    Greetings Danny


    --
    I'm very responsible, when ever something goes wrong they always say I'm
    responsible --
  • Ian Lea at Jun 10, 2011 at 11:35 am
    In different code samples you've got both DocId and DocID. If that
    isn't the problem I suggest you post a complete little program that
    demonstrates the problem. As small as possible, no external
    dependencies.


    --
    Ian.


    On Fri, Jun 10, 2011 at 12:24 PM, Pranav goyal
    wrote:
    Hi Danny,

    I have explained it above.

    It has many fields out of which DocId is the field which I am storing as
    well as indexing. While other fields I am just storing.
    And Each document has unique DocId.

    d=new Document();
    File indexDir = new File("./index-dir");
    StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_31);
    IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_31, analyzer);
    try {
    writer = new IndexWriter(FSDirectory.open(indexDir),conf);
    } catch (IOException e1) {
    e1.printStackTrace();
    }
    String q1 = contract.getDocId();    // Here I am getting my DocId
    Term term = new Term("DocID",contract.getDocId());


    Rest I have stated above.


    On Fri, Jun 10, 2011 at 4:44 PM, Danny Lade wrote:

    You delete it first using your id:
    writer.deleteDocuments(term);
    and then re-add it with the same id:

    writer.addDocument(d);
    Please explain:
    How looks your document BEFORE you try to delete it? (Which fields has it?)

    Greetings Danny


    --
    I'm very responsible, when ever something goes wrong they always say I'm
    responsible --
    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Erick Erickson at Jun 10, 2011 at 12:37 pm
    Well, taking the code all together, what I expect is
    that you'll have a document after all is done that
    only has a "DocId" in it. Nowhere do you fetch
    the document from the index.

    What is your evidence that you haven't deleted
    the document? If you haven't reopened your reader
    after the above, you'll see the old view of the index,
    so be sure you close/open your searcher afterwards.

    Ian's suggestion is the best I think, since the code
    fragments you've provided don't tell the complete
    story. If there's an error in contract.getDocID(), we
    can't see it to help.

    It might help to review:
    http://wiki.apache.org/solr/UsingMailingLists

    Best
    Erick
    On Fri, Jun 10, 2011 at 7:34 AM, Ian Lea wrote:
    In different code samples you've got both DocId and DocID.  If that
    isn't the problem I suggest you post a complete little program that
    demonstrates the problem.  As small as possible, no external
    dependencies.


    --
    Ian.


    On Fri, Jun 10, 2011 at 12:24 PM, Pranav goyal
    wrote:
    Hi Danny,

    I have explained it above.

    It has many fields out of which DocId is the field which I am storing as
    well as indexing. While other fields I am just storing.
    And Each document has unique DocId.

    d=new Document();
    File indexDir = new File("./index-dir");
    StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_31);
    IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_31, analyzer);
    try {
    writer = new IndexWriter(FSDirectory.open(indexDir),conf);
    } catch (IOException e1) {
    e1.printStackTrace();
    }
    String q1 = contract.getDocId();    // Here I am getting my DocId
    Term term = new Term("DocID",contract.getDocId());


    Rest I have stated above.


    On Fri, Jun 10, 2011 at 4:44 PM, Danny Lade wrote:

    You delete it first using your id:
    writer.deleteDocuments(term);
    and then re-add it with the same id:

    writer.addDocument(d);
    Please explain:
    How looks your document BEFORE you try to delete it? (Which fields has it?)

    Greetings Danny


    --
    I'm very responsible, when ever something goes wrong they always say I'm
    responsible --
    ---------------------------------------------------------------------
    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedJun 10, '11 at 8:25a
activeJun 10, '11 at 12:37p
posts8
users4
websitelucene.apache.org

People

Translate

site design / logo © 2022 Grokbase