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 Doug Kirk <do...@dougandalli.com> on 2003/05/21 15:29:19 UTC

IndexReader.delete problem

Using 1.3-RC1, I've got an index where a keyword field contains the 
primary key value of a database row (an int), and when a user updates 
the data for the row, I delete the document from the index and then add 
it back.

My problem: The search index now only recognizes the document just 
updated; it seems as if every other document was deleted from the index.

I'm using IndexReader.delete(term), where term prints out as: 
Term<Event.PKID:153>, which looks okay to me. The field name is 
"Event.PKID", which is in Torque-generated "table.field" format.

As a temporary workaround, I recreate the entire index every time 
somebody submits a change.

Is this a Lucene bug, or could I be doing something wrong here?

Thanks!
-Doug.


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


Re: IndexReader.delete problem

Posted by Doug Kirk <do...@dougandalli.com>.
I always use a new IndexSearcher. I'm sure I've done something stupid 
here, though.


On Wednesday, May 21, 2003, at 10:55 AM, Otis Gospodnetic wrote:

> In your search code detect that the index changed and get a new
> IndexSearcher.
>


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


Re: IndexReader.delete problem

Posted by Otis Gospodnetic <ot...@yahoo.com>.
In your search code detect that the index changed and get a new
IndexSearcher.

Otis

--- Doug Kirk <do...@dougandalli.com> wrote:
> > Perhaps you are using 'new IndexWriter(path, analyzer, true)'
> rather
> > than 'new IndexWriter(path, analyzer, false)'?
> 
> Yes, that is what was happening.  (Big Thanks!)
> 
> Here's a new problem, though: after changing the above to 'new 
> IndexWriter(fsdirectory, analyzer, false)', my updated document no 
> longer shows up in searches. No exception is being thrown during the 
> entire updateObject() process.
> 
> The logic is:
> 
> void updateObject(Object bean)  throws IOException, IndexException {
>      deleteObject(bean);
>      insertObject(bean);
> }
> 
> void insertObject(Object bean)  throws IOException, IndexException {
>      IndexWriter writer = null;
>      try {
>          writer = getIndexWriter(false);    // false == create; uses 
> previously cached FSDirectory and StandardAnalyzer
>          Document doc = createDocument(bean);      //  subclass impl
>          writer.addDocument(doc);
>      }
>      catch (IOException & IndexException & Exception) { ... }      //
>  
> shortened for brevity
>      finally {
>           if (writer != null) writer.close();
>      }
> }
> 
> void deleteObject(Object bean) throws IOException, IndexException
> {
>      IndexReader reader = null;
>      try {
>          reader = getIndexReader();    //  returns 
> IndexReader.open(cached FSDirectory)
>          reader.delete(getPrimaryTerm(bean));    //  subclass impl
>      }
>      catch (IOException & IndexException & Exception) { ... }     // 
> shortened for brevity
>      finally {
>          if (reader != null) {
>              try {
>                  reader.close();
>              }
>              catch (IOException ignored) {
>              }
>          }
>      }
> }
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

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


Re: IndexReader.delete problem

Posted by Doug Kirk <do...@dougandalli.com>.
> Perhaps you are using 'new IndexWriter(path, analyzer, true)' rather
> than 'new IndexWriter(path, analyzer, false)'?

Yes, that is what was happening.  (Big Thanks!)

Here's a new problem, though: after changing the above to 'new 
IndexWriter(fsdirectory, analyzer, false)', my updated document no 
longer shows up in searches. No exception is being thrown during the 
entire updateObject() process.

The logic is:

void updateObject(Object bean)  throws IOException, IndexException {
     deleteObject(bean);
     insertObject(bean);
}

void insertObject(Object bean)  throws IOException, IndexException {
     IndexWriter writer = null;
     try {
         writer = getIndexWriter(false);    // false == create; uses 
previously cached FSDirectory and StandardAnalyzer
         Document doc = createDocument(bean);      //  subclass impl
         writer.addDocument(doc);
     }
     catch (IOException & IndexException & Exception) { ... }      //  
shortened for brevity
     finally {
          if (writer != null) writer.close();
     }
}

void deleteObject(Object bean) throws IOException, IndexException
{
     IndexReader reader = null;
     try {
         reader = getIndexReader();    //  returns 
IndexReader.open(cached FSDirectory)
         reader.delete(getPrimaryTerm(bean));    //  subclass impl
     }
     catch (IOException & IndexException & Exception) { ... }     // 
shortened for brevity
     finally {
         if (reader != null) {
             try {
                 reader.close();
             }
             catch (IOException ignored) {
             }
         }
     }
}


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


Re: IndexReader.delete problem

Posted by Eric Jain <Er...@isb-sib.ch>.
> Yes, it was added with doc.add(Field.Keyword("Event.PKID", "153"));

If you only delete the old document, but do not attempt to do anything
else, does this still reset the index?

Perhaps you are using 'new IndexWriter(path, analyzer, true)' rather
than 'new IndexWriter(path, analyzer, false)'?

--
Eric Jain


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


Re: IndexReader.delete problem

Posted by Doug Kirk <do...@dougandalli.com>.
Yes, it was added with doc.add(Field.Keyword("Event.PKID", "153"));


On Wednesday, May 21, 2003, at 09:05 AM, Eric Jain wrote:

>> Is this a Lucene bug, or could I be doing something wrong here?
>
> You did use doc.add(Field.Keyword("id", "xyz")) for adding the key
> field, to prevent it from being tokenized?
>
> --
> Eric Jain


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


Re: IndexReader.delete problem

Posted by Eric Jain <Er...@isb-sib.ch>.
> Is this a Lucene bug, or could I be doing something wrong here?

You did use doc.add(Field.Keyword("id", "xyz")) for adding the key
field, to prevent it from being tokenized?

--
Eric Jain


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


Re: IndexReader.delete problem

Posted by Otis Gospodnetic <ot...@yahoo.com>.
This would be a pretty big bug :)
You must be doing something wrong, like creating a new instance of
IndexWriter with the third argument being true or some such.

Otis

--- Doug Kirk <do...@dougandalli.com> wrote:
> Using 1.3-RC1, I've got an index where a keyword field contains the 
> primary key value of a database row (an int), and when a user updates
> 
> the data for the row, I delete the document from the index and then
> add 
> it back.
> 
> My problem: The search index now only recognizes the document just 
> updated; it seems as if every other document was deleted from the
> index.
> 
> I'm using IndexReader.delete(term), where term prints out as: 
> Term<Event.PKID:153>, which looks okay to me. The field name is 
> "Event.PKID", which is in Torque-generated "table.field" format.
> 
> As a temporary workaround, I recreate the entire index every time 
> somebody submits a change.
> 
> Is this a Lucene bug, or could I be doing something wrong here?
> 
> Thanks!
> -Doug.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

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