You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by "Edward W. Rouse" <er...@comsquared.com> on 2012/05/17 16:19:18 UTC

IndexWriter.deleteDocuments(Term) only deletes one at a time

Below is the relevant portion of the code were this occurs. I have a test
index with 100 Documents that all have 1 Term that is the same across all
Documents. When I run this code using that Term and the common value, it
only deletes one document. Every time I rerun the code with the same values
it deletes another one. Am I doing something wrong? I can't figure out why
it doesn't delete them all with one call to this code.

this.getWriter(indexName).deleteDocuments(this.createIdTerm(id));
this.getWriter(indexName).commit();


  private IndexWriter getWriter(String index) throws IOException
  {
    if(writers.containsKey(index))
    {
      return writers.get(index);
    }
    else
    {
      return addWriter(index);
    }
  }

  private Term createIdTerm(String id)
  {
    return new Term(Constants.DEFAULT_ID_FIELD, id);
  }

  public IndexWriterConfig getWriterConfig()
  {
    if(writerConfig == null)
    {
      Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_36);
      writerConfig = new IndexWriterConfig(Version.LUCENE_36, analyzer);
    }
    return writerConfig;
  }

  private IndexWriter addWriter(String index) throws IOException
  {
    if(writers.containsKey(index))
    {
      return writers.get(index);
    }
    else
    {
      File f = new File(Constants.ROOT_DIR + index);
      FSDirectory d = FSDirectory.open(f);
      IndexWriter writer = new IndexWriter(d, getWriterConfig());
      writers.put(index, writer);
      return writer;
    }
  }
  
Edward W. Rouse
Comsquared System, Inc.
770-734-5301




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


RE: IndexWriter.deleteDocuments(Term) only deletes one at a time

Posted by "Edward W. Rouse" <er...@comsquared.com>.
Never mind, turns out the Term isn't matching for some as yet unknown reason
and the feedback in my logs was misleading. Sorry for the noise.

> -----Original Message-----
> From: Edward W. Rouse [mailto:erouse@comsquared.com]
> Sent: Thursday, May 17, 2012 10:19 AM
> To: java-user@lucene.apache.org
> Subject: IndexWriter.deleteDocuments(Term) only deletes one at a time
> 
> Below is the relevant portion of the code were this occurs. I have a
> test
> index with 100 Documents that all have 1 Term that is the same across
> all
> Documents. When I run this code using that Term and the common value,
> it
> only deletes one document. Every time I rerun the code with the same
> values
> it deletes another one. Am I doing something wrong? I can't figure out
> why
> it doesn't delete them all with one call to this code.
> 
> this.getWriter(indexName).deleteDocuments(this.createIdTerm(id));
> this.getWriter(indexName).commit();
> 
> 
>   private IndexWriter getWriter(String index) throws IOException
>   {
>     if(writers.containsKey(index))
>     {
>       return writers.get(index);
>     }
>     else
>     {
>       return addWriter(index);
>     }
>   }
> 
>   private Term createIdTerm(String id)
>   {
>     return new Term(Constants.DEFAULT_ID_FIELD, id);
>   }
> 
>   public IndexWriterConfig getWriterConfig()
>   {
>     if(writerConfig == null)
>     {
>       Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_36);
>       writerConfig = new IndexWriterConfig(Version.LUCENE_36,
> analyzer);
>     }
>     return writerConfig;
>   }
> 
>   private IndexWriter addWriter(String index) throws IOException
>   {
>     if(writers.containsKey(index))
>     {
>       return writers.get(index);
>     }
>     else
>     {
>       File f = new File(Constants.ROOT_DIR + index);
>       FSDirectory d = FSDirectory.open(f);
>       IndexWriter writer = new IndexWriter(d, getWriterConfig());
>       writers.put(index, writer);
>       return writer;
>     }
>   }
> 
> Edward W. Rouse
> Comsquared System, Inc.
> 770-734-5301
> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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