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(); } }
public void SetUp() { var configuration = new Configuration(); configuration .SetProperty(NHibernate.Cfg.Environment.GenerateStatistics, "true") .SetProperty(NHibernate.Cfg.Environment.Hbm2ddlAuto, "create-drop") .SetProperty(NHibernate.Cfg.Environment.UseQueryCache, "true") .SetProperty(NHibernate.Cfg.Environment.CacheProvider, typeof(HashtableCacheProvider).AssemblyQualifiedName) .SetProperty(NHibernate.Cfg.Environment.ReleaseConnections, "on_close") .SetProperty(NHibernate.Cfg.Environment.Dialect, typeof(SQLiteDialect).AssemblyQualifiedName) .SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, typeof(SQLite20Driver).AssemblyQualifiedName) .SetProperty(NHibernate.Cfg.Environment.ConnectionString, "Data Source=:memory:;Version=3;New=True;"); var assembly = Assembly.GetExecutingAssembly(); var modelMapper = new ModelMapper(); modelMapper.AddMappings(assembly.GetTypes()); var hbms = modelMapper.CompileMappingForAllExplicitlyAddedEntities(); configuration.AddDeserializedMapping(hbms, assembly.GetName().Name); ConfigureSearch(configuration); sessionFactory = configuration.BuildSessionFactory(); Session = sessionFactory.OpenSession(); SearchSession = Search.CreateFullTextSession(Session); new SchemaExport(configuration) .Execute(false, true, false, Session.Connection, null); AfterSetup(); }
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 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(); }
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 IList <TaskMainDAO> Find(string textQuery) { if (textQuery == string.Empty) { return(null); } ISessionFactory applicationFactory = NhibernateSessionFactory.GetSessionFactory(NhibernateSessionFactory.SessionFactoryConfiguration.Application); using (ISession session = applicationFactory.OpenSession()) using (IFullTextSession fullTextSession = Search.CreateFullTextSession(session)) using (ITransaction transaction = fullTextSession.BeginTransaction()) { try { IFullTextQuery fullTextQuery = fullTextSession.CreateFullTextQuery <TaskMainDAO>(textQuery); IList <TaskMainDAO> tasks = fullTextQuery.List <TaskMainDAO>(); transaction.Commit(); return(tasks); } catch (Lucene.Net.QueryParsers.ParseException e) { //handle parsing failure. Display some indication like "Wrong search criteria" transaction.Commit(); return(new TaskMainDAO[0]); } } }
public void SetUp() { var configuration = new Configuration(); configuration .SetProperty(NHibernate.Cfg.Environment.GenerateStatistics, "true") .SetProperty(NHibernate.Cfg.Environment.Hbm2ddlAuto, "create-drop") .SetProperty(NHibernate.Cfg.Environment.UseQueryCache, "true") .SetProperty(NHibernate.Cfg.Environment.CacheProvider, typeof (HashtableCacheProvider).AssemblyQualifiedName) .SetProperty(NHibernate.Cfg.Environment.ReleaseConnections, "on_close") .SetProperty(NHibernate.Cfg.Environment.Dialect, typeof (SQLiteDialect).AssemblyQualifiedName) .SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, typeof (SQLite20Driver).AssemblyQualifiedName) .SetProperty(NHibernate.Cfg.Environment.ConnectionString, "Data Source=:memory:;Version=3;New=True;"); var assembly = Assembly.GetExecutingAssembly(); var modelMapper = new ModelMapper(); modelMapper.AddMappings(assembly.GetTypes()); var hbms = modelMapper.CompileMappingForAllExplicitlyAddedEntities(); configuration.AddDeserializedMapping(hbms, assembly.GetName().Name); ConfigureSearch(configuration); sessionFactory = configuration.BuildSessionFactory(); Session = sessionFactory.OpenSession(); SearchSession = Search.CreateFullTextSession(Session); new SchemaExport(configuration) .Execute(false, true, false, Session.Connection, null); AfterSetup(); }
public void CustomBridges() { Cloud cloud = new Cloud(); cloud.CustomFieldBridge = ("This is divided by 2"); cloud.CustomStringBridge = ("This is div by 4"); ISession s = OpenSession(); ITransaction tx = s.BeginTransaction(); s.Save(cloud); s.Flush(); tx.Commit(); tx = s.BeginTransaction(); IFullTextSession session = Search.CreateFullTextSession(s); QueryParser parser = new QueryParser("id", new SimpleAnalyzer()); Lucene.Net.Search.Query query = parser.Parse("CustomFieldBridge:This AND CustomStringBridge:This"); IList result = session.CreateFullTextQuery(query).List(); Assert.AreEqual(1, result.Count, "Properties not mapped"); query = parser.Parse("CustomFieldBridge:by AND CustomStringBridge:is"); result = session.CreateFullTextQuery(query).List(); Assert.AreEqual(0, result.Count, "Custom types not taken into account"); s.Delete(s.Get(typeof(Cloud), cloud.Id)); tx.Commit(); s.Close(); }
private static void FillDb() { using (IFullTextSession s = Search.CreateFullTextSession(sf.OpenSession())) { using (ITransaction tx = s.BeginTransaction()){ Book b1 = new Book(1, "Eric Evans", "Domain-Driven Design: Tackling Complexity in the Heart of Software", "This book provides a broad framework for making design decisions and a technical vocabulary for discussing domain design. It is a synthesis of widely accepted best practices along with the author's own insights and experiences." ); s.Save(b1); Book b2 = new Book(2, "Pierre Kuate", "NHibernate in Action", "In the classic style of Manning's 'In Action' series, NHibernate in Action introduces .NET developers to the NHibernate Object/Relational Mapping tool. As NHibernate is a port of Hibernate from Java to .NET."); s.Save(b2); Book b3 = new Book(3, "John Doe", "Foo book NHibernate", "Foo series book"); s.Save(b3); s.Flush(); tx.Commit(); } } }
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(); }
public PropertyMarshaller(EnvironmentContext.Type environmentType) { var sessionfactorybuilder = new NHibernateSessionFactoryBuilder(EnvironmentContext.ConnectionString(environmentType), "~/LuceneIndex"); _session = Search.CreateFullTextSession(sessionfactorybuilder.GetSessionFactory().OpenSession()); _unitOfWork = new NHUnitOfWork(_session); }
/// <summary> /// /// </summary> /// <param name="s"></param> private void DeleteTestBooks(IFullTextSession s) { ITransaction tx = s.BeginTransaction(); s.Delete("from System.Object"); tx.Commit(); s.Clear(); }
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(); }
private static void LuceneCriteria() { using (IFullTextSession s = Search.CreateFullTextSession(sf.OpenSession())) { IList result = s.CreateCriteria(typeof(Book)) .Add(SearchRestrictions.Query("Summary:NHibernate or Name:NHibernate")) .List(); Debug.Assert(result.Count == 2); } }
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 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(); }
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(); }
public void CanLookupEntityByValueOfEmbeddedSetValues() { IFullTextSession session = Search.CreateFullTextSession(s); QueryParser parser = new MultiFieldQueryParser(Environment.LuceneVersion, new string[] { "name", "authors.name" }, new StandardAnalyzer(Environment.LuceneVersion)); Lucene.Net.Search.Query query = parser.Parse("Hugo"); IList result = session.CreateFullTextQuery(query).List(); Assert.AreEqual(1, result.Count, "collection of embedded (set) ignored"); }
public IList <T> QueryProperty(string field, string query) { using (var wu = SessionManager.WorkUnitFor(this, DbWorkUnitType.Read)) { IFullTextSession fullTextSession = NHibernate.Search.Search.CreateFullTextSession(wu.Session); //QueryParser parser = new QueryParser(field, new StandardAnalyzer()); //var luceneQuery = parser.Parse(query); var qq = fullTextSession.CreateFullTextQuery <T>(field, query); return(qq.List <T>()); } }
private static void LuceneQueries() { using (IFullTextSession s = Search.CreateFullTextSession(sf.OpenSession())) { QueryParser qp = new QueryParser("id", new StopAnalyzer()); IQuery NHQuery = s.CreateFullTextQuery(qp.Parse("Summary:series"), typeof(Book)); IList result = NHQuery.List(); Debug.Assert(result.Count == 2); } }
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(); }
private void buildSession() { var cfg = createConfig(); var sessionFactory = cfg.BuildSessionFactory(); this.session = sessionFactory.OpenSession(); IDbConnection connection = session.Connection; new SchemaExport(cfg).Execute(false, true, false, connection, null); fullTextSession = NHibernate.Search.Search.CreateFullTextSession(session); }
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(); }
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(); }
public void CanLookupEntityByValueOfEmbeddedDictionaryValue() { IFullTextSession session = Search.CreateFullTextSession(s); // PhraseQuery TermQuery query = new TermQuery(new Term("orders.orderNumber", "ZERTYD")); IList result = session.CreateFullTextQuery(query, typeof(Product)).List(); Assert.AreEqual(1, result.Count, "collection of untokenized ignored"); query = new TermQuery(new Term("orders.orderNumber", "ACVBNM")); result = session.CreateFullTextQuery(query, typeof(Product)).List(); Assert.AreEqual(1, result.Count, "collection of untokenized ignored"); }
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 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); var version = LuceneVersion.LUCENE_48; QueryParser parser = new QueryParser(version, "id", new StopAnalyzer(version)); 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(); }
public void DefaultAndNullBridges() { Cloud cloud = new Cloud(); cloud.DateTime = null; cloud.Double1 = (null); cloud.Double2 = (2.1d); cloud.Int1 = (null); cloud.Int2 = (2); cloud.Float1 = (null); cloud.Float2 = (2.1f); cloud.Long1 = (null); cloud.Long2 = (2L); cloud.String1 = (null); cloud.Type = (CloudType.Dog); cloud.Storm = (false); ISession s = OpenSession(); ITransaction tx = s.BeginTransaction(); s.Save(cloud); s.Flush(); tx.Commit(); tx = s.BeginTransaction(); IFullTextSession session = Search.CreateFullTextSession(s); QueryParser parser = new QueryParser("id", new StandardAnalyzer()); Lucene.Net.Search.Query query = parser.Parse("Double2:[2 TO 2.1] AND Float2:[2 TO 2.1] " + "AND Int2:[2 TO 2.1] AND Long2:[2 TO 2.1] AND Type:\"Dog\" AND Storm:false"); IList result = session.CreateFullTextQuery(query).List(); Assert.AreEqual(1, result.Count, "find primitives and do not fail on null"); query = parser.Parse("Double1:[2.1 TO 2.1] OR Float1:[2 TO 2.1] " + "OR Int1:[2 TO 2.1] OR Long1:[2 TO 2.1]"); result = session.CreateFullTextQuery(query).List(); Assert.AreEqual(0, result.Count, "null elements should not be stored"); //the query is dumb because restrictive query = parser.Parse("Type:Dog"); result = session.CreateFullTextQuery(query).SetProjection("Type").List(); Assert.AreEqual(1, result.Count, "Enum projection works"); //the query is dumb because restrictive s.Delete(s.Get(typeof(Cloud), cloud.Id)); tx.Commit(); s.Close(); }
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(); }
public IList <T> RawQuery <T>(string field, string query) { using (var wu = SessionManager.WorkUnitFor(this, DbWorkUnitType.Read)) { IFullTextSession fullTextSession = NHibernate.Search.Search.CreateFullTextSession(wu.Session); //QueryParser parser = new QueryParser(field, new StandardAnalyzer()); //var luceneQuery = parser.Parse(query); try { var qq = fullTextSession.CreateFullTextQuery <T>(field, query); return(qq.List <T>()); } catch (ObjectNotFoundException ex) { return(new List <T>()); } } }
/// <summary> /// Helper method creating three books with the same title and summary. /// When searching for these books the results should be returned in the order /// they got added to the index. /// </summary> /// <param name="s">The full text session used to index the test data.</param> private void CreateTestBooks(IFullTextSession s) { ITransaction tx = s.BeginTransaction(); DateTime cal = new DateTime(2007, 07, 25, 11, 20, 30); Book book = new Book(1, "Hibernate & Lucene", "This is a test book."); book.PublicationDate = cal; s.Save(book); book = new Book(2, "Hibernate & Lucene", "This is a test book."); book.PublicationDate = cal.AddSeconds(1); s.Save(book); book = new Book(3, "Hibernate & Lucene", "This is a test book."); book.PublicationDate = cal.AddSeconds(2); s.Save(book); book = new Book(4, "Groovy in Action", "The bible of Groovy"); book.PublicationDate = cal.AddSeconds(3); s.Save(book); tx.Commit(); s.Clear(); }
private void PrepEmployeeIndex(IFullTextSession s) { ITransaction tx = s.BeginTransaction(); Employee e1 = new Employee(1000, "Griffin", "ITech"); s.Save(e1); Employee e2 = new Employee(1001, "Jackson", "Accounting"); s.Save(e2); Employee e3 = new Employee(1002, "Jimenez", "ITech"); s.Save(e3); Employee e4 = new Employee(1003, "Stejskal", "ITech"); s.Save(e4); Employee e5 = new Employee(1004, "Whetbrook", "ITech"); s.Save(e5); tx.Commit(); }