@Override protected Query getStrictlyGreaterQuery() { return matchingContextSupport.rangeMatchingContext().above( value ).excludeLimit().createQuery(); } }
.must(new TermQuery(new Term("siteId", siteId.toString()))); if (null != startPublishDate) { termination.must(queryBuilder.range().onField("publishDate").above(startPublishDate).createQuery()); termination.must(queryBuilder.range().onField("publishDate").below(endPublishDate).createQuery());
.must(new TermQuery(new Term("siteId", siteId.toString()))); if (null != startPublishDate) { termination.must(queryBuilder.range().onField("publishDate").above(startPublishDate).createQuery()); termination.must(queryBuilder.range().onField("publishDate").below(endPublishDate).createQuery());
@Override protected Query getStrictlyLessQuery() { return matchingContextSupport.rangeMatchingContext().below( value ).excludeLimit().createQuery(); }
.must(new TermQuery(new Term("siteId", siteId.toString()))); if (null != startPublishDate) { termination.must(queryBuilder.range().onField("publishDate").above(startPublishDate).createQuery()); termination.must(queryBuilder.range().onField("publishDate").below(endPublishDate).createQuery());
@Test public void testRangeQueryFromTo() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); calendar.setTimeZone( TimeZone.getTimeZone( "UTC" ) ); calendar.set( 1900, 2, 12, 0, 0, 0 ); calendar.set( Calendar.MILLISECOND, 0 ); Date from = calendar.getTime(); calendar.set( 1910, 2, 12, 0, 0, 0 ); Date to = calendar.getTime(); Query query = monthQb .range() .onField( "estimatedCreation" ) .andField( "justfortest" ) .ignoreFieldBridge().ignoreAnalyzer() .from( from ) .to( to ).excludeLimit() .createQuery(); helper.assertThat( query ).from( Month.class ).hasResultSize( 1 ); }
.must(new TermQuery(new Term("siteId", siteId.toString()))); if (null != startPublishDate) { termination.must(queryBuilder.range().onField("publishDate").above(startPublishDate).createQuery()); termination.must(queryBuilder.range().onField("publishDate").below(endPublishDate).createQuery());
@Test @Category(SkipOnElasticsearch.class) // This only works because of a Lucene-specific hack in org.hibernate.search.bridge.util.impl.NumericFieldUtils.createNumericRangeQuery public void testRangeQueryFromToIgnoreFieldBridge() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); calendar.setTimeZone( TimeZone.getTimeZone( "UTC" ) ); calendar.set( 1900, 2, 12, 0, 0, 0 ); calendar.set( Calendar.MILLISECOND, 0 ); Date from = calendar.getTime(); calendar.set( 1910, 2, 12, 0, 0, 0 ); Date to = calendar.getTime(); Query query = monthQb .range() .onField( "estimatedCreation" ) .ignoreFieldBridge() .andField( "justfortest" ) .ignoreFieldBridge().ignoreAnalyzer() .from( DateTools.round( from, DateTools.Resolution.MINUTE ) ) .to( DateTools.round( to, DateTools.Resolution.MINUTE ) ) .excludeLimit() .createQuery(); helper.assertThat( query ).from( Month.class ).hasResultSize( 1 ); }
@Override protected Query getLessOrEqualsQuery() { return matchingContextSupport.rangeMatchingContext().below( value ).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(); }
@Override protected Query getGreaterOrEqualsQuery() { return matchingContextSupport.rangeMatchingContext().above( value ).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(); }
@Override public Query getQuery() { return matchingContextSupport.rangeMatchingContext().from( lower ).to( upper ).createQuery(); } }
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 public void testRangeQueryAbove() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); calendar.setTimeZone( TimeZone.getTimeZone( "UTC" ) ); calendar.set( 10 + 1900, 2, 12, 0, 0, 0 ); Date to = calendar.getTime(); Query query = monthQb .range() .onField( "estimatedCreation" ) .andField( "justfortest" ) .ignoreFieldBridge().ignoreAnalyzer() .above( to ) .createQuery(); helper.assertThat( query ).from( Month.class ).matchesExactlyIds( 2 ); }
@Test public void verifyExplicitRangeQuery() { Query query = getQueryBuilder() .range() .onField( "age" ) .from( 1 ).excludeLimit() .to( 3 ).excludeLimit() .createQuery(); Assert.assertTrue( query instanceof NumericRangeQuery ); assertProjection( query, "title" ).matchesExactlySingleProjections( "title-two" ); }
@Test public void testNumericRangeQueries() { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); Query query = monthQb .range() .onField( "raindropInMm" ) .from( 0.23d ) .to( 0.24d ) .createQuery(); assertTrue( query.getClass().isAssignableFrom( NumericRangeQuery.class ) ); helper.assertThat( query ).from( Month.class ).matchesExactlyIds( 1 ); }
@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 ); }
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"; }
@Test @TestForIssue( jiraKey = "HSEARCH-1378") public void testNumericRangeQueryAbove() { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); //inclusive Query query = monthQb .range() .onField( "raindropInMm" ) .above( 0.231d ) .createQuery(); assertTrue( query.getClass().isAssignableFrom( NumericRangeQuery.class ) ); helper.assertThat( query ).from( Month.class ).matchesUnorderedIds( 1, 2, 3 ); //exclusive query = monthQb .range() .onField( "raindropInMm" ) .above( 0.231d ) .excludeLimit() .createQuery(); helper.assertThat( query ).from( Month.class ).matchesUnorderedIds( 2, 3 ); }