Esempio n. 1
0
        public void Purge()
        {
            IFullTextSession s     = Search.CreateFullTextSession(OpenSession());
            ITransaction     tx    = s.BeginTransaction();
            Clock            clock = new Clock(1, "Seiko");

            s.Save(clock);
            clock = new Clock(2, "Festina");
            s.Save(clock);
            Book book = new Book(1, "La chute de la petite reine a travers les yeux de Festina", "La chute de la petite reine a travers les yeux de Festina, blahblah");

            s.Save(book);
            book = new Book(2, "La gloire de mon père", "Les deboires de mon père en vélo");
            s.Save(book);
            tx.Commit();
            s.Clear();

            tx = s.BeginTransaction();
            QueryParser parser = new QueryParser(Environment.LuceneVersion, "Brand", new StopAnalyzer(Environment.LuceneVersion));

            Lucene.Net.Search.Query query = parser.Parse("Brand:Seiko");
            IQuery hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
            IList  results  = hibQuery.List();

            Assert.AreEqual(1, results.Count, "incorrect test record");
            Assert.AreEqual(1, ((Clock)results[0]).Id, "incorrect test record");

            s.Purge(typeof(Clock), ((Clock)results[0]).Id);

            tx.Commit();

            tx = s.BeginTransaction();

            query    = parser.Parse("Brand:Festina or Brand:Seiko");
            hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
            results  = hibQuery.List();
            Assert.AreEqual(1, results.Count, "incorrect test record count");
            Assert.AreEqual(2, ((Clock)results[0]).Id, "incorrect test record");

            s.Delete("from System.Object");
            tx.Commit();
            s.Close();
        }