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 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 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(); } }