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 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("id", new StopAnalyzer());
            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 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();
        }
        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();
        }
Example #5
0
        public static void Search()
        {
            HttpContext context        = HttpContext.Current;
            ISession    currentSession = context.Items[CurrentSessionKey] as ISession;

            if (currentSession == null)
            {
                currentSession = sessionFactory.OpenSession();
                context.Items[CurrentSessionKey] = currentSession;
            }

            IFullTextSession session = new FullTextSessionImpl(currentSession);

            if (!currentSession.IsOpen)
            {
                currentSession = sessionFactory.OpenSession();
                context.Items[CurrentSessionKey] = currentSession;

                if (currentSession.IsOpen)
                {
                    Debug.WriteLine("Session open");
                }
                else
                {
                    Debug.WriteLine("Session Closed");
                }
            }

            string   searchQuery = "Name:2";
            Analyzer std         = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);

            QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "Name", std);
            Query       query  = parser.Parse(searchQuery);

            IFullTextSession fullTextSession = NHibernate.Search.Search.CreateFullTextSession(NHibernateHelper.GetCurrentSession());
            IFullTextQuery   fullTextQuery   = fullTextSession.CreateFullTextQuery(query, typeof(Species));

            var employeeList = fullTextQuery.List();
        }
Example #6
0
        public static void ReIndex()
        {
            IFullTextSession session = new FullTextSessionImpl(GetCurrentSession());
            ITransaction     tx      = session.BeginTransaction();

            session.PurgeAll(typeof(Subject));
            tx.Commit();

            tx = session.BeginTransaction();



            foreach (object entity in session.CreateCriteria(typeof(Subject)).List())
            {
                session.Index(entity);
            }



            tx.Commit();
            session.Close();
        }
        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 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();
        }