Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Lucene: General

Remove Document in Lucene is not working. Code Snippet added to help.

 

 

Lucene general RSS feed   Index | Next | Previous | View Threaded


gubs4u at gmail

Dec 13, 2011, 7:44 AM

Post #1 of 3 (307 views)
Permalink
Remove Document in Lucene is not working. Code Snippet added to help.

Hi,

I created a new document with 2 fields below code.

String[] names = {"Gubendran", "kavitha"};
for ( String name : names) {
luceneIndexWriter.createDocument(iw, name);
}


private void createDocument(IndexWriter iw, String name) throws
CorruptIndexException,
IOException {
// Creating document to add using indexWriter
Document doc = new Document();

Field nameField = new Field("name", name, Field.Store.YES,
Field.Index.ANALYZED);

// Add fields into document
doc.add(nameField);
iw.addDocument(doc);
}

Later used below code to delete document. But, when i do indexSearcher the
data in document still exist. Any help ?
// Delete the Document
luceneIndexWriter.deleteDocument("Gubendran");

private void deleteDocument(String name) throws IOException {
Directory dir = FSDirectory.open(new File(INDEX_DIR));
IndexReader ir = IndexReader.open(dir, false);
ir.deleteDocuments(new Term("name", "Gubendran"));
ir.close();
}

Thanks and i appreciate

Gubs


--
View this message in context: http://lucene.472066.n3.nabble.com/Remove-Document-in-Lucene-is-not-working-Code-Snippet-added-to-help-tp3582660p3582660.html
Sent from the Lucene - General mailing list archive at Nabble.com.


dawn at digitorial

Dec 13, 2011, 7:52 AM

Post #2 of 3 (298 views)
Permalink
Re: Remove Document in Lucene is not working. Code Snippet added to help. [In reply to]

Does your analyser lower case things by any chance?
If so that delete will never find anything to delete...

Dawn

On 13/12/2011 15:44, gubs wrote:
> Hi,
>
> I created a new document with 2 fields below code.
>
> String[] names = {"Gubendran", "kavitha"};
> for ( String name : names) {
> luceneIndexWriter.createDocument(iw, name);
> }
>
>
> private void createDocument(IndexWriter iw, String name) throws
> CorruptIndexException,
> IOException {
> // Creating document to add using indexWriter
> Document doc = new Document();
>
> Field nameField = new Field("name", name, Field.Store.YES,
> Field.Index.ANALYZED);
>
> // Add fields into document
> doc.add(nameField);
> iw.addDocument(doc);
> }
>
> Later used below code to delete document. But, when i do indexSearcher the
> data in document still exist. Any help ?
> // Delete the Document
> luceneIndexWriter.deleteDocument("Gubendran");
>
> private void deleteDocument(String name) throws IOException {
> Directory dir = FSDirectory.open(new File(INDEX_DIR));
> IndexReader ir = IndexReader.open(dir, false);
> ir.deleteDocuments(new Term("name", "Gubendran"));
> ir.close();
> }
>
> Thanks and i appreciate
>
> Gubs
>
>

--

Rgds.
*Dawn Raison*


gubs4u at gmail

Dec 13, 2011, 1:10 PM

Post #3 of 3 (291 views)
Permalink
Re: Remove Document in Lucene is not working. Code Snippet added to help. [In reply to]

Yes, my analyser converts to lower case. I am using standardAnalyser. You
guys are so smart in this forum. I passed lowercase in Term and i am able to
delete the Document.

Gubs

--
View this message in context: http://lucene.472066.n3.nabble.com/Remove-Document-in-Lucene-is-not-working-Code-Snippet-added-to-help-tp3582660p3583637.html
Sent from the Lucene - General mailing list archive at Nabble.com.

Lucene general RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.