Ejemplo n.º 1
0
        public void ContainedIn()
        {
            Tower tower = new Tower();
            tower.Name = "JBoss tower";
            Address a = new Address();
            a.Street = "Tower place";
            a.Towers.Add(tower);
            tower.Address = a;
            Owner o = new Owner();
            o.Name = "Atlanta Renting corp";
            a.OwnedBy = o;
            o.Address = a;

            ISession s = OpenSession();
            ITransaction tx = s.BeginTransaction();
            s.Persist(tower);
            tx.Commit();

            s.Clear();

            tx = s.BeginTransaction();
            Address address = s.Get<Address>(a.Id);
            address.Street = "Peachtree Road NE";
            tx.Commit();

            s.Clear();

            IFullTextSession session = Search.CreateFullTextSession(s);
            QueryParser parser = new QueryParser("id", new StandardAnalyzer());

            Lucene.Net.Search.Query query = parser.Parse("address.street:peachtree");
            IList result = session.CreateFullTextQuery(query).List();
            Assert.AreEqual(1, result.Count, "change in embedded not reflected in root index");

            s.Clear();

            tx = s.BeginTransaction();
            address = s.Get<Address>(a.Id);
            IEnumerator en = address.Towers.GetEnumerator();
            en.MoveNext();
            Tower tower1 = (Tower) en.Current;
            tower1.Address = null;
            address.Towers.Remove(tower1);
            tx.Commit();

            s.Clear();

            session = Search.CreateFullTextSession(s);

            query = parser.Parse("address.street:peachtree");
            result = session.CreateFullTextQuery(query).List();
            Assert.AreEqual(0, result.Count, "breaking link fails");

            // Tidy up
            tx = s.BeginTransaction();
            s.Delete(tower);
            s.Delete(a);
            tx.Commit();

            s.Close();
        }
Ejemplo n.º 2
0
        public void EmbeddedIndexing()
        {
            Tower tower = new Tower();
            tower.Name = "JBoss tower";
            Address a = new Address();
            a.Street = "Tower place";
            a.Towers.Add(tower);
            tower.Address = a;
            Owner o = new Owner();
            o.Name = "Atlanta Renting corp";
            a.OwnedBy = o;
            o.Address = a;
            Country c = new Country();
            c.Name = "France";
            a.Country = c;

            ISession s = OpenSession();
            ITransaction tx = s.BeginTransaction();
            s.Persist(tower);
            tx.Commit();

            IFullTextSession session = Search.CreateFullTextSession(s);
            QueryParser parser = new QueryParser("id", new StandardAnalyzer());

            Lucene.Net.Search.Query query = parser.Parse("address.street:place");
            IList result = session.CreateFullTextQuery(query).List();
            Assert.AreEqual(1, result.Count, "unable to find property in embedded");

            query = parser.Parse("address.ownedBy_name:renting");
            result = session.CreateFullTextQuery(query).List();
            Assert.AreEqual(1, result.Count, "unable to find property in embedded");

            query = parser.Parse("address.id:" + a.Id);
            result = session.CreateFullTextQuery(query).List();
            Assert.AreEqual(1, result.Count, "unable to find property by id of embedded");

            query = parser.Parse("address.country.name:" + a.Country.Name);
            result = session.CreateFullTextQuery(query).List();
            Assert.AreEqual(1, result.Count, "unable to find property with 2 levels of embedded");

            s.Clear();

            tx = s.BeginTransaction();
            Address address = s.Get<Address>(a.Id);
            address.OwnedBy.Name = "Buckhead community";

            // NB Not in the Java?
            s.Persist(address);
            tx.Commit();

            s.Clear();

            session = Search.CreateFullTextSession(s);

            query = parser.Parse("address.ownedBy_name:buckhead");
            result = session.CreateFullTextQuery(query).List();
            Assert.AreEqual(1, result.Count, "change in embedded not reflected in root index");

            s.Clear();

            // Tidy up
            tx = s.BeginTransaction();
            s.Delete(tower);
            s.Delete(a);
            s.Delete(c);
            tx.Commit();

            s.Close();
        }