termination.must(queryBuilder.range().onField("publishDate").below(endPublishDate).createQuery());
termination.must(queryBuilder.range().onField("publishDate").below(endPublishDate).createQuery());
termination.must(queryBuilder.range().onField("publishDate").below(endPublishDate).createQuery());
termination.must(queryBuilder.range().onField("publishDate").below(endPublishDate).createQuery());
@Override protected Query getLessOrEqualsQuery() { return matchingContextSupport.rangeMatchingContext().below( value ).createQuery(); }
@Override protected Query getStrictlyLessQuery() { return matchingContextSupport.rangeMatchingContext().below( value ).excludeLimit().createQuery(); }
@Test public void testRangeQueryBelow() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); calendar.setTimeZone( TimeZone.getTimeZone( "UTC" ) ); calendar.set( 10 + 1800, 2, 12, 0, 0, 0 ); Date to = calendar.getTime(); Query query = monthQb .range() .onField( "estimatedCreation" ) .andField( "justfortest" ) .ignoreFieldBridge().ignoreAnalyzer() .below( to ) .createQuery(); helper.assertThat( query ).from( Month.class ).matchesExactlyIds( 3 ); query = monthQb.range() .onField( "raindropInMm" ) .below( 0.24d ) .createQuery(); assertTrue( query.getClass().isAssignableFrom( NumericRangeQuery.class ) ); helper.assertThat( query ).from( Month.class ).matchesExactlyIds( 1 ); }
public void testQueryingRangeBelowWithLimit() throws ParseException { loadTestingData(); Query query = Search.getSearchManager(cache).buildQueryBuilderForClass(Person.class) .get().range().onField("age").below(30).createQuery(); CacheQuery<?> cacheQuery = Search.getSearchManager(cache).getQuery(query); List<?> found = cacheQuery.list(); assertEquals(3, found.size()); assert found.contains(person1); assert found.contains(person2); assert found.contains(person3); assert !found.contains(person4) : "This should not contain object person4"; person4 = new Person(); person4.setName("Mighty Goat"); person4.setBlurb("Also eats grass"); person4.setAge(28); cache.put("mighty", person4); cacheQuery = Search.getSearchManager(cache).getQuery(query); found = cacheQuery.list(); assert found.size() == 4 : "Size of list should be 4"; assert found.contains(person1); assert found.contains(person2); assert found.contains(person3); assert found.contains(person4) : "This should now contain object person4"; }
public void testQueryingRangeBelowExcludingLimit() throws ParseException { loadTestingData(); Query query = Search.getSearchManager(cache).buildQueryBuilderForClass(Person.class) .get().range().onField("age").below(30).excludeLimit().createQuery(); CacheQuery<?> cacheQuery = Search.getSearchManager(cache).getQuery(query); List<?> found = cacheQuery.list(); assertEquals(2, found.size()); assert found.contains(person1); assert found.contains(person3); assert !found.contains(person4) : "This should not contain object person4"; person4 = new Person(); person4.setName("Mighty Goat"); person4.setBlurb("Also eats grass"); person4.setAge(28); cache.put("mighty", person4); cacheQuery = Search.getSearchManager(cache).getQuery(query); found = cacheQuery.list(); assert found.size() == 3 : "Size of list should be 3"; assert found.contains(person1); assert found.contains(person3); assert found.contains(person4) : "This should now contain object person4"; }
@Test @Category(SkipOnElasticsearch.class) // This only works because of a Lucene-specific hack in org.hibernate.search.bridge.util.impl.NumericFieldUtils.createNumericRangeQuery public void testRangeQueryBelowIgnoreFieldBridge() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); calendar.setTimeZone( TimeZone.getTimeZone( "UTC" ) ); calendar.set( 10 + 1800, 2, 12, 0, 0, 0 ); Date to = calendar.getTime(); Query query = monthQb .range() .onField( "estimatedCreation" ) .ignoreFieldBridge() .andField( "justfortest" ) .ignoreFieldBridge().ignoreAnalyzer() .below( DateTools.round( to, DateTools.Resolution.MINUTE ) ) .createQuery(); helper.assertThat( query ).from( Month.class ).matchesExactlyIds( 3 ); }
private List<Object> getYoungerThan(SearchManager sm, int age) { QueryBuilder queryBuilder = sm.buildQueryBuilderForClass(Person.class).get(); Query query = queryBuilder.range().onField("age").below(age).createQuery(); return sm.getQuery(query, Person.class).list(); }
public void testQueryingRangeWithAnd() { NumericType type1 = new NumericType(10, 20); NumericType type2 = new NumericType(20, 10); NumericType type3 = new NumericType(10, 10); cache.put(key1, type1); cache.put(key2, type2); cache.put(key3, type3); Query query = Search.getSearchManager(cache).buildQueryBuilderForClass(NumericType.class) .get().range().onField("num1").andField("num2").below(20).excludeLimit().createQuery(); CacheQuery<Person> cacheQuery = Search.getSearchManager(cache).getQuery(query); List<Person> found = cacheQuery.list(); assertEquals(3, found.size()); //<------ All entries should be here, because andField is executed as SHOULD; assert found.contains(type1); assert found.contains(type2); assert found.contains(type3); NumericType type4 = new NumericType(11, 10); cache.put("newKey", type4); cacheQuery = Search.getSearchManager(cache).getQuery(query); found = cacheQuery.list(); assertEquals(4, found.size()); assert found.contains(type3); assert found.contains(type2); assert found.contains(type1); assert found.contains(type4); //@TODO write here another case with not-matching entries }
@Test @TestForIssue( jiraKey = "HSEARCH-1378") public void testNumericRangeQueryBelow() { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); //inclusive Query query = monthQb .range() .onField( "raindropInMm" ) .below( 0.435d ) .createQuery(); assertTrue( query.getClass().isAssignableFrom( NumericRangeQuery.class ) ); helper.assertThat( query ).from( Month.class ).matchesUnorderedIds( 1, 2, 3 ); //exclusive query = monthQb .range() .onField( "raindropInMm" ) .below( 0.435d ) .excludeLimit() .createQuery(); helper.assertThat( query ).from( Month.class ).matchesUnorderedIds( 1 ); }
@Test public void testNumericFieldWithBigDecimals() throws Exception { Session session = openSession(); Transaction tx = session.beginTransaction(); // create entities Item item = new Item(); item.setPrice( new BigDecimal( 154.34 ) ); session.save( item ); tx.commit(); tx = session.beginTransaction(); FullTextSession fullTextSession = Search.getFullTextSession( session ); QueryBuilder queryBuilder = fullTextSession.getSearchFactory() .buildQueryBuilder() .forEntity( Item.class ) .get(); Query rootQuery = queryBuilder.bool() .must( queryBuilder.range().onField( "price" ).above( 10000L ).createQuery() ) .must( queryBuilder.range().onField( "price" ).below( 20000L ).createQuery() ) .createQuery(); @SuppressWarnings( "unchecked" ) List<Item> resultList = fullTextSession.createFullTextQuery( rootQuery, Item.class ).list(); assertNotNull( resultList ); assertEquals( 1, resultList.size() ); tx.commit(); session.close(); }
@Test @TestForIssue(jiraKey = "HSEARCH-2030") public void testRangeQueryWithNullToken() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); Query query = monthQb .range() .onField( "keyForOrdering" ) .below( "-mar" ) .createQuery(); helper.assertThat( query ).from( Month.class ).matchesExactlyIds( 3 ); query = monthQb .range() .onField( "keyForOrdering" ) .below( null ) .createQuery(); helper.assertThat( query ).from( Month.class ).matchesExactlyIds( 3 ); }
public void testBooleanQueriesOnMultipleTables() throws ParseException { loadTestingData(); AnotherGrassEater anotherGrassEater = new AnotherGrassEater("Another grass-eater", "Eats grass"); cache.put("key4", anotherGrassEater); Query subQuery = Search.getSearchManager(cache).buildQueryBuilderForClass(Person.class).get().range() .onField("age").below(20).createQuery(); Query query = Search.getSearchManager(cache).buildQueryBuilderForClass(AnotherGrassEater.class).get().bool() .should(createQueryParser("name").parse("grass")).should(subQuery).createQuery(); CacheQuery<Person> cacheQuery = Search.getSearchManager(cache).getQuery(query); List<Person> found = cacheQuery.list(); assertEquals(2, found.size()); assert found.contains(person1); assert found.contains(anotherGrassEater); }
public void testBooleanQueriesShould() throws ParseException { loadTestingData(); Query subQuery = Search.getSearchManager(cache).buildQueryBuilderForClass(Person.class).get().range() .onField("age").below(20).createQuery(); Query query = Search.getSearchManager(cache).buildQueryBuilderForClass(Person.class).get().bool() .should(createQueryParser("name").parse("Goat")).should(subQuery).createQuery(); CacheQuery<Person> cacheQuery = Search.getSearchManager(cache).getQuery(query); List<Person> found = cacheQuery.list(); assertEquals(3, found.size()); assert found.contains(person1); assert found.contains(person2); assert found.contains(person3); subQuery = Search.getSearchManager(cache).buildQueryBuilderForClass(Person.class).get().range() .onField("age").below(20).excludeLimit().createQuery(); query = Search.getSearchManager(cache).buildQueryBuilderForClass(Person.class).get().bool() .should(createQueryParser("name").parse("Goat")).should(subQuery).createQuery(); cacheQuery = Search.getSearchManager(cache).getQuery(query); found = cacheQuery.list(); assertEquals(2, found.size()); assert found.contains(person2); assert found.contains(person3); }
@Test @TestForIssue(jiraKey = "HSEARCH-2656") public void testNumericRangeQueryWithFieldTypeOverriddenByFieldBridge() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); Query query = monthQb .range() .onField( "monthBase0" ) .ignoreFieldBridge().ignoreAnalyzer() .below( 1 ).excludeLimit() .createQuery(); helper.assertThat( query ).from( Month.class ).matchesUnorderedIds( 1 ); }
@Override public Query visit(FullTextRangeExpr fullTextRangeExpr) { PropertyValueExpr propertyValueExpr = (PropertyValueExpr) fullTextRangeExpr.getChild(); //todo [anistor] incomplete implementation ? if (fullTextRangeExpr.getLower() == null && fullTextRangeExpr.getUpper() == null) { return new TermRangeQuery(propertyValueExpr.getPropertyPath().asStringPath(), null, null, fullTextRangeExpr.isIncludeLower(), fullTextRangeExpr.isIncludeUpper()); } RangeMatchingContext rangeMatchingContext = applyFieldBridge(true, propertyValueExpr.getPropertyPath(), queryBuilder.range().onField(propertyValueExpr.getPropertyPath().asStringPath())); RangeTerminationExcludable t = null; if (fullTextRangeExpr.getLower() != null) { t = rangeMatchingContext.above(fullTextRangeExpr.getLower()); if (!fullTextRangeExpr.isIncludeLower()) { t.excludeLimit(); } } if (fullTextRangeExpr.getUpper() != null) { t = rangeMatchingContext.below(fullTextRangeExpr.getUpper()); if (!fullTextRangeExpr.isIncludeUpper()) { t.excludeLimit(); } } return t.createQuery(); }
@Override public Query visit(FullTextRangeExpr fullTextRangeExpr) { PropertyValueExpr propertyValueExpr = (PropertyValueExpr) fullTextRangeExpr.getChild(); //todo [anistor] incomplete implementation ? if (fullTextRangeExpr.getLower() == null && fullTextRangeExpr.getUpper() == null) { return new TermRangeQuery(propertyValueExpr.getPropertyPath().asStringPath(), null, null, fullTextRangeExpr.isIncludeLower(), fullTextRangeExpr.isIncludeUpper()); } RangeMatchingContext rangeMatchingContext = applyFieldBridge(true, propertyValueExpr.getPropertyPath(), queryBuilder.range().onField(propertyValueExpr.getPropertyPath().asStringPath())); RangeTerminationExcludable t = null; if (fullTextRangeExpr.getLower() != null) { t = rangeMatchingContext.above(fullTextRangeExpr.getLower()); if (!fullTextRangeExpr.isIncludeLower()) { t.excludeLimit(); } } if (fullTextRangeExpr.getUpper() != null) { t = rangeMatchingContext.below(fullTextRangeExpr.getUpper()); if (!fullTextRangeExpr.isIncludeUpper()) { t.excludeLimit(); } } return t.createQuery(); }