public virtual void HandleChange(IEnumerable <ChangeInfo> changedInfo) { var indexWriter = searchProvider.CreateIndex(typeof(T).Name); if (indexWriter == null) { return; } foreach (var ci in changedInfo) { var exp = GetKeyPrediction(ci.Key); var obj = repository.Get(exp); var dic = obj.ToDictionary(); switch (ci.Operation) { case DataOperation.Insert: indexWriter.AddDocument(dic); break; case DataOperation.Update: indexWriter.UpdateDocument(dic); break; case DataOperation.Delete: indexWriter.RemoveDocument(dic); break; default: break; } } }
public void Run() { Parallel.ForEach(loaders, loader => { dbProvider.Initialize(loader.ConnectionStringName); List <Dictionary <string, object> > objs = new List <Dictionary <string, object> >(); using (var cmd = dbProvider.CreateCommand(loader.QuerySql)) { using (var reader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)) { while (reader.Read()) { Dictionary <string, object> dic = new Dictionary <string, object>(); for (int i = 0; i < reader.FieldCount; i++) { var fn = reader.GetName(i); var val = reader[i]; dic.Add(fn, val); } objs.Add(dic); } reader.Close(); } } var writer = searchProvider.CreateIndex(loader.ObjectTypeName); foreach (var obj in objs) { writer.AddDocument(obj); } writer.Save(); }); }
public SearchRepositoryEventHandler(ISearchProvider searchProvider) { this.indexer = searchProvider.CreateIndex(typeof(T).Name); InitHandlers(); }