lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Keegan" <peterlkee...@gmail.com>
Subject Re: How to delete multiple documents
Date Thu, 21 Feb 2008 23:53:15 GMT
srinivas,

Create your IndexWriter and Analyzer once before your loop.
I suggest you follow up any questions to the 'java-user' list.

Peter

On Thu, 21 Feb 2008 13:14:21 -00, srinivas.t@aksha.in <srinivas.t@aksha.in>
wrote:

>
> 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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message