I created a singleton IndexWriter, pasted below in case anyone else wants
it [1]. But now I have a bit of a problem. Someone mentioned that I can't
have my index readers delete either. Makes sense, since that is a write
operation.

I just realized that one of the processes I am moving to use the new
singleton stuff is a "Refresh()" method. It loops through each document,
deletes it (using an indexreader) and then immediately recreates it (using
an indexwriter).

A -- why aren't these methods (delete and add) part of the same class?

B -- but, more importantly, (and less wining)... how do you handle this?
From my understanding you can't just update fields in an already indexed
document. You have to delete it and then re-add it. This operation
necessarily involves a Delete and an Add. Any thoughts would be helpful.




[1]

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using FullTextSearch.Tasks.Properties;
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Index;
using Directory=Lucene.Net.Store.Directory;

namespace FullTextSearch.Tasks
{
   public sealed class IndexWriterSingleton : IndexWriter
   {
       private static readonly IndexWriterSingleton instance =
           new IndexWriterSingleton(Settings.Default.IndexPath, new
StandardAnalyzer(), false);

       static readonly object lockhandle = new object();
       static IndexWriterSingleton(){}

       public static IndexWriterSingleton Instance
       {
           get { return instance; }
       }

       public IndexWriterSingleton(FileInfo path, Analyzer a, bool create)
: base(path, a, create){}
       public IndexWriterSingleton(string path, Analyzer a, bool create) :
base(path, a, create){}
       public IndexWriterSingleton(Directory d, Analyzer a, bool create) :
base(d, a, create){}

       public override void AddDocument(Lucene.Net.Documents.Document doc)
       {
           lock (lockhandle)
           {
               base.AddDocument(doc);
           }
       }

       public override void AddDocument(Lucene.Net.Documents.Document doc,
Analyzer analyzer)
       {
           lock (lockhandle)
           {
               base.AddDocument(doc, analyzer);
           }
       }

       public override void Optimize()
       {
           lock (lockhandle)
           {
               base.Optimize();
           }
       }
   }
}


--
-
P

Reply via email to