Hi
Mr Wolf  What is this

    // remove the document from index
        int docID = hits.id(0);

 and can I increment the "0" factor  in the bracket ...for deletion


Thx in advance

Karthik

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 23, 2004 5:33 PM
To: [EMAIL PROTECTED]
Subject: AW: Delete Indexed from Merged Document


Hello,
> Karthik N S [mailto:[EMAIL PROTECTED]
>
>    Has Somebody out there tried DELETING/UPDATION  of
> INDEXED Files from a
> MERGED Index Format,
>   If HowTo do this Please Explain....
Of course you can delete or update a document from a merged index.
It works in the same way as for all other indexes. You need an
unique key (e.g. the file name or uri), which is indexed
for searching, to find the right document, because the internal
document numbers are changed after merging indexes or deleting
documents and optimizing an index. Using this key you can search
for the document and remove it. It doesn't matter if your index
was created by merging serveral indexes or not.
Example:
/* Create index: */
        Document document = new Document();
        document.add(Field.Keyword("filename", file_name)); // this must be
unique for each document!
        document.add(Field.Text("content", file_content));
        writer.addDocument(document);
/* ... */
      writer.close();

/* Update or remove document: Use the file name to find the original
   document and remove it from index */
  FSDirectory indexDirectory = FSDirectory.getDirectory("indexPath", false);
  IndexReader indexReader = IndexReader.open(indexDirectory);
  IndexSearcher indexSearcher = new IndexSearcher(indexReader);
  // create query and search for document using its filename
  TermQuery query = new TermQuery(new Term("filename", file_name));
  Hits hits = indexSearcher.search(query);
  if ( hits.length() > 0 ) {
      // remove the document from index
        int docID = hits.id(0);
      indexReader.delete( docID );
  }
  // else: this is a new file or already removed, so we can simply add it.
  indexSearcher.close();
  indexReader.close();
  indexDirectory.close();
  // now open an IndexWriter for the same index and add the updated file
  // as new document....
/* done */
Hope it helps. Regards,
        Wolf-Dietrich Materna

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to