lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "srinivas.t@aksha.in" <sriniva...@aksha.in>
Subject How to delete multiple documents
Date Thu, 21 Feb 2008 13:14:21 GMT

In the Following Code if i insert one document i was
able to delete but when i insert multiple documents i
was unable to delete.

please follow the code and advice me 

thanks
srinvias.



            // Code to index Documents
            for (int count = 1; count < 10; count++)
            {
                String CatID = "13";
                String FieldName = "Field-" + count;

                document.add(Field.Text("FieldName",
FieldName));
                document.add(Field.Keyword("CatID",
CatID));
                Analyzer analyzer = new
StandardAnalyzer();
                IndexWriter writer = new
IndexWriter(indexDirectory, analyzer, false);
                writer.addDocument(document);
                writer.optimize();
                writer.close();
            }

            //Code to delete Documents
            Hits objhits = null;
            IndexSearcher is = new
IndexSearcher(LuceneHandle.indexFields);
            Analyzer analyzer = new StandardAnalyzer();
            QueryParser parser = new
QueryParser("CatID", analyzer);
            Query query = parser.parse("13");
            objhits = is.search(query);

            IndexReader ir =
IndexReader.open(LuceneHandle.indexFields);
            for(int i=0;i<objhits.length();i++)
            {
                 Document doc = objhits.doc(i);

                 String [] strtemp = 
doc.getValues("CatID");

                 if(strtemp!=null)
                 for(int tempcount
=0;tempcount<strtemp.length;tempcount++)
                  {  
                    Term uidTerm = new Term("CatID",
"13");
                    int DelCount = ir.delete(uidTerm);
                 }
            }


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Mime
View raw message