我的快速和骯髒的方法=>
public static class LuceneReindexer
{
public static void Run()
{
var entityTypes = typeof(FooEntity).Assembly.GetTypes()
.Where(x => x.BaseType == typeof(Entity)
|| x.BaseType == typeof(KeyedEntity));
foreach (var t in entityTypes)
if (TypeDescriptor
.GetAttributes(t)[typeof(IndexedAttribute)] != null)
ReindexEntity(t);
}
private static void ReindexEntity(Type t)
{
var stop = false;
var index = 0;
const int pageSize = 500;
do
{
var list = NHibernateSession.Current.CreateCriteria(t)
.SetFirstResult(index)
.SetMaxResults(pageSize).List();
NHibernateSession.Current.Transaction.Begin();
foreach (var itm in list)
NHibernateSession.Current.Index(itm);
NHibernateSession.Current.Transaction.Commit();
index += pageSize;
if (list.Count < pageSize) stop = true;
} while (!stop);
}
}
有關事務和尋呼一部分(目前不關心)的任何建議。親切a做我需要的。 :D
我用這種方式,它工作正常 – 2010-02-17 11:08:05