public void testNamedFilters() { createData(); FullTextSession s = Search.getFullTextSession(openSession()); s.getTransaction().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); FullTextQuery ftQuery = s.createFullTextQuery(query, Driver.class); assertEquals("No filter should happen", 3, ftQuery.getResultSize()); ftQuery = s.createFullTextQuery(query, Driver.class); ftQuery.disableFullTextFilter("bestDriver"); // was not enabled, but should be harmless ftQuery.enableFullTextFilter("bestDriver"); assertEquals("Should filter out Gavin", 2, ftQuery.getResultSize()); ftQuery = s.createFullTextQuery(query, Driver.class); ftQuery.enableFullTextFilter("bestDriver"); ftQuery.enableFullTextFilter("security").setParameter("login", "andre"); assertEquals("Should filter to limit to Emmanuel", 1, ftQuery.getResultSize()); ftQuery = s.createFullTextQuery(query, Driver.class); ftQuery.enableFullTextFilter("bestDriver"); ftQuery.enableFullTextFilter("security").setParameter("login", "andre"); ftQuery.disableFullTextFilter("security"); ftQuery.disableFullTextFilter("bestDriver"); assertEquals("Should not filter anymore", 3, ftQuery.getResultSize()); s.getTransaction().commit(); s.close(); deleteData(); }
public void testStraightFilters() { createData(); FullTextSession s = Search.getFullTextSession(openSession()); s.getTransaction().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); FullTextQuery ftQuery; ftQuery = s.createFullTextQuery(query, Driver.class); ftQuery.enableFullTextFilter("bestDriver"); Filter dateFilter = new TermRangeFilter("delivery", "2001", "2005", true, true); ftQuery.setFilter(dateFilter); assertEquals("Should select only liz", 1, ftQuery.getResultSize()); ftQuery = s.createFullTextQuery(query, Driver.class); ftQuery.setFilter(dateFilter); ftQuery.enableFullTextFilter("bestDriver"); ftQuery.enableFullTextFilter("security").setParameter("login", "andre"); ftQuery.disableFullTextFilter("security"); ftQuery.disableFullTextFilter("bestDriver"); ftQuery.setFilter(null); assertEquals("Should not filter anymore", 3, ftQuery.getResultSize()); s.getTransaction().commit(); s.close(); deleteData(); }