Ejemplo n.º 1
0
        public void Optimize()
        {
            IFullTextSession s  = Search.CreateFullTextSession(OpenSession());
            ITransaction     tx = s.BeginTransaction();
            int loop            = 2000;

            for (int i = 0; i < loop; i++)
            {
                s.Persist(new Email(i + 1, "JBoss World Berlin", "Meet the guys who wrote the software"));
            }

            tx.Commit();
            s.Close();

            s  = Search.CreateFullTextSession(OpenSession());
            tx = s.BeginTransaction();
            s.SearchFactory.Optimize(typeof(Email));
            tx.Commit();
            s.Close();

            // Check non-indexed object get indexed by s.index;
            s  = new FullTextSessionImpl(OpenSession());
            tx = s.BeginTransaction();
            QueryParser parser = new QueryParser(Environment.LuceneVersion, "id", new StopAnalyzer(Environment.LuceneVersion));
            int         result = s.CreateFullTextQuery(parser.Parse("Body:wrote")).List().Count;

            Assert.AreEqual(2000, result);

            s.Delete("from System.Object");
            tx.Commit();
            s.Close();
        }
        public void DoubleInsert()
        {
            Address address = new Address();

            address.Address1      = "TEST1";
            address.Address2      = "N/A";
            address.Town          = "TEST TOWN";
            address.County        = "TEST COUNTY";
            address.Country       = "UK";
            address.Postcode      = "XXXXXXX";
            address.Active        = true;
            address.CreatedOn     = DateTime.Now;
            address.LastUpdatedOn = DateTime.Now;

            Phone phone = new Phone();

            phone.Number        = "01273234122";
            phone.Type          = "HOME";
            phone.CreatedOn     = DateTime.Now;
            phone.LastUpdatedOn = DateTime.Now;

            PersonalContact contact = new PersonalContact();

            contact.Firstname   = "Amin";
            contact.Surname     = "Mohammed-Coleman";
            contact.Email       = "*****@*****.**";
            contact.DateOfBirth = DateTime.Now;

            // contact.NotifyBirthDay( false );
            contact.CreatedOn     = DateTime.Now;
            contact.LastUpdatedOn = DateTime.Now;
            contact.Notes         = "TEST";
            contact.AddAddressToContact(address);
            contact.AddPhoneToContact(phone);

            IFullTextSession s = Search.CreateFullTextSession(OpenSession());
            var tx             = s.BeginTransaction();

            s.Save(contact);
            tx.Commit();

            s.Close();

            s  = Search.CreateFullTextSession(OpenSession());
            tx = s.BeginTransaction();
            Term      term      = new Term("county", "county");
            TermQuery termQuery = new TermQuery(term);
            IList     results   = s.CreateFullTextQuery(termQuery).List();

            Assert.AreEqual(1, results.Count);
            s.Flush();
            s.Clear();

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

            s.Close();
        }
        public void ResultTransformToDelimString()
        {
            IFullTextSession s = Search.CreateFullTextSession(this.OpenSession());

            this.PrepEmployeeIndex(s);

            s.Clear();
            ITransaction tx     = s.BeginTransaction();
            QueryParser  parser = new QueryParser(NHibernate.Search.Environment.LuceneVersion, "Dept", new StandardAnalyzer(NHibernate.Search.Environment.LuceneVersion));

            Query          query    = parser.Parse("Dept:ITech");
            IFullTextQuery hibQuery = s.CreateFullTextQuery(query, typeof(Employee));

            hibQuery.SetProjection(
                "Id",
                "Lastname",
                "Dept",
                ProjectionConstants.THIS,
                ProjectionConstants.SCORE,
                ProjectionConstants.BOOST,
                ProjectionConstants.ID);
            hibQuery.SetResultTransformer(new ProjectionToDelimStringResultTransformer());

            IList result = hibQuery.List();

            Assert.IsTrue(((string)result[0]).StartsWith("1000, Griffin, ITech"), "incorrect transformation");
            Assert.IsTrue(((string)result[1]).StartsWith("1002, Jimenez, ITech"), "incorrect transformation");

            // cleanup
            s.Delete("from System.Object");
            tx.Commit();
            s.Close();
        }
Ejemplo n.º 4
0
        public void Cache()
        {
            CreateData();
            IFullTextSession s = Search.CreateFullTextSession(OpenSession());

            s.Transaction.Begin();
            BooleanQuery query = new BooleanQuery();

            query.Add(new TermQuery(new Term("teacher", "andre")), BooleanClause.Occur.SHOULD);
            query.Add(new TermQuery(new Term("teacher", "max")), BooleanClause.Occur.SHOULD);
            query.Add(new TermQuery(new Term("teacher", "aaron")), BooleanClause.Occur.SHOULD);

            IFullTextQuery ftQuery = s.CreateFullTextQuery(query, typeof(Driver));

            Assert.AreEqual(3, ftQuery.ResultSize, "No filter should happen");

            ftQuery = s.CreateFullTextQuery(query, typeof(Driver));
            ftQuery.EnableFullTextFilter("cachetest");
            Assert.AreEqual(0, ftQuery.ResultSize, "Should filter out all");

            ftQuery = s.CreateFullTextQuery(query, typeof(Driver));
            ftQuery.EnableFullTextFilter("cachetest");
            try
            {
                int i = ftQuery.ResultSize;
            }
            catch (NotSupportedException)
            {
                Assert.Fail("Cache does not work");
            }

            s.Transaction.Commit();
            s.Close();
            DeleteData();
        }
Ejemplo n.º 5
0
        public void CombinedFilters()
        {
            try
            {
                CreateData();
                IFullTextSession s = Search.CreateFullTextSession(OpenSession());
                s.Transaction.Begin();
                BooleanQuery query = new BooleanQuery();
                query.Add(new TermQuery(new Term("teacher", "andre")), BooleanClause.Occur.SHOULD);
                query.Add(new TermQuery(new Term("teacher", "max")), BooleanClause.Occur.SHOULD);
                query.Add(new TermQuery(new Term("teacher", "aaron")), BooleanClause.Occur.SHOULD);

                IFullTextQuery ftQuery = s.CreateFullTextQuery(query, typeof(Driver));
                ftQuery.EnableFullTextFilter("bestDriver");
                ftQuery.EnableFullTextFilter("security").SetParameter("Login", "andre");
                Assert.AreEqual(1, ftQuery.ResultSize, "Should filter to limit to Emmanuel");

                ftQuery = s.CreateFullTextQuery(query, typeof(Driver));
                ftQuery.EnableFullTextFilter("bestDriver");
                ftQuery.EnableFullTextFilter("security").SetParameter("login", "andre");
                ftQuery.DisableFullTextFilter("security");
                ftQuery.DisableFullTextFilter("bestDriver");
                Assert.AreEqual(3, ftQuery.ResultSize, "Should not filter anymore");

                s.Transaction.Commit();
                s.Close();
            }
            finally
            {
                DeleteData();
            }
        }
Ejemplo n.º 6
0
        public void StraightFilters()
        {
            try
            {
                CreateData();
                IFullTextSession s = Search.CreateFullTextSession(OpenSession());
                s.Transaction.Begin();
                BooleanQuery query = new BooleanQuery();
                query.Add(new TermQuery(new Term("teacher", "andre")), BooleanClause.Occur.SHOULD);
                query.Add(new TermQuery(new Term("teacher", "max")), BooleanClause.Occur.SHOULD);
                query.Add(new TermQuery(new Term("teacher", "aaron")), BooleanClause.Occur.SHOULD);

                IFullTextQuery ftQuery = s.CreateFullTextQuery(query, typeof(Driver));
                ftQuery.EnableFullTextFilter("bestDriver");
                Lucene.Net.Search.Filter dateFilter = new RangeFilter("delivery", "2001", "2005", true, true);
                ftQuery.SetFilter(dateFilter);
                Assert.AreEqual(1, ftQuery.ResultSize, "Should select only liz");

                s.Transaction.Commit();
                s.Close();
            }
            finally
            {
                DeleteData();
            }
        }
        public void UnsetBatchValueTakesTransaction()
        {
            IFullTextSession         fullTextSession    = Search.CreateFullTextSession(OpenSession());
            SearchFactoryImpl        searchFactory      = (SearchFactoryImpl)fullTextSession.SearchFactory;
            LuceneIndexingParameters indexingParameters = searchFactory.GetIndexingParameters(searchFactory.GetDirectoryProviders(typeof(DocumentTop))[0]);

            Assert.AreEqual(10, (int)indexingParameters.BatchIndexParameters.MergeFactor);
            Assert.AreEqual(1000, (int)indexingParameters.BatchIndexParameters.MaxBufferedDocs);
            Assert.AreEqual(99, (int)indexingParameters.BatchIndexParameters.TermIndexInterval);
            fullTextSession.Close();
        }
Ejemplo n.º 8
0
        public void MultipleEntityPerIndex()
        {
            IFullTextSession s     = Search.CreateFullTextSession(OpenSession());
            ITransaction     tx    = s.BeginTransaction();
            Clock            clock = new Clock(1, "Seiko");

            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);
            AlternateBook alternateBook =
                new AlternateBook(1, "La chute de la petite reine a travers les yeux de Festina");

            s.Save(alternateBook);
            tx.Commit();
            s.Clear();
            tx = s.BeginTransaction();
            QueryParser parser = new QueryParser(Environment.LuceneVersion, "Title", new StopAnalyzer(Environment.LuceneVersion));

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

            Assert.AreEqual(1, result.Count, "Query with explicit class filter");

            query    = parser.Parse("Summary:Festina");
            hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
            IEnumerator it = hibQuery.Enumerable().GetEnumerator();

            Assert.IsTrue(it.MoveNext());
            Assert.IsNotNull(it.Current);
            Assert.IsFalse(it.MoveNext());

            query    = parser.Parse("Summary:Festina OR Brand:seiko");
            hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
            hibQuery.SetMaxResults(2);
            result = hibQuery.List();
            Assert.AreEqual(2, result.Count, "Query with explicit class filter and limit");

            query    = parser.Parse("Summary:Festina");
            hibQuery = s.CreateFullTextQuery(query);
            result   = hibQuery.List();
            Assert.AreEqual(2, result.Count, "Query with no class filter");
            foreach (Object element in result)
            {
                Assert.IsTrue(NHibernateUtil.IsInitialized(element));
                s.Delete(element);
            }
            s.Delete("from System.Object");
            tx.Commit();
            s.Close();
        }
Ejemplo n.º 9
0
        public void List()
        {
            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, "title", new StopAnalyzer(Environment.LuceneVersion));

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

            Assert.AreEqual(0, result.Count);

            query    = parser.Parse("Summary:Festina Or Brand:Seiko");
            hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
            result   = hibQuery.List();
            Assert.AreEqual(2, result.Count, "Query with explicit class filter");

            query    = parser.Parse("Summary:Festina Or Brand:Seiko");
            hibQuery = s.CreateFullTextQuery(query);
            result   = hibQuery.List();
            Assert.AreEqual(2, result.Count, "Query with no class filter");
            foreach (Object element in result)
            {
                Assert.IsTrue(NHibernateUtil.IsInitialized(element));
                s.Delete(element);
            }
            s.Flush();
            tx.Commit();

            tx       = s.BeginTransaction();
            query    = parser.Parse("Summary:Festina Or Brand:Seiko");
            hibQuery = s.CreateFullTextQuery(query);
            result   = hibQuery.List();
            Assert.AreEqual(0, result.Count, "Query with delete objects");

            s.Delete("from System.Object");
            tx.Commit();
            s.Close();
        }
        public void BatchParametersDefault()
        {
            IFullTextSession         fullTextSession    = Search.CreateFullTextSession(OpenSession());
            SearchFactoryImpl        searchFactory      = (SearchFactoryImpl)fullTextSession.SearchFactory;
            LuceneIndexingParameters indexingParameters = searchFactory.GetIndexingParameters(searchFactory.GetDirectoryProviders(typeof(Query.Author))[0]);

            Assert.AreEqual(1, (int)indexingParameters.BatchIndexParameters.RamBufferSizeMb);
            Assert.AreEqual(9, (int)indexingParameters.BatchIndexParameters.MaxMergeDocs);
            Assert.AreEqual(1000, (int)indexingParameters.BatchIndexParameters.MaxBufferedDocs);
            Assert.AreEqual(10, (int)indexingParameters.BatchIndexParameters.MergeFactor);
            fullTextSession.Close();
        }
Ejemplo n.º 11
0
        public void FirstMax()
        {
            ISession sess = OpenSession();

            Assert.AreEqual(0, sess.CreateCriteria(typeof(Clock)).List().Count);

            IFullTextSession s     = Search.CreateFullTextSession(sess);
            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, "title", new StopAnalyzer(Environment.LuceneVersion));

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

            hibQuery.SetFirstResult(1);
            IList result = hibQuery.List();

            Assert.AreEqual(1, result.Count, "first result no max result");

            hibQuery.SetFirstResult(0);
            hibQuery.SetMaxResults(1);
            result = hibQuery.List();
            Assert.AreEqual(1, result.Count, "max result set");

            hibQuery.SetFirstResult(0);
            hibQuery.SetMaxResults(3);
            result = hibQuery.List();
            Assert.AreEqual(2, result.Count, "max result out of limit");

            hibQuery.SetFirstResult(2);
            hibQuery.SetMaxResults(3);
            result = hibQuery.List();
            Assert.AreEqual(0, result.Count, "first result out of limit");

            s.Delete("from System.Object");
            tx.Commit();
            s.Close();
        }
        public void TransactionParameters()
        {
            IFullTextSession         fullTextSession    = Search.CreateFullTextSession(OpenSession());
            SearchFactoryImpl        searchFactory      = (SearchFactoryImpl)fullTextSession.SearchFactory;
            LuceneIndexingParameters indexingParameters = searchFactory.GetIndexingParameters(searchFactory.GetDirectoryProviders(typeof(Query.Book))[0]);

            Assert.AreEqual(4, (int)indexingParameters.TransactionIndexParameters.RamBufferSizeMb);
            Assert.AreEqual(15, (int)indexingParameters.TransactionIndexParameters.MaxMergeDocs);
            Assert.AreEqual(17, (int)indexingParameters.TransactionIndexParameters.MaxBufferedDocs);
            Assert.AreEqual(16, (int)indexingParameters.TransactionIndexParameters.MergeFactor);
            Assert.AreEqual(101, (int)indexingParameters.TransactionIndexParameters.TermIndexInterval);
            fullTextSession.Close();
        }
Ejemplo n.º 13
0
        public void Iterator()
        {
            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(); //post Commit events for lucene
            s.Clear();
            tx = s.BeginTransaction();
            QueryParser parser = new QueryParser(Environment.LuceneVersion, "title", new StopAnalyzer(Environment.LuceneVersion));

            Lucene.Net.Search.Query query = parser.Parse("Summary:noword");
            IQuery      hibQuery          = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
            IEnumerator result            = hibQuery.Enumerable().GetEnumerator();

            Assert.IsFalse(result.MoveNext());

            query    = parser.Parse("Summary:Festina Or Brand:Seiko");
            hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
            result   = hibQuery.Enumerable().GetEnumerator();
            int index = 0;

            while (result.MoveNext())
            {
                index++;
                s.Delete(result.Current);
            }
            Assert.AreEqual(2, index);

            tx.Commit();

            tx       = s.BeginTransaction();
            query    = parser.Parse("Summary:Festina Or Brand:Seiko");
            hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
            result   = hibQuery.Enumerable().GetEnumerator();

            Assert.IsFalse(result.MoveNext());
            s.Delete("from System.Object");
            tx.Commit();
            s.Close();
        }
Ejemplo n.º 14
0
        public void BatchSize()
        {
            IFullTextSession s  = Search.CreateFullTextSession(OpenSession());
            ITransaction     tx = s.BeginTransaction();
            int loop            = 14;

            for (int i = 0; i < loop; i++)
            {
                using (IDbCommand cmd = s.Connection.CreateCommand())
                {
                    s.Transaction.Enlist(cmd);
                    cmd.CommandText = "insert into Email(Id, Title, Body, Header) values( + " + (i + 1)
                                      + ", 'Bob Sponge', 'Meet the guys who create the software', 'nope')";
                    cmd.ExecuteNonQuery();
                }
            }
            tx.Commit();
            s.Close();

            s  = new FullTextSessionImpl(OpenSession());
            tx = s.BeginTransaction();
            int index = 0;

            foreach (object entity in s.CreateCriteria(typeof(Email)).List())
            {
                index++;
                s.Index(entity);

                // NB Java uses a scrollable result, so clear works for them, but not for us I think
                //if (index % 5 == 0)
                //{
                //    s.Clear();
                //}
            }
            tx.Commit();
            s.Clear();

            tx = s.BeginTransaction();
            QueryParser parser = new QueryParser("id", new StopAnalyzer());
            IList       result = s.CreateFullTextQuery(parser.Parse("Body:create")).List();

            Assert.AreEqual(14, result.Count);

            s.Delete("from System.Object");
            tx.Commit();
            s.Close();
        }
Ejemplo n.º 15
0
        public void PurgeAll()
        {
            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);
            clock = new Clock(3, "Longine");
            s.Save(clock);
            clock = new Clock(4, "Rolex");
            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));

            tx = s.BeginTransaction();
            s.PurgeAll(typeof(Clock));

            tx.Commit();

            tx = s.BeginTransaction();

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

            Assert.AreEqual(0, results.Count, "class not completely purged");

            query    = parser.Parse("Summary:Festina or Summary:gloire");
            hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
            results  = hibQuery.List();
            Assert.AreEqual(2, results.Count, "incorrect class purged");

            s.Delete("from System.Object");
            tx.Commit();
            s.Close();
        }
        public void ProxyObjectInheritance()
        {
            // This will test subclassed proxy objects and make sure that they are index correctly.
            IFullTextSession s  = Search.CreateFullTextSession(OpenSession());
            ITransaction     tx = s.BeginTransaction();

            // Create an object in db
            Mammal temp = new Mammal();

            temp.NumberOfLegs = (4);
            temp.Name         = ("Some Mammal Name Here");
            s.Save(temp);

            tx.Commit(); //post commit events for lucene

            // Clear object from cache by clearing session
            s.Clear();

            // This should return a proxied object
            Mammal mammal = s.Load <Mammal>(temp.Id);

            // Index the proxied object
            s.Index(mammal);

            // Build an index reader
            var reader = s.SearchFactory.ReaderProvider.OpenReader(s.SearchFactory.GetDirectoryProviders(typeof(Mammal)));

            // Get the last document indexed
            var Document = reader.Document(reader.MaxDoc() - 1);

            // get the class name field from the document
            string classTypeThatWasIndex = Document.Get(NHibernate.Search.Engine.DocumentBuilder.CLASS_FIELDNAME);

            // get the expected lucene type name (this should be equivilent to
            // the static method of NHibernate.Search.Util.TypeHelper.LuceneTypeName
            string expectedLuceneTypeName = typeof(Mammal).FullName + ", " + typeof(Mammal).Assembly.GetName().Name;

            Assert.AreEqual(expectedLuceneTypeName, classTypeThatWasIndex);

            // Tidyup
            tx = s.BeginTransaction();
            s.Delete("from System.Object");
            tx.Commit();
            s.Close();
        }
Ejemplo n.º 17
0
        public void UsingCriteriaApi()
        {
            IFullTextSession s     = Search.CreateFullTextSession(OpenSession());
            ITransaction     tx    = s.BeginTransaction();
            Clock            clock = new Clock(1, "Seiko");

            s.Save(clock);
            tx.Commit();

            IList list = s.CreateFullTextQuery <Clock>("Brand:seiko")
                         .SetCriteriaQuery(s.CreateCriteria(typeof(Clock)).Add(Restrictions.IdEq(1)))
                         .List();

            Assert.AreEqual(1, list.Count, "should get result back from query");

            s.Delete(clock);
            s.Flush();
            s.Close();
        }
Ejemplo n.º 18
0
        public void TestScopedAnalyzers()
        {
            MyEntity en = new MyEntity();

            en.Entity    = "Entity";
            en.Field     = "Field";
            en.Property  = "Property";
            en.Component = new MyComponent();
            en.Component.ComponentProperty = "component property";

            IFullTextSession s  = Search.CreateFullTextSession(OpenSession());
            ITransaction     tx = s.BeginTransaction();

            s.Save(en);
            s.Flush();
            tx.Commit();

            tx = s.BeginTransaction();

            QueryParser parser = new QueryParser("id", new StandardAnalyzer());

            Lucene.Net.Search.Query luceneQuery = parser.Parse("entity:alarm");
            IFullTextQuery          query       = s.CreateFullTextQuery(luceneQuery, typeof(MyEntity));

            Assert.AreEqual(1, query.ResultSize, "Entity query");

            luceneQuery = parser.Parse("property:cat");
            query       = s.CreateFullTextQuery(luceneQuery, typeof(MyEntity));
            Assert.AreEqual(1, query.ResultSize, "Property query");

            luceneQuery = parser.Parse("field:energy");
            query       = s.CreateFullTextQuery(luceneQuery, typeof(MyEntity));
            Assert.AreEqual(1, query.ResultSize, "Field query");

            luceneQuery = parser.Parse("component.componentProperty:noise");
            query       = s.CreateFullTextQuery(luceneQuery);
            Assert.AreEqual(1, query.ResultSize, "Component query");

            s.Delete(query.UniqueResult());
            tx.Commit();

            s.Close();
        }
        public void LuceneObjectsProjectionWithIterate()
        {
            IFullTextSession s = Search.CreateFullTextSession(this.OpenSession());

            this.PrepEmployeeIndex(s);

            s.Clear();
            ITransaction tx     = s.BeginTransaction();
            QueryParser  parser = new QueryParser(NHibernate.Search.Environment.LuceneVersion, "Dept", new StandardAnalyzer(NHibernate.Search.Environment.LuceneVersion));

            Query          query    = parser.Parse("Dept:ITech");
            IFullTextQuery hibQuery = s.CreateFullTextQuery(query, typeof(Employee));

            hibQuery.SetProjection(
                "Id",
                "Lastname",
                "Dept",
                ProjectionConstants.THIS,
                ProjectionConstants.SCORE,
                ProjectionConstants.BOOST,
                ProjectionConstants.DOCUMENT,
                ProjectionConstants.ID);

            int counter = 0;

            foreach (object[] projection in hibQuery.Enumerable())
            {
                Assert.IsNotNull(projection);
                counter++;
                Assert.AreEqual("ITech", projection[2], "dept incorrect");
                Assert.AreEqual(projection[3], s.Get <Employee>(projection[0]), "THIS incorrect");
                Assert.AreEqual(1.0F, projection[4], "SCORE incorrect");
                Assert.AreEqual(1.0F, projection[5], "BOOST incorrect");
                Assert.IsTrue(projection[6] is Document, "DOCUMENT incorrect");
                Assert.AreEqual(4, ((Document)projection[6]).GetFields().Count, "DOCUMENT size incorrect");
            }
            Assert.AreEqual(4, counter, "incorrect number of results returned");

            // cleanup
            s.Delete("from System.Object");
            tx.Commit();
            s.Close();
        }
Ejemplo n.º 20
0
        public void Inheritance()
        {
            IFullTextSession s  = Search.CreateFullTextSession(OpenSession());
            ITransaction     tx = s.BeginTransaction();
            Animal           a  = new Animal();

            a.Name = ("Shark Jr");
            s.Save(a);
            Mammal m = new Mammal();

            m.NumberOfLegs = (4);
            m.Name         = ("Elephant Jr");
            s.Save(m);
            tx.Commit(); //post commit events for lucene
            s.Clear();
            tx = s.BeginTransaction();
            QueryParser parser = new QueryParser(Environment.LuceneVersion, "Name", new StopAnalyzer(Environment.LuceneVersion));

            Lucene.Net.Search.Query query = parser.Parse("Elephant");
            IQuery hibQuery = s.CreateFullTextQuery(query, typeof(Mammal));
            IList  result   = hibQuery.List();

            Assert.IsNotEmpty(result);
            Assert.AreEqual(1, result.Count, "Query subclass by superclass attribute");

            query    = parser.Parse("NumberOfLegs:[4 TO 4]");
            hibQuery = s.CreateFullTextQuery(query, typeof(Animal), typeof(Mammal));
            result   = hibQuery.List();
            Assert.IsNotEmpty(result);
            Assert.AreEqual(1, result.Count, "Query subclass by subclass attribute");

            query    = parser.Parse("Jr");
            hibQuery = s.CreateFullTextQuery(query, typeof(Animal));
            result   = hibQuery.List();
            Assert.IsNotEmpty(result);
            Assert.AreEqual(2, result.Count, "Query filtering on superclass return mapped subclasses");
            foreach (Object managedEntity in result)
            {
                s.Delete(managedEntity);
            }
            tx.Commit();
            s.Close();
        }
Ejemplo n.º 21
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("Brand", new StopAnalyzer());

            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();
        }
        public void ResultTransformMap()
        {
            IFullTextSession s = Search.CreateFullTextSession(this.OpenSession());

            this.PrepEmployeeIndex(s);

            s.Clear();
            ITransaction tx     = s.BeginTransaction();
            QueryParser  parser = new QueryParser(NHibernate.Search.Environment.LuceneVersion, "Dept", new StandardAnalyzer(NHibernate.Search.Environment.LuceneVersion));

            Query          query    = parser.Parse("Dept:ITech");
            IFullTextQuery hibQuery = s.CreateFullTextQuery(query, typeof(Employee));

            hibQuery.SetProjection(
                "Id",
                "Lastname",
                "Dept",
                ProjectionConstants.THIS,
                ProjectionConstants.SCORE,
                ProjectionConstants.BOOST,
                ProjectionConstants.DOCUMENT,
                ProjectionConstants.ID);
            hibQuery.SetResultTransformer(new ProjectionToMapResultTransformer());

            IList transforms = hibQuery.List();
            Dictionary <string, object> map = (Dictionary <string, object>)transforms[1];

            Assert.AreEqual("ITech", map["Dept"], "incorrect transformation");
            Assert.AreEqual(1002, map["Id"], "incorrect transformation");
            Assert.IsTrue(map[ProjectionConstants.DOCUMENT] is Document, "incorrect transformation");
            Assert.AreEqual(
                "1002",
                ((Document)map[ProjectionConstants.DOCUMENT]).GetField("Id").StringValue,
                "incorrect transformation");

            // cleanup
            s.Delete("from System.Object");
            tx.Commit();
            s.Close();
        }
Ejemplo n.º 23
0
        public void Criteria()
        {
            IFullTextSession s    = Search.CreateFullTextSession(OpenSession());
            ITransaction     tx   = s.BeginTransaction();
            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);
            Author emmanuel = new Author();

            emmanuel.Name = "Emmanuel";
            s.Save(emmanuel);
            book.Authors.Add(emmanuel);
            tx.Commit();
            s.Clear();

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

            Lucene.Net.Search.Query query    = parser.Parse("Summary:Festina");
            IFullTextQuery          hibQuery = s.CreateFullTextQuery(query, typeof(Book));
            IList result = hibQuery.List();

            Assert.NotNull(result);
            Assert.AreEqual(1, result.Count, "Query with no explicit criteria");
            book = (Book)result[0];
            //Assert.IsFalse(NHibernate.IsInitialized(book.Authors), "Association should not be initialized");

            result = s.CreateFullTextQuery(query).SetCriteriaQuery(s.CreateCriteria(typeof(Book)).SetFetchMode("Authors", FetchMode.Join)).List();
            Assert.NotNull(result);
            Assert.AreEqual(1, result.Count, "Query with no explicit criteria");
            book = (Book)result[0];
            //Assert.IsTrue(NHibernate.IsInitialized(book.Authors), "Association should be initialized");
            Assert.AreEqual(1, book.Authors.Count);

            // cleanup
            s.Delete("from System.Object");
            tx.Commit();
            s.Close();
        }
Ejemplo n.º 24
0
        public void ObjectNotFound()
        {
            ISession     sess = OpenSession();
            ITransaction tx   = sess.BeginTransaction();

            Author author = new Author();

            author.Name = "Moo Cow";
            sess.Persist(author);

            tx.Commit();
            sess.Clear();
            IDbCommand statement = sess.Connection.CreateCommand();

            statement.CommandText = "DELETE FROM Author";
            statement.ExecuteNonQuery();

            IFullTextSession s = Search.CreateFullTextSession(sess);

            tx = s.BeginTransaction();
            QueryParser parser = new QueryParser(LuceneVersion.LUCENE_48, "title", new KeywordAnalyzer());

            Lucene.Net.Search.Query query    = parser.Parse("name:moo");
            IFullTextQuery          hibQuery = s.CreateFullTextQuery(query, typeof(Author), typeof(Music));
            IList result = hibQuery.List();

            Assert.AreEqual(0, result.Count, "Should have returned no author");

            foreach (object o in result)
            {
                s.Delete(o);
            }

            tx.Commit();
            s.Close();
        }
Ejemplo n.º 25
0
        public void Transactional()
        {
            IFullTextSession s  = Search.CreateFullTextSession(OpenSession());
            ITransaction     tx = s.BeginTransaction();
            int loop            = 4;

            for (int i = 0; i < loop; i++)
            {
                s.Save(new Email(i + 1, "JBoss World Berlin", "Meet the guys who wrote the software"));
            }
            tx.Commit();
            s.Close();

            // check non created object does get found!!1
            s  = new FullTextSessionImpl(OpenSession());
            tx = s.BeginTransaction();
            QueryParser parser = new QueryParser("id", new StopAnalyzer());
            IList       result = s.CreateFullTextQuery(parser.Parse("Body:create")).List();

            Assert.IsEmpty(result);
            tx.Commit();
            s.Close();

            s = new FullTextSessionImpl(OpenSession());
            s.Transaction.Begin();
            using (IDbCommand cmd = s.Connection.CreateCommand())
            {
                s.Transaction.Enlist(cmd);
                cmd.CommandText = "update Email set Body='Meet the guys who write the software'";
                cmd.ExecuteNonQuery();

                cmd.CommandText = "insert into Email(Id, Title, Body, Header) values( + "
                                  + (loop + 1) + ", 'Bob Sponge', 'Meet the guys who create the software', 'nope')";
                cmd.ExecuteNonQuery();
            }

            s.Transaction.Commit();
            s.Close();

            s      = new FullTextSessionImpl(OpenSession());
            tx     = s.BeginTransaction();
            parser = new QueryParser("id", new StopAnalyzer());
            result = s.CreateFullTextQuery(parser.Parse("Body:write")).List();
            Assert.IsEmpty(result);
            result = s.CreateCriteria(typeof(Email)).List();
            for (int i = 0; i < loop / 2; i++)
            {
                s.Index(result[i]);
            }
            tx.Commit();                 //do the process

            s.Index(result[(loop / 2)]); //do the process out of tx

            tx = s.BeginTransaction();
            for (int i = loop / 2 + 1; i < loop; i++)
            {
                s.Index(result[i]);
            }
            tx.Commit(); //do the process
            s.Close();

            s  = Search.CreateFullTextSession(OpenSession());
            tx = s.BeginTransaction();

            // object never indexed
            Email email = (Email)s.Get(typeof(Email), loop + 1);

            s.Index(email);
            tx.Commit();
            s.Close();

            // check non indexed object get indexed by s.index
            s      = new FullTextSessionImpl(OpenSession());
            tx     = s.BeginTransaction();
            result = s.CreateFullTextQuery(parser.Parse("Body:create")).List();
            Assert.AreEqual(1, result.Count);
            tx.Commit();

            s.Delete("from System.Object");
            s.Flush();

            s.Close();
        }
        public void ProperCopy()
        {
            // Assert that the slave index is empty
            IFullTextSession fullTextSession = Search.CreateFullTextSession(GetSlaveSession());
            ITransaction     tx     = fullTextSession.BeginTransaction();
            QueryParser      parser = new QueryParser(LuceneVersion.LUCENE_48, "id", new StopAnalyzer(LuceneVersion.LUCENE_48));
            IList            result = fullTextSession.CreateFullTextQuery(parser.Parse("Location:texas")).List();

            Assert.AreEqual(0, result.Count, "No copy yet, fresh index expected");
            tx.Commit();
            fullTextSession.Close();

            // create an entity on the master and persist it in order to index it
            ISession session = CreateSession(0);

            tx = session.BeginTransaction();
            SnowStorm sn = new SnowStorm();

            sn.DateTime = DateTime.Now;
            sn.Location = ("Dallas, TX, USA");
            session.Persist(sn);
            tx.Commit();
            session.Close();

            int waitPeriodMilli = 2 * 1 * 1000 + 10; //wait a bit more than 2 refresh (one master / one slave)

            Thread.Sleep(waitPeriodMilli);

            // assert that the master has indexed the snowstorm
            fullTextSession = Search.CreateFullTextSession(GetMasterSession());
            tx     = fullTextSession.BeginTransaction();
            result = fullTextSession.CreateFullTextQuery(parser.Parse("Location:dallas")).List();
            Assert.AreEqual(1, result.Count, "Original should get one");
            tx.Commit();
            fullTextSession.Close();

            // assert that index got copied to the slave as well
            fullTextSession = Search.CreateFullTextSession(GetSlaveSession());
            tx     = fullTextSession.BeginTransaction();
            result = fullTextSession.CreateFullTextQuery(parser.Parse("Location:dallas")).List();
            Assert.AreEqual(1, result.Count, "First copy did not work out");
            tx.Commit();
            fullTextSession.Close();

            // add a new snowstorm to the master
            session     = GetMasterSession();
            tx          = session.BeginTransaction();
            sn          = new SnowStorm();
            sn.DateTime = DateTime.Now;
            sn.Location = ("Chennai, India");
            session.Persist(sn);
            tx.Commit();
            session.Close();

            Thread.Sleep(waitPeriodMilli); //wait a bit more than 2 refresh (one master / one slave)

            // assert that the new snowstorm made it into the slave
            fullTextSession = Search.CreateFullTextSession(GetSlaveSession());
            tx     = fullTextSession.BeginTransaction();
            result = fullTextSession.CreateFullTextQuery(parser.Parse("Location:chennai")).List();
            Assert.AreEqual(1, result.Count, "Second copy did not work out");
            tx.Commit();
            fullTextSession.Close();

            session     = GetMasterSession();
            tx          = session.BeginTransaction();
            sn          = new SnowStorm();
            sn.DateTime = DateTime.Now;
            sn.Location = ("Melbourne, Australia");
            session.Persist(sn);
            tx.Commit();
            session.Close();

            Thread.Sleep(waitPeriodMilli); //wait a bit more than 2 refresh (one master / one slave)

            // once more - assert that the new snowstorm made it into the slave
            fullTextSession = Search.CreateFullTextSession(GetSlaveSession());
            tx     = fullTextSession.BeginTransaction();
            result = fullTextSession.CreateFullTextQuery(parser.Parse("Location:melbourne")).List();
            Assert.AreEqual(1, result.Count, "Third copy did not work out");
            tx.Commit();
            fullTextSession.Close();
        }
Ejemplo n.º 27
0
        public void TestList()
        {
            IFullTextSession s = Search.CreateFullTextSession(OpenSession());

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

            Lucene.Net.Search.Query query    = parser.Parse("Summary:lucene");
            IFullTextQuery          hibQuery = s.CreateFullTextQuery(query, typeof(Book));
            IList result = hibQuery.List();

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Count, "Wrong number of test results.");

            int id = 1;

            // Ignoring the default sort order as this does not appear to be the same between Lucene.Net and Lucene
            // This also beats against KW's change to queue processing order - see

            /*
             * // Make sure that the order is according to in which order the books got inserted into the index.
             * foreach (Book b in result)
             * {
             *  Assert.AreEqual(id, b.Id, "Expected another id");
             *  id++;
             * }
             */

            // now the same query, but with a lucene sort specified.
            query    = parser.Parse("Summary:lucene");
            hibQuery = s.CreateFullTextQuery(query, typeof(Book));
            Sort sort = new Sort(new SortField("Id", SortField.INT, true));

            hibQuery.SetSort(sort);
            result = hibQuery.List();
            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Count, "Wrong number of test results.");
            id = 3;
            foreach (Book b in result)
            {
                Assert.AreEqual(id, b.Id, "Expected another id");
                id--;
            }

            // order by summary
            query    = parser.Parse("Summary:lucene OR Summary:action");
            hibQuery = s.CreateFullTextQuery(query, typeof(Book));
            sort     = new Sort(new SortField("summary_forSort", SortField.STRING, false)); //ASC
            hibQuery.SetSort(sort);
            result = hibQuery.List();
            Assert.IsNotNull(result);
            Assert.AreEqual(4, result.Count, "Wrong number of test results.");
            Assert.AreEqual("Groovy in Action", ((Book)result[0]).Summary);

            // order by summary backwards
            query    = parser.Parse("Summary:lucene OR Summary:action");
            hibQuery = s.CreateFullTextQuery(query, typeof(Book));
            sort     = new Sort(new SortField("summary_forSort", SortField.STRING, true)); //DESC
            hibQuery.SetSort(sort);
            result = hibQuery.List();
            Assert.IsNotNull(result);
            Assert.AreEqual(4, result.Count, "Wrong number of test results.");
            Assert.AreEqual("Hibernate & Lucene", ((Book)result[0]).Summary);

            // order by date backwards
            query    = parser.Parse("Summary:lucene OR Summary:action");
            hibQuery = s.CreateFullTextQuery(query, typeof(Book));
            sort     = new Sort(new SortField("PublicationDate", SortField.STRING, true)); //DESC
            hibQuery.SetSort(sort);
            result = hibQuery.List();
            Assert.IsNotNull(result);
            Assert.AreEqual(4, result.Count, "Wrong number of test results.");
            foreach (Book book in result)
            {
                //System.out.println(book.getSummary() + " : " + book.getPublicationDate());
            }
            Assert.AreEqual("Groovy in Action", ((Book)result[0]).Summary);

            tx.Commit();

            DeleteTestBooks(s);
            s.Close();
        }
        public void LuceneObjectsProjectionWithList()
        {
            IFullTextSession s = Search.CreateFullTextSession(this.OpenSession());

            this.PrepEmployeeIndex(s);

            s.Clear();
            ITransaction tx     = s.BeginTransaction();
            QueryParser  parser = new QueryParser(NHibernate.Search.Environment.LuceneVersion, "Dept", new StandardAnalyzer(NHibernate.Search.Environment.LuceneVersion));

            Query          query    = parser.Parse("Dept:Accounting");
            IFullTextQuery hibQuery = s.CreateFullTextQuery(query, typeof(Employee));

            hibQuery.SetProjection(
                "Id",
                "Lastname",
                "Dept",
                ProjectionConstants.THIS,
                ProjectionConstants.SCORE,
                ProjectionConstants.BOOST,
                ProjectionConstants.DOCUMENT,
                ProjectionConstants.ID,
                ProjectionConstants.DOCUMENT_ID);

            IList result = hibQuery.List();

            Assert.IsNotNull(result);

            object[] projection = (Object[])result[0];
            Assert.IsNotNull(projection);
            Assert.AreEqual(1001, projection[0], "id incorrect");
            Assert.AreEqual("Jackson", projection[1], "last name incorrect");
            Assert.AreEqual("Accounting", projection[2], "dept incorrect");
            Assert.AreEqual("Jackson", ((Employee)projection[3]).Lastname, "THIS incorrect");
            Assert.AreEqual(projection[3], s.Get <Employee>(projection[0]), "THIS incorrect");
            //Assert.AreEqual(1.0F, projection[4], "SCORE incorrect");
            Assert.AreEqual(1.0F, projection[5], "BOOST incorrect");
            Assert.IsTrue(projection[6] is Document, "DOCUMENT incorrect");
            Assert.AreEqual(4, ((Document)projection[6]).GetFields().Count, "DOCUMENT size incorrect");
            Assert.AreEqual(1001, projection[7], "ID incorrect");
            Assert.IsNotNull(projection[8], "Lucene internal doc id");

            // Change the projection order and null one
            hibQuery.SetProjection(
                ProjectionConstants.DOCUMENT,
                ProjectionConstants.THIS,
                ProjectionConstants.SCORE,
                null,
                ProjectionConstants.ID,
                "Id",
                "Lastname",
                "Dept",
                ProjectionConstants.DOCUMENT_ID);

            result = hibQuery.List();
            Assert.IsNotNull(result);

            projection = (object[])result[0];
            Assert.IsNotNull(projection);

            Assert.IsTrue(projection[0] is Document, "DOCUMENT incorrect");
            Assert.AreEqual(4, ((Document)projection[0]).GetFields().Count, "DOCUMENT size incorrect");
            Assert.AreEqual(projection[1], s.Get <Employee>(projection[4]), "THIS incorrect");
            //Assert.AreEqual(1.0F, projection[2], "SCORE incorrect");
            Assert.IsNull(projection[3], "BOOST not removed");
            Assert.AreEqual(1001, projection[4], "ID incorrect");
            Assert.AreEqual(1001, projection[5], "id incorrect");
            Assert.AreEqual("Jackson", projection[6], "last name incorrect");
            Assert.AreEqual("Accounting", projection[7], "dept incorrect");
            Assert.IsNotNull(projection[8], "Lucene internal doc id");

            // cleanup
            s.Delete("from System.Object");
            tx.Commit();
            s.Close();
        }
Ejemplo n.º 29
0
        public void EagerCollectionLoad()
        {
            ISession     sess = this.OpenSession();
            ITransaction tx   = sess.BeginTransaction();

            Music music = new Music();

            music.Title = "Moo Goes The Cow";
            Author author = new Author();

            author.Name = "Moo Cow";
            music.Authors.Add(author);
            sess.Persist(author);

            author      = new Author();
            author.Name = "Another Moo Cow";
            music.Authors.Add(author);
            sess.Persist(author);

            author      = new Author();
            author.Name = "A Third Moo Cow";
            music.Authors.Add(author);
            sess.Persist(author);

            author      = new Author();
            author.Name = "Random Moo Cow";
            music.Authors.Add(author);
            sess.Persist(author);
            sess.Save(music);

            Music music2 = new Music();

            music2.Title = "The Cow Goes Moo";
            author       = new Author();
            author.Name  = "Moo Cow The First";
            music2.Authors.Add(author);
            sess.Persist(author);

            author      = new Author();
            author.Name = "Moo Cow The Second";
            music2.Authors.Add(author);
            sess.Persist(author);

            author      = new Author();
            author.Name = "Moo Cow The Third";
            music2.Authors.Add(author);
            sess.Persist(author);

            author      = new Author();
            author.Name = "Moo Cow The Fourth";
            music2.Authors.Add(author);
            sess.Persist(author);
            sess.Save(music2);
            tx.Commit();
            sess.Clear();

            IFullTextSession s = Search.CreateFullTextSession(sess);

            tx = s.BeginTransaction();
            QueryParser parser = new QueryParser(Environment.LuceneVersion, "title", new KeywordAnalyzer());

            Lucene.Net.Search.Query query    = parser.Parse("title:moo");
            IFullTextQuery          hibQuery = s.CreateFullTextQuery(query, typeof(Music));
            IList result = hibQuery.List();

            Assert.AreEqual(2, result.Count, "Should have returned 2 Music");
            music = (Music)result[0];
            Assert.AreEqual(4, music.Authors.Count, "Music 1 should have 4 authors");
            music = (Music)result[1];
            Assert.AreEqual(4, music.Authors.Count, "Music 2 should have 4 authors");

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