I'm getting the items from a MessageQueue. They come in sporadically, and
not all require an initial delete. Only when a DeleteFirst flag is set.
So... I can't really batch my deletes.
On 7/2/07, Simone Busoli <[EMAIL PROTECTED]> wrote:
As far as I can tell from the docs you should open a reader, delete all
the documents you need to delete and close the reader. The open a writer,
add all the documents you need to add and close it. I wouldn't wrap them
into other classes since you loose granularity on what you really want to
happen. In the project I am developing using Lucene.Net I'm doing
something like the following into a method which gets called on a regular
basis into a singleton class, to ensure that this instance is the only
responsible for creating writers which lock the index:
public void UpdateIndex()
{
[...]
// Create new IndexReader to update the index
indexReader = IndexReader.Open(indexDirectory);
// Here remove files from the index using the indexReader
instance
// Close the IndexReader
indexReader.Close();
indexReader = null;
// Create a new IndexWriter to add new documents to the index
indexWriter = new IndexWriter(indexDirectory, new
StandardAnalyzer(), false);
// Here add documents to the index using the indexWriter
instance
// Close the IndexWriter
indexWriter.Optimize();
indexWriter.Close();
indexWriter = null;
}
Simone
Patrick Burrows wrote:
Assuming I have assured that only one thread from one process is calling
the
below methods, is there any issue with calling
DeletePost(post.Id);
AddPostToIndex(post);
in terms of potentially corrupting the index? I can't see any. But I've
suddenly got paranoid about index corruption. IndexModifierSingleton is
just
that, a singleton for the IndexModifier. The IndexReader is not, since I
wanted a fresh reader for each delete operation.
private static void DeletePost(int feedItemId)
{
IndexReader ir = IndexReader.Open(IndexPath());
ir.DeleteDocuments(new Term(Post.FIELD_FEEDITEMID,
feedItemId.ToString()));
ir.Close();
}
public static string IndexPath()
{
return Settings.Default.IndexPath;
}
public static void AddPostToIndex(Post post)
{
IndexModifierSingleton.instance.AddDocument(post.ToDocument());
}
--
-
P