Esempio n. 1
0
        public void StandardBehavior()
        {
            ISession s = OpenSession();
            ITransaction tx = s.BeginTransaction();
            Animal a = new Animal();
            a.Id = 1;
            a.Name = "Elephant";
            s.Persist(a);
            a = new Animal();
            a.Id = 2;
            a.Name = "Bear";
            s.Persist(a);
            tx.Commit();

            s.Clear();

            tx = s.BeginTransaction();
            a = (Animal) s.Get(typeof(Animal), 1);
            a.Name = "Mouse";
            Furniture fur = new Furniture();
            fur.Color = "dark blue";
            s.Persist(fur);
            tx.Commit();

            s.Clear();

            tx = s.BeginTransaction();
            IFullTextSession fts = Search.CreateFullTextSession(s);
            QueryParser parser = new QueryParser("id", new StopAnalyzer());

            IList results = fts.CreateFullTextQuery(parser.Parse("name:mouse OR name:bear")).List();
            Assert.AreEqual(2, results.Count, "Either double insert, single update, or query fails with shards");

            results = fts.CreateFullTextQuery(parser.Parse("name:mouse OR name:bear OR color:blue")).List();
            Assert.AreEqual(3, results.Count, "Mixing shared and non sharded properties fails");
            results = fts.CreateFullTextQuery(parser.Parse("name:mouse OR name:bear OR color:blue")).List();
            Assert.AreEqual(3, results.Count, "Mixing shared and non sharded properties fails with indexreader reuse");

            // cleanup
            s.Delete("from System.Object");
            tx.Commit();
            s.Close();
        }
Esempio n. 2
0
        public void InternalSharding()
        {
            ISession s = OpenSession();
            ITransaction tx = s.BeginTransaction();
            Animal a = new Animal();
            a.Id = 1;
            a.Name = "Elephant";
            s.Persist(a);
            a = new Animal();
            a.Id = 2;
            a.Name = "Bear";
            s.Persist(a);
            tx.Commit();

            s.Clear();

            IndexReader reader = IndexReader.Open(new FileInfo(BaseIndexDir.FullName + "\\Animal00"));
            try
            {
                int num = reader.NumDocs();
                Assert.AreEqual(1, num);
            }
            finally
            {
                reader.Close();
            }

            reader = IndexReader.Open(new FileInfo(BaseIndexDir.FullName + "\\Animal.1"));
            try
            {
                int num = reader.NumDocs();
                Assert.AreEqual(1, num);
            }
            finally
            {
                reader.Close();
            }

            tx = s.BeginTransaction();
            a = (Animal) s.Get(typeof(Animal),1);
            a.Name = "Mouse";
            tx.Commit();

            s.Clear();

            reader = IndexReader.Open(new FileInfo(BaseIndexDir.FullName + "\\Animal.1"));
            try
            {
                int num = reader.NumDocs();
                Assert.AreEqual(1, num);
                TermDocs docs = reader.TermDocs(new Term("name", "mouse"));
                Assert.IsTrue(docs.Next());
                Document doc = reader.Document(docs.Doc());
                Assert.IsFalse(docs.Next());
            }
            finally
            {
                reader.Close();
            }

            tx = s.BeginTransaction();
            IFullTextSession fts = Search.CreateFullTextSession(s);
            QueryParser parser = new QueryParser("id", new StopAnalyzer());

            IList results = fts.CreateFullTextQuery(parser.Parse("name:mouse OR name:bear")).List();
            Assert.AreEqual(2, results.Count, "Either double insert, single update, or query fails with shards");

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