Hi Christian, This is NHibernate specific, so I guess you have a better chance in there forum.
:-) Anders Lybecker On Mon, Nov 14, 2011 at 5:24 PM, Christian Setzkorn <christ...@setzkorn.eu>wrote: > I have a class Publication which has a child PublicationX. I am trying to > index all instances of Publication like this: > > public void BuildSearchIndex() > { > FSDirectory entityDirectory = null; > IndexWriter writer = null; > > var entityType = typeof(Publication); > > var indexDirectory = new DirectoryInfo(GetIndexDirectory()); > > if (indexDirectory.Exists) > { > indexDirectory.Delete(true); > } > > try > { > var dir = new DirectoryInfo(Path.Combine(indexDirectory.FullName, > entityType.Name)); > entityDirectory = FSDirectory.Open(dir); > writer = new IndexWriter(entityDirectory, new > StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), true, > IndexWriter.MaxFieldLength.UNLIMITED); > } > finally > { > if (entityDirectory != null) > { > entityDirectory.Close(); > } > > if (writer != null) > { > writer.Close(); > } > } > > var fullTextSession = > Search.CreateFullTextSession(NHibernateSession.Current); > > int totalCount = > > NHibernateSession.Current.CreateCriteria(typeof(Publication)).SetProjection( > Projections.RowCount()).FutureValue<Int32>().Value; > > int pageSize = 500; > int totalPages = totalCount / pageSize + 1; > int currentPage = 0; > > do > { > IList<Publication> list = > > NHibernateSession.Current.CreateCriteria(typeof(Publication)).SetFirstResult > (pageSize * (currentPage - 1)).SetMaxResults(pageSize * > currentPage).Future<Publication>().ToList(); > > foreach (Publication p in list) > { > fullTextSession.Index(p); > } > currentPage++; > } > while (currentPage < totalPages); > } > > The idea is to do the indexing in batches (improvement suggestions welcome) > as there are quite a lot of publications already in the relational > database. > Unfortunately, I am getting this exception: > > NHibernate.Search.Impl.SearchException was unhandled by user code > Message=Unable to open IndexReader for EID2.Domain.PublicationX > Source=NHibernate.Search > > I have marked both classes with [Indexed]. > > Thanks. > > Christian > >