public void PerformWork(AddLuceneWork work, IDirectoryProvider provider) { Add(work.EntityClass, work.Id, work.Document, provider); }
/// <summary> /// This add the new work to the queue, so it can be processed in a batch fashion later /// </summary> public void AddToWorkQueue(System.Type entityClass, object entity, object id, WorkType workType, List <LuceneWork> queue, ISearchFactoryImplementor searchFactoryImplementor) { // TODO with the caller loop we are in a n^2: optimize it using a HashMap for work recognition foreach (LuceneWork luceneWork in queue) { if (luceneWork.EntityClass == entityClass && luceneWork.Id.Equals(id)) { return; } } bool searchForContainers = false; string idString = idMapping.Bridge.ObjectToString(id); switch (workType) { case WorkType.Add: queue.Add(new AddLuceneWork(id, idString, entityClass, GetDocument(entity, id, entityClass))); searchForContainers = true; break; case WorkType.Delete: case WorkType.Purge: queue.Add(new DeleteLuceneWork(id, idString, entityClass)); break; case WorkType.PurgeAll: queue.Add(new PurgeAllLuceneWork((System.Type)entity)); break; case WorkType.Update: case WorkType.Collection: /** * even with Lucene 2.1, use of indexWriter to update is not an option * We can only delete by term, and the index doesn't have a term that * uniquely identify the entry. * But essentially the optimization we are doing is the same Lucene is doing, the only extra cost is the * double file opening. */ queue.Add(new DeleteLuceneWork(id, idString, entityClass)); queue.Add(new AddLuceneWork(id, idString, entityClass, GetDocument(entity, id, entityClass))); searchForContainers = true; break; case WorkType.Index: queue.Add(new DeleteLuceneWork(id, idString, entityClass)); LuceneWork work = new AddLuceneWork(id, idString, entityClass, GetDocument(entity, id, entityClass)); work.IsBatch = true; queue.Add(work); searchForContainers = true; break; default: throw new AssertionFailure("Unknown WorkType: " + workType); } /** * When references are changed, either null or another one, we expect dirty checking to be triggered (both sides * have to be updated) * When the internal object is changed, we apply the {Add|Update}Work on containedIns */ if (searchForContainers) { ProcessContainedIn(entity, queue, rootClassMapping, searchFactoryImplementor); } }