/// <summary> /// Processa os elementos que devem ser removidos do pesquisador. /// </summary> public void ProcessRemovedElements() { if (!_initialized) { Initialize(); } lock (_processElementsLock) { Exception exception = null; var startDate = DateTime.Now; if (_repositoryLoader.CheckClearAllElements()) { using (var writerAccess = CreateIndexWriter()) writerAccess.Writer.DeleteAll(); _repositoryLoader.ConfirmClearAllElements(); _dataRepository.Clear(); _newElementsCutoffDate = DateTime.MinValue; } else { IndexWriterAccess writerAccess = null; try { foreach (var uid in _repositoryLoader.GetRemoved(_removedElementsCutoffDate)) { try { if (writerAccess == null) { writerAccess = CreateIndexWriter(); } writerAccess.Writer.DeleteDocuments(new Term("Uid", uid.ToString())); _dataRepository.Remove(uid); } catch (Exception ex) { exception = ex; } } } finally { if (writerAccess != null) { writerAccess.Dispose(); } } } if (exception != null) { throw exception; } _removedElementsCutoffDate = startDate; } }
/// <summary> /// Processa os novos elementos que devem ser carregados para o pesquisador. /// </summary> public void ProcessNewElements() { if (!_initialized) { Initialize(); } lock (_processElementsLock) { var startDate = DateTime.Now; IndexWriterAccess writerAccess = null; var analyzer = new StandardAnalyzer(Version.LUCENE_29, Stopwords.PORTUGUESE_SET); var exceptionQueue = new Queue <Exception>(); IEnumerator <Element> elementsEnumerator = null; try { try { elementsEnumerator = _repositoryLoader.GetElements(_newElementsCutoffDate).GetEnumerator(); } catch (Exception ex) { throw new Exception(string.Format("Fail on get enumerator for elements from repository loader using date '{0}'", _newElementsCutoffDate.ToString()), ex); } while (true) { try { if (!elementsEnumerator.MoveNext()) { break; } } catch (Exception ex) { throw new Exception("Fail on get next elemento from elementsEnumerator", ex); } var element = elementsEnumerator.Current; try { if (writerAccess == null) { writerAccess = CreateIndexWriter(); } writerAccess.Writer.DeleteDocuments(new Term("Uid", element.Uid.ToString())); AddElement(writerAccess.Writer, analyzer, element); } catch (Exception ex) { exceptionQueue.Enqueue(ex); } } } finally { if (elementsEnumerator != null) { elementsEnumerator.Dispose(); } if (writerAccess != null) { writerAccess.Dispose(); } } if (exceptionQueue.Count > 0) { throw new SearchEngineAggregateException(string.Format("there were {0} exceptions, the first '{1}'", exceptionQueue.Count, exceptionQueue.Peek().Message), exceptionQueue); } _newElementsCutoffDate = startDate; } }